Skip to content

Commit d3fd59c

Browse files
committed
fix: support configs with @typescript-eslint type-checking rules
While the ESLint api provides `executeOnText`, type checking services that power some of rules offered by `@typescript-eslint` use TypeScript, which requires a file on disk. Additionally, both ESLint & `@typescript-eslint` include `node_modules` in their default ignores, so we need to explicitly un-ignore our blank file as well as prevent ESLint from using any `.eslintignore` files that might exist.
1 parent 0a4b833 commit d3fd59c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/blank.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#! blank file used as an ignore for eslint, and as a js file for @typescript-eslint

src/rules/utils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import ESLint from 'eslint';
22
import requireRelative from 'require-relative';
33
import { runInNewContext } from 'vm';
44

5+
const pathToBlankFile = require.resolve('../blank.js');
6+
57
const getsertCache = <T>(
68
cache: Map<string, T>,
79
key: string,
@@ -54,13 +56,16 @@ const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
5456
() =>
5557
new ESLint.CLIEngine({
5658
useEslintrc: false,
59+
ignorePath: pathToBlankFile,
60+
ignorePattern: ['!node_modules/*'],
5761
cache: false,
5862
envs: ['node'],
5963
baseConfig: {
6064
...config,
6165
parserOptions: {
6266
...config.parserOptions,
63-
project: require.resolve('../../tsconfig.fake.json')
67+
project: require.resolve('../../tsconfig.fake.json'),
68+
projectFolderIgnoreList: []
6469
}
6570
}
6671
}),
@@ -343,7 +348,10 @@ const collectConfigInfoFromESLint = (
343348
}
344349

345350
try {
346-
const results = createCLIEngine(theConfig).executeOnText('');
351+
const results = createCLIEngine(theConfig).executeOnText(
352+
'',
353+
pathToBlankFile
354+
);
347355

348356
return {
349357
deprecatedRules: results.usedDeprecatedRules,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ruleTester.run('no-invalid-config', rule, {
9191
data: {
9292
message: dedent`
9393
Unable to parse error from ESLint: Error while loading rule 'prettier/erroneous-rule': explosions!
94-
Occurred while linting <text>
94+
Occurred while linting ${require.resolve('../../../src/blank.js')}
9595
`.trim()
9696
},
9797
line: 1,

0 commit comments

Comments
 (0)