Skip to content

fix(cli): throw error if no file found to lint #2778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/cli/src/services/__tests__/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ describe('Linter service', () => {
);
});

it('demands a file to be present', () => {
return expect(run('lint -r ./gh-474/ruleset.js ./gh-474/does-not-exist.json')).rejects.toThrow(
'No files found to lint. Please check your file path and extension and try again',
);
});

describe('when document is local file', () => {
describe('and the file is expected to have no warnings', () => {
it('outputs no issues', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/services/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export async function lint(documents: Array<number | string>, flags: ILintConfig
}
}

for (const targetUri of [...targetUris, ...fileDescriptors]) {
const targets = [...targetUris, ...fileDescriptors];
if (targets.length === 0) {
throw new CLIError(`No files found to lint. Please check your file path and extension and try again`);
}

for (const targetUri of targets) {
if (flags.verbose === true) {
console.info(`Linting ${targetUri}`);
}
Expand Down