Skip to content

Commit 34442b8

Browse files
authored
Warn on async suites (microsoft#188378)
Part of microsoft#187718
1 parent 41c7fc3 commit 34442b8

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { TSESTree } from '@typescript-eslint/experimental-utils';
7+
import * as eslint from 'eslint';
8+
9+
function isCallExpression(node: TSESTree.Node): node is TSESTree.CallExpression {
10+
return node.type === 'CallExpression';
11+
}
12+
13+
function isFunctionExpression(node: TSESTree.Node): node is TSESTree.FunctionExpression {
14+
return node.type.includes('FunctionExpression');
15+
}
16+
17+
export = new class NoAsyncSuite implements eslint.Rule.RuleModule {
18+
19+
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
20+
function hasAsyncSuite(node: any) {
21+
if (isCallExpression(node) && node.arguments.length >= 2 && isFunctionExpression(node.arguments[1]) && node.arguments[1].async) {
22+
return context.report({
23+
node: node as any,
24+
message: 'suite factory function should never be async'
25+
});
26+
}
27+
}
28+
29+
return {
30+
['CallExpression[callee.name=/suite$/][arguments]']: hasAsyncSuite,
31+
};
32+
}
33+
};

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
],
121121
"rules": {
122122
"local/code-no-test-only": "error",
123+
"local/code-no-test-async-suite": "warn",
123124
"local/code-no-unexternalized-strings": "off"
124125
}
125126
},

0 commit comments

Comments
 (0)