@@ -2,10 +2,12 @@ import fs, {promises as fsAsync} from 'node:fs';
22import path from 'node:path' ;
33import process from 'node:process' ;
44import test from 'ava' ;
5- import { ESLint } from 'eslint' ;
5+ import eslintExperimentalApis from 'eslint/use-at-your-own-risk ' ;
66import * as eslintrc from '@eslint/eslintrc' ;
77import eslintPluginUnicorn from '../index.js' ;
88
9+ const { FlatESLint} = eslintExperimentalApis ;
10+
911let ruleFiles ;
1012
1113test . before ( async ( ) => {
@@ -76,13 +78,10 @@ test('Every rule is defined in index file in alphabetical order', t => {
7678
7779test ( 'validate configuration' , async t => {
7880 const results = await Promise . all (
79- Object . entries ( eslintPluginUnicorn . configs ) . filter ( ( [ name ] ) => ! name . startsWith ( 'flat/' ) ) . map ( async ( [ name , config ] ) => {
80- const eslint = new ESLint ( {
81+ Object . entries ( eslintPluginUnicorn . configs ) . filter ( ( [ name ] ) => name . startsWith ( 'flat/' ) ) . map ( async ( [ name , config ] ) => {
82+ const eslint = new FlatESLint ( {
8183 baseConfig : config ,
82- useEslintrc : false ,
83- plugins : {
84- unicorn : eslintPluginUnicorn ,
85- } ,
84+ overrideConfigFile : true ,
8685 } ) ;
8786
8887 const result = await eslint . calculateConfigForFile ( 'dummy.js' ) ;
@@ -98,68 +97,6 @@ test('validate configuration', async t => {
9897 `Configuration for "${ name } " is invalid.` ,
9998 ) ;
10099 }
101-
102- // `env`
103- {
104- // https://github.com/eslint/eslint/blob/32ac37a76b2e009a8f106229bc7732671d358189/conf/globals.js#L19
105- const testObjects = [
106- 'undefinedGlobalObject' ,
107- // `es3`
108- 'Array' ,
109- // `es5`
110- 'JSON' ,
111- // `es2015`(`es6`)
112- 'Promise' ,
113- // `es2021`
114- 'WeakRef' ,
115- ] ;
116- const baseOptions = {
117- useEslintrc : false ,
118- plugins : {
119- unicorn : eslintPluginUnicorn ,
120- } ,
121- overrideConfig : {
122- rules : {
123- 'no-undef' : 'error' ,
124- } ,
125- } ,
126- } ;
127- const getUndefinedGlobals = async options => {
128- const [ { messages} ] = await new ESLint ( { ...baseOptions , ...options } ) . lintText ( testObjects . join ( ';\n' ) ) ;
129- return messages . map ( ( { message} ) => message . match ( / ^ ' (?< object > .* ) ' i s n o t d e f i n e d \. $ / ) . groups . object ) ;
130- } ;
131-
132- t . deepEqual ( await getUndefinedGlobals ( ) , [ 'undefinedGlobalObject' , 'Promise' , 'WeakRef' ] ) ;
133- t . deepEqual ( await getUndefinedGlobals ( { baseConfig : eslintPluginUnicorn . configs . recommended } ) , [ 'undefinedGlobalObject' ] ) ;
134-
135- const availableEnvironments = [ ...eslintrc . Legacy . environments . keys ( ) ] . filter ( name => / ^ e s \d + $ / . test ( name ) ) ;
136- const recommendedEnvironments = Object . keys ( eslintPluginUnicorn . configs . recommended . env ) ;
137- t . is ( recommendedEnvironments . length , 1 ) ;
138- t . is (
139- availableEnvironments . at ( - 1 ) ,
140- recommendedEnvironments [ 0 ] ,
141- 'env should be the latest es version' ,
142- ) ;
143- }
144-
145- // `sourceType`
146- {
147- const text = 'import fs from "node:fs";' ;
148- const baseOptions = {
149- useEslintrc : false ,
150- plugins : {
151- unicorn : eslintPluginUnicorn ,
152- } ,
153- } ;
154- const runEslint = async options => {
155- const [ { messages} ] = await new ESLint ( { ...baseOptions , ...options } ) . lintText ( text ) ;
156- return messages ;
157- } ;
158-
159- const [ { message} ] = await runEslint ( ) ;
160- t . is ( message , 'Parsing error: The keyword \'import\' is reserved' ) ;
161- t . deepEqual ( await runEslint ( { baseConfig : eslintPluginUnicorn . configs . recommended } ) , [ ] ) ;
162- }
163100} ) ;
164101
165102test ( 'Every rule has valid meta.type' , t => {
0 commit comments