forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-no-test-async-suite.ts
33 lines (27 loc) · 1.23 KB
/
code-no-test-async-suite.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TSESTree } from '@typescript-eslint/experimental-utils';
import * as eslint from 'eslint';
function isCallExpression(node: TSESTree.Node): node is TSESTree.CallExpression {
return node.type === 'CallExpression';
}
function isFunctionExpression(node: TSESTree.Node): node is TSESTree.FunctionExpression {
return node.type.includes('FunctionExpression');
}
export = new class NoAsyncSuite implements eslint.Rule.RuleModule {
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
function hasAsyncSuite(node: any) {
if (isCallExpression(node) && node.arguments.length >= 2 && isFunctionExpression(node.arguments[1]) && node.arguments[1].async) {
return context.report({
node: node as any,
message: 'suite factory function should never be async'
});
}
}
return {
['CallExpression[callee.name=/suite$/][arguments]']: hasAsyncSuite,
};
}
};