@@ -4664,75 +4664,142 @@ describe("FlatESLint", () => {
4664
4664
4665
4665
let eslint ;
4666
4666
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 ( ) => {
4669
4695
eslint = new FlatESLint ( {
4670
4696
cwd : path . join ( fixtureDir , ".." ) ,
4671
4697
overrideConfigFile : true ,
4672
4698
fix : true ,
4673
- fixTypes : [ "layou " ]
4699
+ fixTypes : [ "layout " ]
4674
4700
} ) ;
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" ) ;
4677
4705
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 ) ;
4684
4707
} ) ;
4685
- const inputPath = getFixturePath ( "fix-types/fix-only-semi.js" ) ;
4686
- const results = await eslint . lintFiles ( [ inputPath ] ) ;
4687
4708
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" ) ;
4690
4720
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 ) ;
4697
4722
} ) ;
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" ) ;
4702
4723
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
+ } ) ;
4704
4738
} ) ;
4705
4739
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 ) ;
4712
4753
} ) ;
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" ) ;
4717
4754
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" ) ;
4720
4767
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 ) ;
4727
4769
} ) ;
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" ) ;
4732
4770
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
+ } ) ;
4735
4786
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
+ } ) ;
4736
4803
} ) ;
4737
4804
4738
4805
describe ( "isPathIgnored" , ( ) => {
0 commit comments