@@ -4664,75 +4664,142 @@ describe("FlatESLint", () => {
46644664
46654665let eslint ;
46664666
4667- it ( "should throw an error when an invalid fix type is specified" , ( ) => {
4668- assert . throws ( ( ) => {
4667+ describe ( "fixTypes values validation" , ( ) => {
4668+ it ( "should throw an error when an invalid fix type is specified" , ( ) => {
4669+ assert . throws ( ( ) => {
4670+ eslint = new FlatESLint ( {
4671+ cwd :path . join ( fixtureDir , ".." ) ,
4672+ overrideConfigFile :true ,
4673+ fix :true ,
4674+ fixTypes :[ "layou" ]
4675+ } ) ;
4676+ } , / ' f i x T y p e s ' m u s t b e a n a r r a y o f a n y o f " d i r e c t i v e " , " p r o b l e m " , " s u g g e s t i o n " , a n d " l a y o u t " \. / iu) ;
4677+ } ) ;
4678+ } ) ;
4679+
4680+ describe ( "with lintFiles" , ( ) => {
4681+ it ( "should not fix any rules when fixTypes is used without fix" , async ( ) => {
4682+ eslint = new FlatESLint ( {
4683+ cwd :path . join ( fixtureDir , ".." ) ,
4684+ overrideConfigFile :true ,
4685+ fix :false ,
4686+ fixTypes :[ "layout" ]
4687+ } ) ;
4688+ const inputPath = getFixturePath ( "fix-types/fix-only-semi.js" ) ;
4689+ const results = await eslint . lintFiles ( [ inputPath ] ) ;
4690+
4691+ assert . strictEqual ( results [ 0 ] . output , void 0 ) ;
4692+ } ) ;
4693+
4694+ it ( "should not fix non-style rules when fixTypes has only 'layout'" , async ( ) => {
46694695eslint = new FlatESLint ( {
46704696cwd :path . join ( fixtureDir , ".." ) ,
46714697overrideConfigFile :true ,
46724698fix :true ,
4673- fixTypes :[ "layou " ]
4699+ fixTypes :[ "layout " ]
46744700} ) ;
4675- } , / ' f i x T y p e s ' m u s t b e a n a r r a y o f a n y o f " d i r e c t i v e " , " p r o b l e m " , " s u g g e s t i o n " , a n d " l a y o u t " \. / iu) ;
4676- } ) ;
4701+ const inputPath = getFixturePath ( "fix-types/fix-only-semi.js" ) ;
4702+ const outputPath = getFixturePath ( "fix-types/fix-only-semi.expected.js" ) ;
4703+ const results = await eslint . lintFiles ( [ inputPath ] ) ;
4704+ const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
46774705
4678- it ( "should not fix any rules when fixTypes is used without fix" , async ( ) => {
4679- eslint = new FlatESLint ( {
4680- cwd :path . join ( fixtureDir , ".." ) ,
4681- overrideConfigFile :true ,
4682- fix :false ,
4683- fixTypes :[ "layout" ]
4706+ assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
46844707} ) ;
4685- const inputPath = getFixturePath ( "fix-types/fix-only-semi.js" ) ;
4686- const results = await eslint . lintFiles ( [ inputPath ] ) ;
46874708
4688- assert . strictEqual ( results [ 0 ] . output , void 0 ) ;
4689- } ) ;
4709+ it ( "should not fix style or problem rules when fixTypes has only 'suggestion'" , async ( ) => {
4710+ eslint = new FlatESLint ( {
4711+ cwd :path . join ( fixtureDir , ".." ) ,
4712+ overrideConfigFile :true ,
4713+ fix :true ,
4714+ fixTypes :[ "suggestion" ]
4715+ } ) ;
4716+ const inputPath = getFixturePath ( "fix-types/fix-only-prefer-arrow-callback.js" ) ;
4717+ const outputPath = getFixturePath ( "fix-types/fix-only-prefer-arrow-callback.expected.js" ) ;
4718+ const results = await eslint . lintFiles ( [ inputPath ] ) ;
4719+ const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
46904720
4691- it ( "should not fix non-style rules when fixTypes has only 'layout'" , async ( ) => {
4692- eslint = new FlatESLint ( {
4693- cwd :path . join ( fixtureDir , ".." ) ,
4694- overrideConfigFile :true ,
4695- fix :true ,
4696- fixTypes :[ "layout" ]
4721+ assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
46974722} ) ;
4698- const inputPath = getFixturePath ( "fix-types/fix-only-semi.js" ) ;
4699- const outputPath = getFixturePath ( "fix-types/fix-only-semi.expected.js" ) ;
4700- const results = await eslint . lintFiles ( [ inputPath ] ) ;
4701- const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
47024723
4703- assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
4724+ it ( "should fix both style and problem rules when fixTypes has 'suggestion' and 'layout'" , async ( ) => {
4725+ eslint = new FlatESLint ( {
4726+ cwd :path . join ( fixtureDir , ".." ) ,
4727+ overrideConfigFile :true ,
4728+ fix :true ,
4729+ fixTypes :[ "suggestion" , "layout" ]
4730+ } ) ;
4731+ const inputPath = getFixturePath ( "fix-types/fix-both-semi-and-prefer-arrow-callback.js" ) ;
4732+ const outputPath = getFixturePath ( "fix-types/fix-both-semi-and-prefer-arrow-callback.expected.js" ) ;
4733+ const results = await eslint . lintFiles ( [ inputPath ] ) ;
4734+ const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
4735+
4736+ assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
4737+ } ) ;
47044738} ) ;
47054739
4706- it ( "should not fix style or problem rules when fixTypes has only 'suggestion'" , async ( ) => {
4707- eslint = new FlatESLint ( {
4708- cwd :path . join ( fixtureDir , ".." ) ,
4709- overrideConfigFile :true ,
4710- fix :true ,
4711- fixTypes :[ "suggestion" ]
4740+ describe ( "with lintText" , ( ) => {
4741+ it ( "should not fix any rules when fixTypes is used without fix" , async ( ) => {
4742+ eslint = new FlatESLint ( {
4743+ cwd :path . join ( fixtureDir , ".." ) ,
4744+ overrideConfigFile :true ,
4745+ fix :false ,
4746+ fixTypes :[ "layout" ]
4747+ } ) ;
4748+ const inputPath = getFixturePath ( "fix-types/fix-only-semi.js" ) ;
4749+ const content = fs . readFileSync ( inputPath , "utf8" ) ;
4750+ const results = await eslint . lintText ( content , { filePath :inputPath } ) ;
4751+
4752+ assert . strictEqual ( results [ 0 ] . output , void 0 ) ;
47124753} ) ;
4713- const inputPath = getFixturePath ( "fix-types/fix-only-prefer-arrow-callback.js" ) ;
4714- const outputPath = getFixturePath ( "fix-types/fix-only-prefer-arrow-callback.expected.js" ) ;
4715- const results = await eslint . lintFiles ( [ inputPath ] ) ;
4716- const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
47174754
4718- assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
4719- } ) ;
4755+ it ( "should not fix non-style rules when fixTypes has only 'layout'" , async ( ) => {
4756+ eslint = new FlatESLint ( {
4757+ cwd :path . join ( fixtureDir , ".." ) ,
4758+ overrideConfigFile :true ,
4759+ fix :true ,
4760+ fixTypes :[ "layout" ]
4761+ } ) ;
4762+ const inputPath = getFixturePath ( "fix-types/fix-only-semi.js" ) ;
4763+ const outputPath = getFixturePath ( "fix-types/fix-only-semi.expected.js" ) ;
4764+ const content = fs . readFileSync ( inputPath , "utf8" ) ;
4765+ const results = await eslint . lintText ( content , { filePath :inputPath } ) ;
4766+ const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
47204767
4721- it ( "should fix both style and problem rules when fixTypes has 'suggestion' and 'layout'" , async ( ) => {
4722- eslint = new FlatESLint ( {
4723- cwd :path . join ( fixtureDir , ".." ) ,
4724- overrideConfigFile :true ,
4725- fix :true ,
4726- fixTypes :[ "suggestion" , "layout" ]
4768+ assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
47274769} ) ;
4728- const inputPath = getFixturePath ( "fix-types/fix-both-semi-and-prefer-arrow-callback.js" ) ;
4729- const outputPath = getFixturePath ( "fix-types/fix-both-semi-and-prefer-arrow-callback.expected.js" ) ;
4730- const results = await eslint . lintFiles ( [ inputPath ] ) ;
4731- const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
47324770
4733- assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
4734- } ) ;
4771+ it ( "should not fix style or problem rules when fixTypes has only 'suggestion'" , async ( ) => {
4772+ eslint = new FlatESLint ( {
4773+ cwd :path . join ( fixtureDir , ".." ) ,
4774+ overrideConfigFile :true ,
4775+ fix :true ,
4776+ fixTypes :[ "suggestion" ]
4777+ } ) ;
4778+ const inputPath = getFixturePath ( "fix-types/fix-only-prefer-arrow-callback.js" ) ;
4779+ const outputPath = getFixturePath ( "fix-types/fix-only-prefer-arrow-callback.expected.js" ) ;
4780+ const content = fs . readFileSync ( inputPath , "utf8" ) ;
4781+ const results = await eslint . lintText ( content , { filePath :inputPath } ) ;
4782+ const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
4783+
4784+ assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
4785+ } ) ;
47354786
4787+ it ( "should fix both style and problem rules when fixTypes has 'suggestion' and 'layout'" , async ( ) => {
4788+ eslint = new FlatESLint ( {
4789+ cwd :path . join ( fixtureDir , ".." ) ,
4790+ overrideConfigFile :true ,
4791+ fix :true ,
4792+ fixTypes :[ "suggestion" , "layout" ]
4793+ } ) ;
4794+ const inputPath = getFixturePath ( "fix-types/fix-both-semi-and-prefer-arrow-callback.js" ) ;
4795+ const outputPath = getFixturePath ( "fix-types/fix-both-semi-and-prefer-arrow-callback.expected.js" ) ;
4796+ const content = fs . readFileSync ( inputPath , "utf8" ) ;
4797+ const results = await eslint . lintText ( content , { filePath :inputPath } ) ;
4798+ const expectedOutput = fs . readFileSync ( outputPath , "utf8" ) ;
4799+
4800+ assert . strictEqual ( results [ 0 ] . output , expectedOutput ) ;
4801+ } ) ;
4802+ } ) ;
47364803} ) ;
47374804
47384805describe ( "isPathIgnored" , ( ) => {