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 11import validateOptions from 'schema-utils' ;
22
33import schema from './options.json' ;
4+ import getCLIEngine from './getCLIEngine' ;
45
56export default function getOptions ( pluginOptions ) {
67 const options = {
7- eslintPath : 'eslint' ,
88 files : '.' ,
99 ...pluginOptions ,
1010 } ;
@@ -14,7 +14,7 @@ export default function getOptions(pluginOptions) {
1414 baseDataPath : 'options' ,
1515 } ) ;
1616
17- const { CLIEngine } = require ( options . eslintPath ) ;
17+ const { CLIEngine } = getCLIEngine ( options , false ) ;
1818
1919 options . formatter = getFormatter ( CLIEngine , options . formatter ) ;
2020
Original file line number Diff line number Diff line change @@ -3,11 +3,11 @@ import { isAbsolute, join } from 'path';
33import { writeFileSync , ensureFileSync } from 'fs-extra' ;
44
55import ESLintError from './ESLintError' ;
6+ import getCLIEngine from './getCLIEngine' ;
67
78export default function linter ( options , compiler , callback ) {
89 try {
9- const { CLIEngine } = require ( options . eslintPath ) ;
10- const cli = new CLIEngine ( options ) ;
10+ const { CLIEngine, cli } = getCLIEngine ( options ) ;
1111 const report = cli . executeOnFiles ( options . files ) ;
1212
1313 // filter ignored files
You can’t perform that action at this time.
0 commit comments