Skip to content

Commit

Permalink
Merge pull request #244 from mizdra/support-ignore-path
Browse files Browse the repository at this point in the history
Support `--ignore-path` option
  • Loading branch information
mizdra authored Dec 7, 2022
2 parents de83365 + 20d0a15 commit 04dcf37
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Options:
--version Show version number [boolean]
--rulesdir Use additional rules from this directory [array]
--ext Specify JavaScript file extensions [array]
--ignore-path Specify path of ignore file [string]
--format Specify the format to be used for the `Display problem messa
ges` action [string] [default: "codeframe"]
--quiet Report errors only [boolean] [default: false]
Expand Down
1 change: 1 addition & 0 deletions fixtures/.customignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
warning.js
4 changes: 4 additions & 0 deletions src/cli/parse-argv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ describe('parseArgv', () => {
expect(parseArgv([...baseArgs, '--rulesdir', 'foo', 'bar']).rulePaths).toStrictEqual(['foo']);
expect(parseArgv([...baseArgs, '--rulesdir', '1', '--rulesdir', 'true']).rulePaths).toStrictEqual(['1', 'true']);
});
test('--ignore-path', () => {
expect(parseArgv([...baseArgs]).ignorePath).toStrictEqual(undefined);
expect(parseArgv([...baseArgs, '--ignore-path', 'foo']).ignorePath).toStrictEqual('foo');
});
test('--ext', () => {
expect(parseArgv([...baseArgs, '--ext', 'js']).extensions).toStrictEqual(['js']);
expect(parseArgv([...baseArgs, '--ext', 'js', '--ext', 'ts']).extensions).toStrictEqual(['js', 'ts']);
Expand Down
7 changes: 7 additions & 0 deletions src/cli/parse-argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export function parseArgv(argv: string[]): Config {
type: 'array',
describe: 'Specify JavaScript file extensions',
})
// Following ESLint, --ignore-path accepts only one path. However, this limitation may be relaxed in the future.
// ref: https://github.com/eslint/eslint/issues/9794
.option('ignore-path', {
type: 'string',
describe: 'Specify path of ignore file',
})
.nargs('ext', 1)
.option('format', {
type: 'string',
Expand Down Expand Up @@ -50,6 +56,7 @@ export function parseArgv(argv: string[]): Config {
return {
patterns,
rulePaths,
ignorePath: parsedArgv.ignorePath,
extensions,
formatterName,
quiet: parsedArgv.quiet,
Expand Down
14 changes: 14 additions & 0 deletions src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ describe('Core', () => {
const resultsWithQuiet = await coreWithQuiet.lint();
expect(countWarnings(resultsWithQuiet)).toEqual(0);
});
test('ignores files with --ignore-path option', async () => {
const coreWithoutIgnorePath = new Core({
...core.config,
});
const resultsWithoutIgnorePath = await coreWithoutIgnorePath.lint();
expect(countWarnings(resultsWithoutIgnorePath)).not.toEqual(0);

const coreWithIgnorePath = new Core({
...core.config,
ignorePath: 'fixtures-tmp/.customignore',
});
const resultsWithIgnorePath = await coreWithIgnorePath.lint();
expect(countWarnings(resultsWithIgnorePath)).toEqual(0);
});
});
// This test fails because the documentation url is not supported in eslint 7.0.0. Therefore, ignore this test.
testIf(ESLint.version !== '7.0.0')('printSummaryOfResults', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type Undo = () => Promise<void>;
/** The config of eslint-interactive */
export type Config = Pick<
ESLint.Options,
'extensions' | 'rulePaths' | 'cache' | 'cacheLocation' | 'useEslintrc' | 'overrideConfig' | 'cwd'
'extensions' | 'rulePaths' | 'ignorePath' | 'cache' | 'cacheLocation' | 'useEslintrc' | 'overrideConfig' | 'cwd'
> & {
patterns: string[];
formatterName?: string;
Expand Down

0 comments on commit 04dcf37

Please sign in to comment.