@@ -4,25 +4,25 @@ import eslintrc from '..';
44import reactRules from '../rules/react' ;
55import reactA11yRules from '../rules/react-a11y' ;
66
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+ } ;
715const cli = new ( CLIEngine || ESLint ) ( {
816 useEslintrc : false ,
917 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 } } ) ,
1919} ) ;
2020
21- function lint ( text ) {
21+ async function lint ( text ) {
2222 // @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles
2323 // @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 ] ;
2626}
2727
2828function wrapComponent ( body ) {
@@ -42,9 +42,8 @@ test('validate react methods order', (t) => {
4242 t . deepEqual ( reactA11yRules . plugins , [ 'jsx-a11y' , 'react' ] ) ;
4343 } ) ;
4444
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 ( `
4847 componentDidMount() {}
4948 handleSubmit() {}
5049 onButtonAClick() {}
@@ -61,9 +60,8 @@ test('validate react methods order', (t) => {
6160 t . notOk ( result . errorCount , 'no errors' ) ;
6261 } ) ;
6362
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 ( `
6765 someMethod() {}
6866 componentDidMount() {}
6967 setFoo() {}
@@ -77,9 +75,8 @@ test('validate react methods order', (t) => {
7775 t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
7876 } ) ;
7977
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 ( `
8380 componentDidMount() {}
8481 someMethod() {}
8582 setFoo() {}
@@ -93,9 +90,8 @@ test('validate react methods order', (t) => {
9390 t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
9491 } ) ;
9592
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 ( `
9995 componentDidMount() {}
10096 onButtonAClick() {}
10197 handleSubmit() {}
@@ -108,9 +104,8 @@ test('validate react methods order', (t) => {
108104 t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
109105 } ) ;
110106
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 ( `
114109 handleSubmit() {}
115110 componentDidMount() {}
116111 setFoo() {}
@@ -122,9 +117,8 @@ test('validate react methods order', (t) => {
122117 t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
123118 } ) ;
124119
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 ( `
128122 componentDidMount() {}
129123 setFoo() {}
130124 getFoo() {}
0 commit comments