mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
For #269213 This adds a new eslint rule for `as any` and `<any>({... })`. We'd like to remove almost all of these, however right now the first goal is to prevent them in new code. That's why with this first PR I simply add `eslint-disable` comments for all breaks Trying to get this change in soon after branching off for release to hopefully minimize disruption during debt week work
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* 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/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({
|
|
// eslint-disable-next-line local/code-no-any-casts
|
|
node: node as any,
|
|
message: 'suite factory function should never be async'
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
['CallExpression[callee.name=/suite$/][arguments]']: hasAsyncSuite,
|
|
};
|
|
}
|
|
};
|