1
- import ESLint from 'eslint' ;
1
+ import { CLIEngine , Linter } from 'eslint' ;
2
2
import requireRelative from 'require-relative' ;
3
3
import { runInNewContext } from 'vm' ;
4
4
@@ -32,25 +32,25 @@ const relativeRequire = (name: string): unknown =>
32
32
relativeRequire . resolve = ( name : string ) : string =>
33
33
requireRelative . resolve ( name , process . cwd ( ) ) ;
34
34
35
- const compileConfigCodeCache = new Map < string , ESLint . Linter . Config > ( ) ;
35
+ const compileConfigCodeCache = new Map < string , Linter . Config > ( ) ;
36
36
37
- const compileConfigCode = ( fileCode : string ) : ESLint . Linter . Config => {
37
+ const compileConfigCode = ( fileCode : string ) : Linter . Config => {
38
38
return getsertCache (
39
39
compileConfigCodeCache ,
40
40
fileCode ,
41
41
( ) =>
42
42
( runInNewContext ( fileCode , {
43
43
module : { exports : { } } ,
44
44
require : relativeRequire
45
- } ) ?? { } ) as ESLint . Linter . Config ,
45
+ } ) ?? { } ) as Linter . Config ,
46
46
'compileConfigCode'
47
47
) ;
48
48
} ;
49
49
50
- const createCliEngineCache = new Map < string , ESLint . CLIEngine > ( ) ;
50
+ const createCliEngineCache = new Map < string , CLIEngine > ( ) ;
51
51
52
- const createCLIEngine = ( config : ESLint . Linter . Config ) : ESLint . CLIEngine => {
53
- const extraConfig : ESLint . Linter . Config = {
52
+ const createCLIEngine = ( config : Linter . Config ) : CLIEngine => {
53
+ const extraConfig : Linter . Config = {
54
54
parserOptions : {
55
55
...config . parserOptions ,
56
56
project : require . resolve ( '../../tsconfig.fake.json' ) ,
@@ -72,7 +72,7 @@ const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
72
72
createCliEngineCache ,
73
73
JSON . stringify ( config ) ,
74
74
( ) =>
75
- new ESLint . CLIEngine ( {
75
+ new CLIEngine ( {
76
76
useEslintrc : false ,
77
77
ignorePath : pathToBlankFile ,
78
78
ignorePattern : [ '!node_modules/*' ] ,
@@ -88,7 +88,7 @@ const createCLIEngine = (config: ESLint.Linter.Config): ESLint.CLIEngine => {
88
88
} ;
89
89
90
90
interface ConfigInfo {
91
- deprecatedRules : ESLint . CLIEngine . DeprecatedRuleUse [ ] ;
91
+ deprecatedRules : CLIEngine . DeprecatedRuleUse [ ] ;
92
92
unknownRules : string [ ] ;
93
93
errors : ESLintError [ ] ;
94
94
}
@@ -107,10 +107,7 @@ const ensureArray = <T>(v: T | T[] = []): T[] => (Array.isArray(v) ? v : [v]);
107
107
* Merging is done at the top level only, and based on explicit named properties,
108
108
* so any additional properties on either config will be lost.
109
109
*/
110
- const mergeConfigs = (
111
- a : ESLint . Linter . Config ,
112
- b : ESLint . Linter . Config
113
- ) : ESLint . Linter . Config => ( {
110
+ const mergeConfigs = ( a : Linter . Config , b : Linter . Config ) : Linter . Config => ( {
114
111
parser : b . parser ?? a . parser ,
115
112
parserOptions : { ...a . parserOptions , ...b . parserOptions } ,
116
113
processor : b . processor ?? a . processor ,
@@ -126,9 +123,7 @@ const mergeConfigs = (
126
123
rules : { ...a . rules , ...b . rules }
127
124
} ) ;
128
125
129
- const extractRelevantConfigs = (
130
- config : ESLint . Linter . Config
131
- ) : ESLint . Linter . Config [ ] => [
126
+ const extractRelevantConfigs = ( config : Linter . Config ) : Linter . Config [ ] => [
132
127
{ ...config , overrides : [ ] } ,
133
128
...( config . overrides ?? [ ] )
134
129
. map ( override =>
@@ -279,9 +274,9 @@ const parseESLintError = (error: Error): ESLintError => {
279
274
} ;
280
275
281
276
const followErrorPathToConfig = (
282
- config : ESLint . Linter . Config ,
277
+ config : Linter . Config ,
283
278
error : ESLintError
284
- ) : ESLint . Linter . Config => {
279
+ ) : Linter . Config => {
285
280
if ( ! error . path || ! config . overrides ) {
286
281
return config ;
287
282
}
@@ -296,7 +291,7 @@ const followErrorPathToConfig = (
296
291
} ;
297
292
298
293
const tryRemoveErrorPointFromConfig = (
299
- config : ESLint . Linter . Config ,
294
+ config : Linter . Config ,
300
295
error : ESLintError
301
296
) : boolean => {
302
297
const configToDeleteFrom = followErrorPathToConfig ( config , error ) ;
@@ -350,9 +345,7 @@ const tryRemoveErrorPointFromConfig = (
350
345
return false ;
351
346
} ;
352
347
353
- const collectConfigInfoFromESLint = (
354
- config : ESLint . Linter . Config
355
- ) : ConfigInfo => {
348
+ const collectConfigInfoFromESLint = ( config : Linter . Config ) : ConfigInfo => {
356
349
const theConfig = { rules : { } , ...config } ;
357
350
const errors : ESLintError [ ] = [ ] ;
358
351
let counter = 0 ;
@@ -406,7 +399,7 @@ const collectConfigInfoCache = new Map<string, ConfigInfo>();
406
399
* Info about any `overrides` the `config` might have will be collected and
407
400
* merged into the returned info object.
408
401
*/
409
- const collectConfigInfo = ( config : ESLint . Linter . Config ) : ConfigInfo => {
402
+ const collectConfigInfo = ( config : Linter . Config ) : ConfigInfo => {
410
403
return getsertCache (
411
404
collectConfigInfoCache ,
412
405
JSON . stringify ( config ) ,
0 commit comments