add lint rule for missing cancellation token in resolve and provide methods, fyi @alexr00 please remove surpression comment
This commit is contained in:
parent
eed13efcc3
commit
0319fedae1
|
@ -976,6 +976,7 @@
|
|||
"vscode-dts-create-func": "warn",
|
||||
"vscode-dts-literal-or-types": "warn",
|
||||
"vscode-dts-interface-naming": "warn",
|
||||
"vscode-dts-cancellation": "warn",
|
||||
"vscode-dts-provider-naming": [
|
||||
"warn",
|
||||
{
|
||||
|
|
33
build/lib/eslint/vscode-dts-cancellation.js
Normal file
33
build/lib/eslint/vscode-dts-cancellation.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
"use strict";
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
||||
module.exports = new class ApiProviderNaming {
|
||||
constructor() {
|
||||
this.meta = {
|
||||
messages: {
|
||||
noToken: 'Function lacks a cancellation token, preferable as last argument',
|
||||
}
|
||||
};
|
||||
}
|
||||
create(context) {
|
||||
return {
|
||||
['TSInterfaceDeclaration[id.name=/.+Provider/] TSMethodSignature[key.name=/^(provide|resolve).+/]']: (node) => {
|
||||
let found = false;
|
||||
for (let param of node.params) {
|
||||
if (param.type === experimental_utils_1.AST_NODE_TYPES.Identifier) {
|
||||
found = found || param.name === 'token';
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'noToken'
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
38
build/lib/eslint/vscode-dts-cancellation.ts
Normal file
38
build/lib/eslint/vscode-dts-cancellation.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as eslint from 'eslint';
|
||||
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/experimental-utils';
|
||||
|
||||
export = new class ApiProviderNaming implements eslint.Rule.RuleModule {
|
||||
|
||||
readonly meta: eslint.Rule.RuleMetaData = {
|
||||
messages: {
|
||||
noToken: 'Function lacks a cancellation token, preferable as last argument',
|
||||
}
|
||||
};
|
||||
|
||||
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
|
||||
|
||||
return {
|
||||
['TSInterfaceDeclaration[id.name=/.+Provider/] TSMethodSignature[key.name=/^(provide|resolve).+/]']: (node: any) => {
|
||||
|
||||
let found = false;
|
||||
for (let param of (<TSESTree.TSMethodSignature>node).params) {
|
||||
if (param.type === AST_NODE_TYPES.Identifier) {
|
||||
found = found || param.name === 'token';
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'noToken'
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
1
src/vs/vscode.d.ts
vendored
1
src/vs/vscode.d.ts
vendored
|
@ -8886,6 +8886,7 @@ declare module 'vscode' {
|
|||
* @return The resolved tree item or a thenable that resolves to such. It is OK to return the given
|
||||
* `item`. When no result is returned, the given `item` will be used.
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-cancellation
|
||||
resolveTreeItem?(item: TreeItem, element: T): ProviderResult<TreeItem>;
|
||||
}
|
||||
|
||||
|
|
1
src/vs/vscode.proposed.d.ts
vendored
1
src/vs/vscode.proposed.d.ts
vendored
|
@ -1582,6 +1582,7 @@ declare module 'vscode' {
|
|||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
openNotebook(uri: Uri, openContext: NotebookDocumentOpenContext): NotebookData | Promise<NotebookData>;
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
// eslint-disable-next-line vscode-dts-cancellation
|
||||
resolveNotebook(document: NotebookDocument, webview: NotebookCommunication): Promise<void>;
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
saveNotebook(document: NotebookDocument, cancellation: CancellationToken): Promise<void>;
|
||||
|
|
Loading…
Reference in a new issue