Skip to content

Commit

Permalink
Yield error if no files were found even without CLI arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Feb 23, 2025
1 parent e977912 commit 949725a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/elm-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ async function getProjectFiles(options, elmSyntaxVersion) {
const emptyDirectories = filesInDirectories.filter(
({files}) => files.length === 0
);
const elmFilesToRead = [
...new Set(filesInDirectories.flatMap((directory) => directory.files))
];

// TODO(@jfmengels): Have a different message depending on how directories were chosen (CLI directories, application, package).
if (options.directoriesToAnalyze.length > 0 && emptyDirectories.length > 0) {
Expand All @@ -65,6 +68,12 @@ ${emptyDirectories.map(({directory}) => `- ${directory}`).join('\n')}
When I can’t find files in some of the directories, I’m assuming that you
misconfigured the CLI’s arguments.`
);
} else if (elmFilesToRead.length === 0) {
throw new ErrorMessage.CustomError(
'NO FILES FOUND',
`I could not find any files in this project. I looked in these folders:
${sourceDirectories.map((directory) => `- ${directory}`).join('\n')}`
);
}

Debug.log(`Parsing using stil4m/elm-syntax v${elmSyntaxVersion}`);
Expand All @@ -73,9 +82,6 @@ misconfigured the CLI’s arguments.`
Benchmark.start(options, 'parse/fetch parsed files');
const elmParserPath = options.elmParserPath(elmSyntaxVersion);
elmParser.prepareWorkers();
const elmFilesToRead = [
...new Set(filesInDirectories.flatMap((directory) => directory.files))
];
const elmFiles = await Promise.all(
elmFilesToRead.map(
async (filePath) =>
Expand Down
24 changes: 24 additions & 0 deletions test/project-empty/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
Empty file.
8 changes: 8 additions & 0 deletions test/review.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ test('Running on project with unknown file', async () => {
expect(output).toMatchFile(testName('run-with-unknown-target'));
});

test('Running on project with no files', async () => {
const output = await TestCli.runAndExpectError(
['--config=../project-with-errors/review'],
{project: 'project-empty'}
);
expect(output).toMatchFile(testName('run-with-empty-project'));
});

test('Running on project with a directory ending in .elm (without arg)', async () => {
const output = await TestCli.run(
['--config', '../config-that-triggers-no-errors'],
Expand Down
6 changes: 6 additions & 0 deletions test/snapshots/review/run-with-empty-project.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- NO FILES FOUND --------------------------------------------------------------

I could not find any files in this project. I looked in these folders:
- <local-path>/test/project-empty/src
- <local-path>/test/project-empty/tests

0 comments on commit 949725a

Please # to comment.