@@ -4,6 +4,8 @@ import eslintrc from '..';
44import reactRules from '../rules/react' ;
55import reactA11yRules from '../rules/react-a11y' ;
66
7+ const isFlat = ESLint . configType === 'flat' ;
8+
79const rules = {
810 // It is okay to import devDependencies in tests.
911 'import/no-extraneous-dependencies' : [ 2 , { devDependencies : true } ] ,
@@ -12,17 +14,32 @@ const rules = {
1214 // otherwise we need some junk in our fixture code
1315 'react/no-unused-class-component-methods' : 0 ,
1416} ;
15- const cli = new ( CLIEngine || ESLint ) ( {
16- useEslintrc : false ,
17- baseConfig : eslintrc ,
18- ...( CLIEngine ? { rules } : { overrideConfig : { rules } } ) ,
19- } ) ;
17+
18+ function createCli ( ) {
19+ if ( isFlat ) {
20+ // eslint-disable-next-line global-require
21+ const flatConfig = require ( '../flat' ) ;
22+ return new ESLint ( {
23+ overrideConfigFile : true ,
24+ overrideConfig : [ ...flatConfig , { rules } ] ,
25+ } ) ;
26+ }
27+ return new ( CLIEngine || ESLint ) ( {
28+ useEslintrc : false ,
29+ baseConfig : eslintrc ,
30+ ...( CLIEngine ? { rules } : { overrideConfig : { rules } } ) ,
31+ } ) ;
32+ }
33+ const cli = createCli ( ) ;
2034
2135async function lint ( text ) {
2236 // @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles
2337 // @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeontext
24- const linter = CLIEngine ? cli . executeOnText ( text ) : await cli . lintText ( text ) ;
25- return ( CLIEngine ? linter . results : linter ) [ 0 ] ;
38+ if ( CLIEngine ) {
39+ return cli . executeOnText ( text ) . results [ 0 ] ;
40+ }
41+ const results = await cli . lintText ( text , isFlat ? { filePath : 'test.jsx' } : undefined ) ;
42+ return results [ 0 ] ;
2643}
2744
2845function wrapComponent ( body ) {
0 commit comments