8
8
'use strict' ;
9
9
10
10
const minimatch = require ( 'minimatch' ) ;
11
- const CLIEngine = require ( 'eslint' ) . CLIEngine ;
11
+ const { ESLint } = require ( 'eslint' ) ;
12
12
const listChangedFiles = require ( '../shared/listChangedFiles' ) ;
13
13
14
14
const allPaths = [ '**/*.js' ] ;
15
15
16
16
let changedFiles = null ;
17
17
18
- function runESLintOnFilesWithOptions ( filePatterns , onlyChanged , options ) {
19
- const cli = new CLIEngine ( options ) ;
20
- const formatter = cli . getFormatter ( ) ;
18
+ async function runESLintOnFilesWithOptions ( filePatterns , onlyChanged , options ) {
19
+ const eslint = new ESLint ( options ) ;
20
+ const formatter = await eslint . loadFormatter ( ) ;
21
21
22
22
if ( onlyChanged && changedFiles === null ) {
23
23
// Calculate lazily.
@@ -26,15 +26,15 @@ function runESLintOnFilesWithOptions(filePatterns, onlyChanged, options) {
26
26
const finalFilePatterns = onlyChanged
27
27
? intersect ( changedFiles , filePatterns )
28
28
: filePatterns ;
29
- const report = cli . executeOnFiles ( finalFilePatterns ) ;
29
+ const results = await eslint . lintFiles ( finalFilePatterns ) ;
30
30
31
31
if ( options != null && options . fix === true ) {
32
- CLIEngine . outputFixes ( report ) ;
32
+ await ESLint . outputFixes ( results ) ;
33
33
}
34
34
35
35
// When using `ignorePattern`, eslint will show `File ignored...` warnings for any ignores.
36
36
// We don't care because we *expect* some passed files will be ignores if `ignorePattern` is used.
37
- const messages = report . results . filter ( item => {
37
+ const messages = results . filter ( item => {
38
38
if ( ! onlyChanged ) {
39
39
// Don't suppress the message on a full run.
40
40
// We only expect it to happen for "only changed" runs.
@@ -45,11 +45,19 @@ function runESLintOnFilesWithOptions(filePatterns, onlyChanged, options) {
45
45
return ! ( item . messages [ 0 ] && item . messages [ 0 ] . message === ignoreMessage ) ;
46
46
} ) ;
47
47
48
- const ignoredMessageCount = report . results . length - messages . length ;
48
+ const errorCount = results . reduce (
49
+ ( count , result ) => count + result . errorCount ,
50
+ 0
51
+ ) ;
52
+ const warningCount = results . reduce (
53
+ ( count , result ) => count + result . warningCount ,
54
+ 0
55
+ ) ;
56
+ const ignoredMessageCount = results . length - messages . length ;
49
57
return {
50
- output : formatter ( messages ) ,
51
- errorCount : report . errorCount ,
52
- warningCount : report . warningCount - ignoredMessageCount ,
58
+ output : formatter . format ( messages ) ,
59
+ errorCount : errorCount ,
60
+ warningCount : warningCount - ignoredMessageCount ,
53
61
} ;
54
62
}
55
63
@@ -64,11 +72,11 @@ function intersect(files, patterns) {
64
72
return [ ...new Set ( intersection ) ] ;
65
73
}
66
74
67
- function runESLint ( { onlyChanged, ...options } ) {
75
+ async function runESLint ( { onlyChanged, ...options } ) {
68
76
if ( typeof onlyChanged !== 'boolean' ) {
69
77
throw new Error ( 'Pass options.onlyChanged as a boolean.' ) ;
70
78
}
71
- const { errorCount, warningCount, output} = runESLintOnFilesWithOptions (
79
+ const { errorCount, warningCount, output} = await runESLintOnFilesWithOptions (
72
80
allPaths ,
73
81
onlyChanged ,
74
82
options
0 commit comments