Skip to content

Commit 8384a38

Browse files
committed
fix: remove string values from ignorePatterns if they exist
1 parent fea1e6b commit 8384a38

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/rules/utils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ const compileConfigCode = (fileCode: string): ESLint.Linter.Config => {
5050
const createCliEngineCache = new Map<string, ESLint.CLIEngine>();
5151

5252
const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
53+
const extraConfig: ESLint.Linter.Config = {
54+
parserOptions: {
55+
...config.parserOptions,
56+
project: require.resolve('../../tsconfig.fake.json'),
57+
projectFolderIgnoreList: []
58+
}
59+
};
60+
61+
if (config.ignorePatterns) {
62+
const patterns = Array.isArray(config.ignorePatterns)
63+
? config.ignorePatterns
64+
: [config.ignorePatterns];
65+
66+
extraConfig.ignorePatterns = patterns.filter(
67+
pattern => typeof pattern !== 'string'
68+
);
69+
}
70+
5371
return getsertCache(
5472
createCliEngineCache,
5573
JSON.stringify(config),
@@ -62,11 +80,7 @@ const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
6280
envs: ['node'],
6381
baseConfig: {
6482
...config,
65-
parserOptions: {
66-
...config.parserOptions,
67-
project: require.resolve('../../tsconfig.fake.json'),
68-
projectFolderIgnoreList: []
69-
}
83+
...extraConfig
7084
}
7185
}),
7286
'createCLIEngine'

test/src/rules/no-invalid-config.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ ruleTester.run('no-invalid-config', rule, {
2626
valid: [
2727
'module.exports = undefined;',
2828
'module.exports = "";',
29+
'module.exports = { ignorePatterns: ["node_modules/"] }',
30+
'module.exports = { ignorePatterns: "node_modules/" }',
2931
dedent`
3032
const { files } = require('./package.json');
3133
@@ -748,6 +750,21 @@ ruleTester.run('InvalidConfig', rule, {
748750
column: 1
749751
})
750752
]
753+
},
754+
{
755+
code: 'module.exports = { ignorePatterns: [1] }',
756+
errors: [
757+
expectedError({
758+
type: ESLintErrorType.InvalidConfig,
759+
reason: [
760+
'\n\t- Property "ignorePatterns" is the wrong type (expected string but got `[1]`).',
761+
'\n\t- Property "ignorePatterns[0]" is the wrong type (expected string but got `1`).',
762+
'\n\t- "ignorePatterns" should match exactly one schema in oneOf. Value: [1].'
763+
].join(''),
764+
line: 1,
765+
column: 1
766+
})
767+
]
751768
}
752769
]
753770
});

0 commit comments

Comments
 (0)