File tree Expand file tree Collapse file tree 4 files changed +17
-7
lines changed
packages/plugin-eslint/src/lib Expand file tree Collapse file tree 4 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import type { ConfigFormat } from './formats';
5
5
import { loadRulesForLegacyConfig } from './legacy' ;
6
6
7
7
export { detectConfigVersion } from './detect' ;
8
+ export type { ConfigFormat } from './formats' ;
8
9
9
10
export function selectRulesLoader (
10
11
version : ConfigFormat ,
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export async function loadRulesForLegacyConfig({
8
8
eslintrc,
9
9
patterns,
10
10
} : ESLintTarget ) : Promise < RuleData [ ] > {
11
- const eslint = setupESLint ( eslintrc ) ;
11
+ const eslint = await setupESLint ( eslintrc ) ;
12
12
13
13
const configs = await toArray ( patterns ) . reduce (
14
14
async ( acc , pattern ) => [
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ export async function lint({
15
15
patterns,
16
16
} : ESLintTarget ) : Promise < LinterOutput > {
17
17
const results = await executeLint ( { eslintrc, patterns } ) ;
18
- const ruleOptionsPerFile = await loadRuleOptionsPerFile ( eslintrc , results ) ;
18
+ const eslint = await setupESLint ( eslintrc ) ;
19
+ const ruleOptionsPerFile = await loadRuleOptionsPerFile ( eslint , results ) ;
19
20
return { results, ruleOptionsPerFile } ;
20
21
}
21
22
@@ -45,11 +46,9 @@ async function executeLint({
45
46
}
46
47
47
48
function loadRuleOptionsPerFile (
48
- eslintrc : ESLintTarget [ 'eslintrc' ] ,
49
+ eslint : ESLint ,
49
50
results : ESLint . LintResult [ ] ,
50
51
) : Promise < RuleOptionsPerFile > {
51
- const eslint = setupESLint ( eslintrc ) ;
52
-
53
52
return results . reduce ( async ( acc , { filePath, messages } ) => {
54
53
const filesMap = await acc ;
55
54
const config = ( await eslint . calculateConfigForFile (
Original file line number Diff line number Diff line change 1
1
import { ESLint } from 'eslint' ;
2
2
import type { ESLintTarget } from './config' ;
3
3
4
- export function setupESLint ( eslintrc : ESLintTarget [ 'eslintrc' ] ) {
5
- return new ESLint ( {
4
+ export async function setupESLint ( eslintrc : ESLintTarget [ 'eslintrc' ] ) {
5
+ const eslintConstructor = await loadESLint ( ) ;
6
+ return new eslintConstructor ( {
6
7
overrideConfigFile : eslintrc ,
7
8
errorOnUnmatchedPattern : false ,
8
9
} ) ;
9
10
}
11
+
12
+ async function loadESLint ( ) {
13
+ const eslint = await import ( 'eslint' ) ;
14
+ // loadESLint added to public API in v9, selects ESLint or LegacyESLint based on environment
15
+ if ( 'loadESLint' in eslint && typeof eslint . loadESLint === 'function' ) {
16
+ return ( await eslint . loadESLint ( ) ) as typeof ESLint ;
17
+ }
18
+ return ESLint ;
19
+ }
You can’t perform that action at this time.
0 commit comments