1- import { ESLintUtils , TSESTree } from '@typescript-eslint/experimental-utils'
2- import { getDocsUrl , hasTestingLibraryImportModule } from '../utils'
3- import { isBlockStatement , findClosestCallNode , isMemberExpression , isCallExpression , isIdentifier } from '../node-utils'
1+ import { ESLintUtils , TSESTree } from '@typescript-eslint/experimental-utils' ;
2+ import { getDocsUrl , hasTestingLibraryImportModule } from '../utils' ;
3+ import {
4+ isBlockStatement ,
5+ findClosestCallNode ,
6+ isMemberExpression ,
7+ isCallExpression ,
8+ isIdentifier ,
9+ } from '../node-utils' ;
410
511export const RULE_NAME = 'no-side-effects-wait-for' ;
612
7- const WAIT_EXPRESSION_QUERY =
8- 'CallExpression[callee.name=/^(waitFor)$/]' ;
13+ const WAIT_EXPRESSION_QUERY = 'CallExpression[callee.name=/^(waitFor)$/]' ;
914
10- const SIDE_EFFECTS : Array < string > = [ 'fireEvent' , 'userEvent' ]
15+ const SIDE_EFFECTS : Array < string > = [ 'fireEvent' , 'userEvent' ] ;
1116
1217export type MessageIds = 'noSideEffectsWaitFor' ;
1318type Options = [ ] ;
@@ -17,13 +22,13 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
1722 meta : {
1823 type : 'suggestion' ,
1924 docs : {
20- description :
21- "It's preferred to avoid side effects in `waitFor`" ,
25+ description : "It's preferred to avoid side effects in `waitFor`" ,
2226 category : 'Best Practices' ,
2327 recommended : false ,
2428 } ,
2529 messages : {
26- noSideEffectsWaitFor : 'Avoid using side effects within `waitFor` callback' ,
30+ noSideEffectsWaitFor :
31+ 'Avoid using side effects within `waitFor` callback' ,
2732 } ,
2833 fixable : null ,
2934 schema : [ ] ,
@@ -32,25 +37,27 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
3237 create : function ( context ) {
3338 let isImportingTestingLibrary = false ;
3439
35- function reportSideEffects (
36- node : TSESTree . BlockStatement
37- ) {
40+ function reportSideEffects ( node : TSESTree . BlockStatement ) {
3841 const hasSideEffects = ( body : Array < TSESTree . Node > ) : boolean =>
3942 body . some ( ( node : TSESTree . ExpressionStatement ) => {
4043 if (
4144 isCallExpression ( node . expression ) &&
4245 isMemberExpression ( node . expression . callee ) &&
4346 isIdentifier ( node . expression . callee . object )
4447 ) {
45- const object : TSESTree . Identifier = node . expression . callee . object
46- const identifierName : string = object . name
47- return SIDE_EFFECTS . includes ( identifierName )
48+ const object : TSESTree . Identifier = node . expression . callee . object ;
49+ const identifierName : string = object . name ;
50+ return SIDE_EFFECTS . includes ( identifierName ) ;
4851 } else {
49- return false
52+ return false ;
5053 }
51- } )
54+ } ) ;
5255
53- if ( isImportingTestingLibrary && isBlockStatement ( node ) && hasSideEffects ( node . body ) ) {
56+ if (
57+ isImportingTestingLibrary &&
58+ isBlockStatement ( node ) &&
59+ hasSideEffects ( node . body )
60+ ) {
5461 context . report ( {
5562 node,
5663 loc : node . loc . start ,
@@ -64,7 +71,7 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
6471 [ `${ WAIT_EXPRESSION_QUERY } > FunctionExpression > BlockStatement` ] : reportSideEffects ,
6572 ImportDeclaration ( node : TSESTree . ImportDeclaration ) {
6673 isImportingTestingLibrary = hasTestingLibraryImportModule ( node ) ;
67- }
74+ } ,
6875 } ;
69- }
70- } )
76+ } ,
77+ } ) ;
0 commit comments