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+ isMemberExpression ,
6+ isCallExpression ,
7+ isIdentifier ,
8+ } from '../node-utils' ;
49
510export const RULE_NAME = 'no-side-effects-wait-for' ;
611
7- const WAIT_EXPRESSION_QUERY =
8- 'CallExpression[callee.name=/^(waitFor)$/]' ;
12+ const WAIT_EXPRESSION_QUERY = 'CallExpression[callee.name=/^(waitFor)$/]' ;
913
10- const SIDE_EFFECTS : Array < string > = [ 'fireEvent' , 'userEvent' ]
14+ const SIDE_EFFECTS : Array < string > = [ 'fireEvent' , 'userEvent' ] ;
1115
1216export type MessageIds = 'noSideEffectsWaitFor' ;
1317type Options = [ ] ;
@@ -17,13 +21,13 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
1721 meta : {
1822 type : 'suggestion' ,
1923 docs : {
20- description :
21- "It's preferred to avoid side effects in `waitFor`" ,
24+ description : "It's preferred to avoid side effects in `waitFor`" ,
2225 category : 'Best Practices' ,
2326 recommended : false ,
2427 } ,
2528 messages : {
26- noSideEffectsWaitFor : 'Avoid using side effects within `waitFor` callback' ,
29+ noSideEffectsWaitFor :
30+ 'Avoid using side effects within `waitFor` callback' ,
2731 } ,
2832 fixable : null ,
2933 schema : [ ] ,
@@ -32,25 +36,27 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
3236 create : function ( context ) {
3337 let isImportingTestingLibrary = false ;
3438
35- function reportSideEffects (
36- node : TSESTree . BlockStatement
37- ) {
39+ function reportSideEffects ( node : TSESTree . BlockStatement ) {
3840 const hasSideEffects = ( body : Array < TSESTree . Node > ) : boolean =>
3941 body . some ( ( node : TSESTree . ExpressionStatement ) => {
4042 if (
4143 isCallExpression ( node . expression ) &&
4244 isMemberExpression ( node . expression . callee ) &&
4345 isIdentifier ( node . expression . callee . object )
4446 ) {
45- const object : TSESTree . Identifier = node . expression . callee . object
46- const identifierName : string = object . name
47- return SIDE_EFFECTS . includes ( identifierName )
47+ const object : TSESTree . Identifier = node . expression . callee . object ;
48+ const identifierName : string = object . name ;
49+ return SIDE_EFFECTS . includes ( identifierName ) ;
4850 } else {
49- return false
51+ return false ;
5052 }
51- } )
53+ } ) ;
5254
53- if ( isImportingTestingLibrary && isBlockStatement ( node ) && hasSideEffects ( node . body ) ) {
55+ if (
56+ isImportingTestingLibrary &&
57+ isBlockStatement ( node ) &&
58+ hasSideEffects ( node . body )
59+ ) {
5460 context . report ( {
5561 node,
5662 loc : node . loc . start ,
@@ -64,7 +70,7 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
6470 [ `${ WAIT_EXPRESSION_QUERY } > FunctionExpression > BlockStatement` ] : reportSideEffects ,
6571 ImportDeclaration ( node : TSESTree . ImportDeclaration ) {
6672 isImportingTestingLibrary = hasTestingLibraryImportModule ( node ) ;
67- }
73+ } ,
6874 } ;
69- }
70- } )
75+ } ,
76+ } ) ;
0 commit comments