File tree 8 files changed +68
-40
lines changed
8 files changed +68
-40
lines changed Original file line number Diff line number Diff line change 31
31
with :
32
32
fail_ci_if_error : true
33
33
token : ${{ secrets.CODECOV_TOKEN }}
34
- e2e-legacy-config :
35
- name : E2E Legacy Config
36
- runs-on : ubuntu-latest
37
- steps :
38
- - uses : tatethurston/github-actions/build@main
39
- - name : pnpm eslint
40
- run : |
41
- cd packages/legacy-config
42
- output=$(pnpm eslint index.jsx || true)
43
- echo "$output"
44
-
45
- expected="Class component should be written as a function react-prefer-function-component/react-prefer-function-component"
46
- if [[ "$output" != *"$expected"* ]]; then
47
- echo "❌ Fail"
48
- exit 1
49
- else
50
- echo "✅ Pass"
51
- fi
52
- e2e-flat-config :
53
- name : E2E Flat Config
54
- runs-on : ubuntu-latest
55
- steps :
56
- - uses : tatethurston/github-actions/build@main
57
- - name : pnpm eslint
58
- run : |
59
- cd packages/flat-config
60
- output=$(pnpm eslint index.jsx || true)
61
- echo "$output"
62
-
63
- expected="Class component should be written as a function react-prefer-function-component/react-prefer-function-component"
64
- if [[ "$output" != *"$expected"* ]]; then
65
- echo "❌ Fail"
66
- exit 1
67
- else
68
- echo "✅ Pass"
69
- fi
Original file line number Diff line number Diff line change @@ -79,10 +79,17 @@ export default [
79
79
80
80
### ESLint Legacy Configuration
81
81
82
- ` .eslintrc ` configuration:
82
+ ` .eslintrc.js ` configuration:
83
83
84
84
``` js
85
85
module .exports = {
86
+ parserOptions: {
87
+ ecmaVersion: " latest" ,
88
+ sourceType: " module" ,
89
+ ecmaFeatures: {
90
+ jsx: true ,
91
+ },
92
+ },
86
93
extends: [" plugin:react-prefer-function-component/recommended" ],
87
94
};
88
95
```
Original file line number Diff line number Diff line change 1
1
{
2
+ "name" : " example-custom-config" ,
2
3
"version" : " 1.0.0" ,
3
4
"description" : " " ,
4
- "name" : " test" ,
5
5
"scripts" : {
6
6
"lint" : " eslint *.jsx"
7
7
},
Original file line number Diff line number Diff line change 2
2
"version" : " 1.0.0" ,
3
3
"type" : " module" ,
4
4
"description" : " " ,
5
- "name" : " flat-config" ,
5
+ "name" : " examples- flat-config" ,
6
6
"scripts" : {
7
7
"lint" : " eslint ."
8
8
},
Original file line number Diff line number Diff line change 1
1
{
2
+ "name" : " recommended-config" ,
2
3
"version" : " 1.0.0" ,
3
4
"description" : " " ,
4
- "name" : " test" ,
5
5
"scripts" : {
6
6
"lint" : " eslint *.jsx"
7
7
},
Original file line number Diff line number Diff line change 2
2
export default {
3
3
clearMocks : true ,
4
4
coverageDirectory : "coverage" ,
5
+ prettierPath : null ,
5
6
testEnvironment : "node" ,
6
7
// TS ESM imports are referenced with .js extensions, but jest will fail to find
7
8
// the uncompiled file because it ends with .ts and is looking for .js.
Original file line number Diff line number Diff line change
1
+ import { spawnSync } from "child_process" ;
2
+
3
+ function run ( cmd : string ) {
4
+ return spawnSync ( cmd , { shell : true , encoding : "utf8" } ) ;
5
+ }
6
+
7
+ function removeAbsolutePathToEslintFile ( str : string ) : string {
8
+ return str . replace ( __dirname , "" ) ;
9
+ }
10
+
11
+ describe ( "flat config" , ( ) => {
12
+ beforeAll ( ( ) => process . chdir ( __dirname ) ) ;
13
+
14
+ it ( "flags errors" , ( ) => {
15
+ const result = run ( "pnpm eslint index.jsx" ) ;
16
+ expect ( removeAbsolutePathToEslintFile ( result . stdout ) )
17
+ . toMatchInlineSnapshot ( `
18
+ "
19
+ /index.jsx
20
+ 3:14 error Class component should be written as a function react-prefer-function-component/react-prefer-function-component
21
+
22
+ ✖ 1 problem (1 error, 0 warnings)
23
+
24
+ "
25
+ ` ) ;
26
+ expect ( result . status ) . toEqual ( 1 ) ;
27
+ } ) ;
28
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { spawnSync } from "child_process" ;
2
+
3
+ function run ( cmd : string ) {
4
+ return spawnSync ( cmd , { shell : true , encoding : "utf8" } ) ;
5
+ }
6
+
7
+ function removeAbsolutePathToEslintFile ( str : string ) : string {
8
+ return str . replace ( __dirname , "" ) ;
9
+ }
10
+
11
+ describe ( "flat config" , ( ) => {
12
+ beforeAll ( ( ) => process . chdir ( __dirname ) ) ;
13
+
14
+ it ( "flags errors" , ( ) => {
15
+ const result = run ( "pnpm eslint index.jsx" ) ;
16
+ expect ( removeAbsolutePathToEslintFile ( result . stdout ) )
17
+ . toMatchInlineSnapshot ( `
18
+ "
19
+ /index.jsx
20
+ 3:14 error Class component should be written as a function react-prefer-function-component/react-prefer-function-component
21
+
22
+ ✖ 1 problem (1 error, 0 warnings)
23
+
24
+ "
25
+ ` ) ;
26
+ expect ( result . status ) . toEqual ( 1 ) ;
27
+ } ) ;
28
+ } ) ;
You can’t perform that action at this time.
0 commit comments