add provider naming rule
This commit is contained in:
parent
4649e1205f
commit
fee7cdacf7
|
@ -976,6 +976,18 @@
|
|||
"vscode-dts-create-func": "warn",
|
||||
"vscode-dts-literal-or-types": "warn",
|
||||
"vscode-dts-interface-naming": "warn",
|
||||
"vscode-dts-provider-naming": [
|
||||
"warn",
|
||||
{
|
||||
"allowed": [
|
||||
"FileSystemProvider",
|
||||
"TreeDataProvider",
|
||||
"CustomEditorProvider",
|
||||
"CustomReadonlyEditorProvider",
|
||||
"TerminalLinkProvider"
|
||||
]
|
||||
}
|
||||
],
|
||||
"vscode-dts-event-naming": [
|
||||
"warn",
|
||||
{
|
||||
|
|
38
build/lib/eslint/vscode-dts-provider-naming.js
Normal file
38
build/lib/eslint/vscode-dts-provider-naming.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
let _a;
|
||||
module.exports = new (_a = class ApiProviderNaming {
|
||||
constructor() {
|
||||
this.meta = {
|
||||
messages: {
|
||||
naming: 'A provider should only have functions like provideXYZ or resolveXYZ',
|
||||
}
|
||||
};
|
||||
}
|
||||
create(context) {
|
||||
const config = context.options[0];
|
||||
const allowed = new Set(config.allowed);
|
||||
return {
|
||||
['TSInterfaceDeclaration[id.name=/.+Provider/] TSMethodSignature']: (node) => {
|
||||
let _a;
|
||||
const interfaceName = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent).id.name;
|
||||
if (allowed.has(interfaceName)) {
|
||||
// allowed
|
||||
return;
|
||||
}
|
||||
const methodName = node.key.name;
|
||||
if (!ApiProviderNaming._providerFunctionNames.test(methodName)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'naming'
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
_a._providerFunctionNames = /^(provide|resolve|prepare).+/,
|
||||
_a);
|
45
build/lib/eslint/vscode-dts-provider-naming.ts
Normal file
45
build/lib/eslint/vscode-dts-provider-naming.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { TSESTree } from '@typescript-eslint/experimental-utils';
|
||||
|
||||
export = new class ApiProviderNaming implements eslint.Rule.RuleModule {
|
||||
|
||||
readonly meta: eslint.Rule.RuleMetaData = {
|
||||
messages: {
|
||||
naming: 'A provider should only have functions like provideXYZ or resolveXYZ',
|
||||
}
|
||||
};
|
||||
|
||||
private static _providerFunctionNames = /^(provide|resolve|prepare).+/;
|
||||
|
||||
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
|
||||
|
||||
const config = <{ allowed: string[] }>context.options[0];
|
||||
const allowed = new Set(config.allowed);
|
||||
|
||||
return {
|
||||
['TSInterfaceDeclaration[id.name=/.+Provider/] TSMethodSignature']: (node: any) => {
|
||||
|
||||
|
||||
const interfaceName = (<TSESTree.TSInterfaceDeclaration>(<TSESTree.Identifier>node).parent?.parent).id.name;
|
||||
if (allowed.has(interfaceName)) {
|
||||
// allowed
|
||||
return;
|
||||
}
|
||||
|
||||
const methodName = (<any>(<TSESTree.TSMethodSignatureNonComputedName>node).key).name;
|
||||
|
||||
if (!ApiProviderNaming._providerFunctionNames.test(methodName)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'naming'
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
12
src/vs/vscode.proposed.d.ts
vendored
12
src/vs/vscode.proposed.d.ts
vendored
|
@ -106,17 +106,20 @@ declare module 'vscode' {
|
|||
/**
|
||||
* Returns an array of current sessions.
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
getSessions(): Thenable<ReadonlyArray<AuthenticationSession>>;
|
||||
|
||||
/**
|
||||
* Prompts a user to login.
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
login(scopes: string[]): Thenable<AuthenticationSession>;
|
||||
|
||||
/**
|
||||
* Removes the session corresponding to session id.
|
||||
* @param sessionId The session id to log out of
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
logout(sessionId: string): Thenable<void>;
|
||||
}
|
||||
|
||||
|
@ -1028,6 +1031,7 @@ declare module 'vscode' {
|
|||
*
|
||||
* @return Thenable indicating that the webview editor has been moved.
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
moveCustomTextEditor?(newDocument: TextDocument, existingWebviewPanel: WebviewPanel, token: CancellationToken): Thenable<void>;
|
||||
}
|
||||
|
||||
|
@ -1616,10 +1620,15 @@ declare module 'vscode' {
|
|||
* Content providers should always use [file system providers](#FileSystemProvider) to
|
||||
* resolve the raw content for `uri` as the resouce is not necessarily a file on disk.
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
openNotebook(uri: Uri, openContext: NotebookDocumentOpenContext): NotebookData | Promise<NotebookData>;
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
resolveNotebook(document: NotebookDocument, webview: NotebookCommunication): Promise<void>;
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
saveNotebook(document: NotebookDocument, cancellation: CancellationToken): Promise<void>;
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
saveNotebookAs(targetResource: Uri, document: NotebookDocument, cancellation: CancellationToken): Promise<void>;
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
backupNotebook(document: NotebookDocument, context: NotebookDocumentBackupContext, cancellation: CancellationToken): Promise<NotebookDocumentBackup>;
|
||||
}
|
||||
|
||||
|
@ -2156,6 +2165,7 @@ declare module 'vscode' {
|
|||
* It's guaranteed that this method will not be called again while
|
||||
* there is a previous undisposed watcher for the given workspace folder.
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
createWorkspaceTestHierarchy?(workspace: WorkspaceFolder): TestHierarchy<T>;
|
||||
|
||||
/**
|
||||
|
@ -2163,6 +2173,7 @@ declare module 'vscode' {
|
|||
* be called when tests need to be enumerated for a single open file,
|
||||
* for instance by code lens UI.
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
createDocumentTestHierarchy?(document: TextDocument): TestHierarchy<T>;
|
||||
|
||||
/**
|
||||
|
@ -2170,6 +2181,7 @@ declare module 'vscode' {
|
|||
* fire with update test states during the run.
|
||||
* @todo this will eventually need to be able to return a summary report, coverage for example.
|
||||
*/
|
||||
// eslint-disable-next-line vscode-dts-provider-naming
|
||||
runTests?(options: TestRunOptions<T>, cancellationToken: CancellationToken): ProviderResult<void>;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue