@@ -4,25 +4,25 @@ import eslintrc from '..';
4
4
import reactRules from '../rules/react' ;
5
5
import reactA11yRules from '../rules/react-a11y' ;
6
6
7
+ const rules = {
8
+ // It is okay to import devDependencies in tests.
9
+ 'import/no-extraneous-dependencies' : [ 2 , { devDependencies : true } ] ,
10
+ // this doesn't matter for tests
11
+ 'lines-between-class-members' : 0 ,
12
+ // otherwise we need some junk in our fixture code
13
+ 'react/no-unused-class-component-methods' : 0 ,
14
+ } ;
7
15
const cli = new ( CLIEngine || ESLint ) ( {
8
16
useEslintrc : false ,
9
17
baseConfig : eslintrc ,
10
-
11
- rules : {
12
- // It is okay to import devDependencies in tests.
13
- 'import/no-extraneous-dependencies' : [ 2 , { devDependencies : true } ] ,
14
- // this doesn't matter for tests
15
- 'lines-between-class-members' : 0 ,
16
- // otherwise we need some junk in our fixture code
17
- 'react/no-unused-class-component-methods' : 0 ,
18
- } ,
18
+ ...( CLIEngine ? { rules } : { overrideConfig : { rules } } ) ,
19
19
} ) ;
20
20
21
- function lint ( text ) {
21
+ async function lint ( text ) {
22
22
// @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles
23
23
// @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeontext
24
- const linter = CLIEngine ? cli . executeOnText ( text ) : cli . lintText ( text ) ;
25
- return linter . results [ 0 ] ;
24
+ const linter = CLIEngine ? cli . executeOnText ( text ) : await cli . lintText ( text ) ;
25
+ return ( CLIEngine ? linter . results : linter ) [ 0 ] ;
26
26
}
27
27
28
28
function wrapComponent ( body ) {
@@ -42,9 +42,8 @@ test('validate react methods order', (t) => {
42
42
t . deepEqual ( reactA11yRules . plugins , [ 'jsx-a11y' , 'react' ] ) ;
43
43
} ) ;
44
44
45
- t . test ( 'passes a good component' , ( t ) => {
46
- t . plan ( 3 ) ;
47
- const result = lint ( wrapComponent ( `
45
+ t . test ( 'passes a good component' , async ( t ) => {
46
+ const result = await lint ( wrapComponent ( `
48
47
componentDidMount() {}
49
48
handleSubmit() {}
50
49
onButtonAClick() {}
@@ -61,9 +60,8 @@ test('validate react methods order', (t) => {
61
60
t . notOk ( result . errorCount , 'no errors' ) ;
62
61
} ) ;
63
62
64
- t . test ( 'order: when random method is first' , ( t ) => {
65
- t . plan ( 2 ) ;
66
- const result = lint ( wrapComponent ( `
63
+ t . test ( 'order: when random method is first' , async ( t ) => {
64
+ const result = await lint ( wrapComponent ( `
67
65
someMethod() {}
68
66
componentDidMount() {}
69
67
setFoo() {}
@@ -77,9 +75,8 @@ test('validate react methods order', (t) => {
77
75
t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
78
76
} ) ;
79
77
80
- t . test ( 'order: when random method after lifecycle methods' , ( t ) => {
81
- t . plan ( 2 ) ;
82
- const result = lint ( wrapComponent ( `
78
+ t . test ( 'order: when random method after lifecycle methods' , async ( t ) => {
79
+ const result = await lint ( wrapComponent ( `
83
80
componentDidMount() {}
84
81
someMethod() {}
85
82
setFoo() {}
@@ -93,9 +90,8 @@ test('validate react methods order', (t) => {
93
90
t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
94
91
} ) ;
95
92
96
- t . test ( 'order: when handler method with `handle` prefix after method with `on` prefix' , ( t ) => {
97
- t . plan ( 2 ) ;
98
- const result = lint ( wrapComponent ( `
93
+ t . test ( 'order: when handler method with `handle` prefix after method with `on` prefix' , async ( t ) => {
94
+ const result = await lint ( wrapComponent ( `
99
95
componentDidMount() {}
100
96
onButtonAClick() {}
101
97
handleSubmit() {}
@@ -108,9 +104,8 @@ test('validate react methods order', (t) => {
108
104
t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
109
105
} ) ;
110
106
111
- t . test ( 'order: when lifecycle methods after event handler methods' , ( t ) => {
112
- t . plan ( 2 ) ;
113
- const result = lint ( wrapComponent ( `
107
+ t . test ( 'order: when lifecycle methods after event handler methods' , async ( t ) => {
108
+ const result = await lint ( wrapComponent ( `
114
109
handleSubmit() {}
115
110
componentDidMount() {}
116
111
setFoo() {}
@@ -122,9 +117,8 @@ test('validate react methods order', (t) => {
122
117
t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
123
118
} ) ;
124
119
125
- t . test ( 'order: when event handler methods after getters and setters' , ( t ) => {
126
- t . plan ( 2 ) ;
127
- const result = lint ( wrapComponent ( `
120
+ t . test ( 'order: when event handler methods after getters and setters' , async ( t ) => {
121
+ const result = await lint ( wrapComponent ( `
128
122
componentDidMount() {}
129
123
setFoo() {}
130
124
getFoo() {}
0 commit comments