Skip to content

Commit

Permalink
Warn on async suites (microsoft#188378)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 authored Jul 28, 2023
1 parent 41c7fc3 commit 34442b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .eslintplugin/code-no-test-async-suite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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,
};
}
};
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
],
"rules": {
"local/code-no-test-only": "error",
"local/code-no-test-async-suite": "warn",
"local/code-no-unexternalized-strings": "off"
}
},
Expand Down

0 comments on commit 34442b8

Please sign in to comment.