diff --git a/.eslintplugin/code-no-test-async-suite.ts b/.eslintplugin/code-no-test-async-suite.ts new file mode 100644 index 0000000000000..41d15d286365e --- /dev/null +++ b/.eslintplugin/code-no-test-async-suite.ts @@ -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, + }; + } +}; diff --git a/.eslintrc.json b/.eslintrc.json index 2f52208fa18cb..9e8e0cffe6265 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -120,6 +120,7 @@ ], "rules": { "local/code-no-test-only": "error", + "local/code-no-test-async-suite": "warn", "local/code-no-unexternalized-strings": "off" } },