@@ -48,7 +48,12 @@ function emitError (obj) {
48
48
process . stderr . write ( `${ obj } \n` ) ;
49
49
}
50
50
51
+ function log ( message ) {
52
+ emit ( { log : message } ) ;
53
+ }
54
+
51
55
function getPathRoot ( filePath , eslintPath ) {
56
+ log ( `getPathRoot ${ filePath } // ${ eslintPath } ` ) ;
52
57
filePath = normalize ( filePath ) . split ( sep ) ;
53
58
eslintPath = normalize ( eslintPath ) . split ( sep ) ;
54
59
@@ -83,35 +88,26 @@ function clearESLintCache () {
83
88
}
84
89
}
85
90
86
- function getESLint ( filePath , projectPath , config , { legacyPackagePresent } ) {
87
- // `eslint` will get resolved relative to the path of the file we're going to
88
- // lint — unless the user has specified their own `localNodeModules` path.
89
- let { advanced : { localNodeModules } } = config ;
90
- let resolvePath = filePath ;
91
- if ( localNodeModules ) {
92
- resolvePath = normalize ( [ projectPath , localNodeModules ] . join ( sep ) ) ;
91
+ function resolveESLint ( filePath ) {
92
+ try {
93
+ return createRequire ( filePath ) . resolve ( 'eslint' ) ;
94
+ } catch ( e ) {
95
+ return createRequire ( __dirname ) . resolve ( 'eslint' ) ;
93
96
}
97
+ }
94
98
95
- if ( ! PATHS_CACHE [ resolvePath ] ) {
96
- PATHS_CACHE [ resolvePath ] = createRequire ( resolvePath ) . resolve ( 'eslint' ) ;
99
+ function getESLint ( filePath , projectPath , config , { legacyPackagePresent } ) {
100
+ if ( ! PATHS_CACHE [ filePath ] ) {
101
+ PATHS_CACHE [ filePath ] = resolveESLint ( filePath ) ;
97
102
}
98
103
99
- const eslintPath = PATHS_CACHE [ filePath ] ;
100
- const eslintRootPath = eslintPath . replace ( / e s l i n t ( [ / \\ ] ) .* ?$ / , 'eslint$1' ) ;
104
+ let eslintPath = PATHS_CACHE [ filePath ] ;
101
105
102
106
if ( ! ESLINT_CACHE [ eslintPath ] ) {
107
+ const eslintRootPath = eslintPath . replace ( / e s l i n t ( [ / \\ ] ) .* ?$ / , 'eslint$1' ) ;
103
108
const packageMeta = require ( join ( eslintRootPath , 'package.json' ) ) ;
104
- if ( compareVersions ( packageMeta . version , MINIMUM_ESLINT_VERSION ) < 1 ) {
105
- // Unsupported version.
106
- throw new IncompatibleVersionError ( packageMeta . version ) ;
107
- } if ( ( compareVersions ( packageMeta . version , '8.0.0' ) < 1 ) && legacyPackagePresent ) {
108
- // We're dealing with version 7 of ESLint. The legacy `linter-eslint`
109
- // package is present and capable of linting with this version, so we
110
- // should halt instead of trying to lint everything twice.
111
- throw new VersionOverlapError ( packageMeta . version ) ;
112
- }
113
109
114
- const { ESLint } = createRequire ( filePath ) ( 'eslint' ) ;
110
+ let { ESLint } = createRequire ( eslintPath ) ( 'eslint' ) ;
115
111
let commonOptions = buildCommonConstructorOptions ( config ) ;
116
112
117
113
// `fix` is a predicate in `commonOptions` and represents the "yes,
@@ -123,9 +119,23 @@ function getESLint (filePath, projectPath, config, { legacyPackagePresent }) {
123
119
eslintFix : new ESLint ( { ...commonOptions } ) ,
124
120
workingDir : getPathRoot ( filePath , eslintPath ) ,
125
121
eslintPath : eslintRootPath ,
126
- eslintVersion : packageMeta . version
122
+ eslintVersion : packageMeta . version ,
123
+ isBuiltIn : eslintPath === PATHS_CACHE [ __dirname ]
127
124
} ;
128
125
}
126
+
127
+ let cache = ESLINT_CACHE [ eslintPath ] ;
128
+
129
+ if ( compareVersions ( cache . eslintVersion , MINIMUM_ESLINT_VERSION ) < 1 ) {
130
+ // Unsupported version.
131
+ throw new IncompatibleVersionError ( cache . eslintVersion ) ;
132
+ } else if ( ( compareVersions ( cache . eslintVersion , '8.0.0' ) < 1 ) && legacyPackagePresent ) {
133
+ // We're dealing with version 7 of ESLint. The legacy `linter-eslint`
134
+ // package is present and capable of linting with this version, so we
135
+ // should halt instead of trying to lint everything twice.
136
+ throw new VersionOverlapError ( cache . eslintVersion ) ;
137
+ }
138
+
129
139
return ESLINT_CACHE [ eslintPath ] ;
130
140
}
131
141
@@ -173,7 +183,7 @@ function formatResults (files, rules, config, { isModified, key }) {
173
183
174
184
let idTag = '' ;
175
185
if ( showRuleIdInMessage && message . ruleId ) {
176
- idTag = `[ ${ message . ruleId } ] ` ;
186
+ idTag = ` ( ${ message . ruleId } ) ` ;
177
187
}
178
188
let position ;
179
189
if ( message . fatal ) {
@@ -202,7 +212,7 @@ function formatResults (files, rules, config, { isModified, key }) {
202
212
position,
203
213
} ,
204
214
fix : message . fix ,
205
- excerpt : `${ idTag } ${ message . message } `
215
+ excerpt : `${ message . message } ${ idTag } `
206
216
} ) ;
207
217
}
208
218
}
@@ -240,14 +250,14 @@ async function processMessage (bundle) {
240
250
return ;
241
251
}
242
252
243
- if ( ! projectPath ) {
244
- emit ( {
245
- key,
246
- error : `Must provide projectPath` ,
247
- type : 'no-project'
248
- } ) ;
249
- return ;
250
- }
253
+ // if (!projectPath) {
254
+ // emit({
255
+ // key,
256
+ // error: `Must provide projectPath`,
257
+ // type: 'no-project'
258
+ // });
259
+ // return;
260
+ // }
251
261
252
262
let eslint ;
253
263
try {
@@ -268,6 +278,7 @@ async function processMessage (bundle) {
268
278
type : 'version-overlap'
269
279
} ) ;
270
280
} else {
281
+ log ( `Error: ${ err . message } ` ) ;
271
282
emit ( {
272
283
key,
273
284
error : `Can't find an ESLint for file: ${ filePath } ` ,
@@ -278,7 +289,7 @@ async function processMessage (bundle) {
278
289
}
279
290
280
291
if ( type === 'debug' ) {
281
- let { eslintPath, eslintVersion } = eslint ;
292
+ let { eslintPath, eslintVersion, isBuiltIn } = eslint ;
282
293
let isIncompatible = compareVersions ( eslintVersion , MINIMUM_ESLINT_VERSION ) < 1 ;
283
294
let isOverlap = ( compareVersions ( eslintVersion , '8.0.0' ) < 1 ) && ! isIncompatible ;
284
295
emit ( {
@@ -287,7 +298,8 @@ async function processMessage (bundle) {
287
298
eslintPath,
288
299
eslintVersion,
289
300
isIncompatible,
290
- isOverlap
301
+ isOverlap,
302
+ isBuiltIn
291
303
} ) ;
292
304
return ;
293
305
}
0 commit comments