File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change
1
+ export default function getCLIEngine ( options , startCli = true ) {
2
+ let { eslintPath, CLIEngine, cli } = options ;
3
+
4
+ if ( ! eslintPath ) {
5
+ eslintPath = 'eslint' ;
6
+
7
+ // eslint-disable-next-line no-param-reassign
8
+ options . eslintPath = eslintPath ;
9
+ }
10
+
11
+ if ( ! CLIEngine ) {
12
+ ( { CLIEngine } = require ( eslintPath ) ) ;
13
+
14
+ // eslint-disable-next-line no-param-reassign
15
+ options . CLIEngine = CLIEngine ;
16
+ }
17
+
18
+ if ( ! cli && startCli ) {
19
+ cli = new CLIEngine ( options ) ;
20
+
21
+ // eslint-disable-next-line no-param-reassign
22
+ options . cli = cli ;
23
+ }
24
+
25
+ return {
26
+ eslintPath,
27
+ CLIEngine,
28
+ cli,
29
+ } ;
30
+ }
Original file line number Diff line number Diff line change 1
1
import validateOptions from 'schema-utils' ;
2
2
3
3
import schema from './options.json' ;
4
+ import getCLIEngine from './getCLIEngine' ;
4
5
5
6
export default function getOptions ( pluginOptions ) {
6
7
const options = {
7
- eslintPath : 'eslint' ,
8
8
files : '.' ,
9
9
...pluginOptions ,
10
10
} ;
@@ -14,7 +14,7 @@ export default function getOptions(pluginOptions) {
14
14
baseDataPath : 'options' ,
15
15
} ) ;
16
16
17
- const { CLIEngine } = require ( options . eslintPath ) ;
17
+ const { CLIEngine } = getCLIEngine ( options , false ) ;
18
18
19
19
options . formatter = getFormatter ( CLIEngine , options . formatter ) ;
20
20
Original file line number Diff line number Diff line change @@ -3,11 +3,11 @@ import { isAbsolute, join } from 'path';
3
3
import { writeFileSync , ensureFileSync } from 'fs-extra' ;
4
4
5
5
import ESLintError from './ESLintError' ;
6
+ import getCLIEngine from './getCLIEngine' ;
6
7
7
8
export default function linter ( options , compiler , callback ) {
8
9
try {
9
- const { CLIEngine } = require ( options . eslintPath ) ;
10
- const cli = new CLIEngine ( options ) ;
10
+ const { CLIEngine, cli } = getCLIEngine ( options ) ;
11
11
const report = cli . executeOnFiles ( options . files ) ;
12
12
13
13
// filter ignored files
You can’t perform that action at this time.
0 commit comments