vscode
Зеркало из https://github.com/microsoft/vscode
39 строк · 1.2 Кб
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
6import * as eslint from 'eslint';7import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';8
9export = new class ApiProviderNaming implements eslint.Rule.RuleModule {10
11readonly meta: eslint.Rule.RuleMetaData = {12messages: {13noToken: 'Function lacks a cancellation token, preferable as last argument',14},15schema: false,16};17
18create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {19
20return {21['TSInterfaceDeclaration[id.name=/.+Provider/] TSMethodSignature[key.name=/^(provide|resolve).+/]']: (node: any) => {22
23let found = false;24for (const param of (<TSESTree.TSMethodSignature>node).params) {25if (param.type === AST_NODE_TYPES.Identifier) {26found = found || param.name === 'token';27}28}29
30if (!found) {31context.report({32node,33messageId: 'noToken'34});35}36}37};38}39};40