mirror of
https://github.com/Microsoft/vscode
synced 2024-06-30 23:04:56 +00:00
add lint rule to prevent type discrimination properties in API types (#180829)
re https://github.com/microsoft/vscode/issues/63943 and other
This commit is contained in:
parent
6fc61894a1
commit
89b615d105
34
.eslintplugin/vscode-dts-string-type-literals.ts
Normal file
34
.eslintplugin/vscode-dts-string-type-literals.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 ApiTypeDiscrimination implements eslint.Rule.RuleModule {
|
||||
|
||||
readonly meta: eslint.Rule.RuleMetaData = {
|
||||
docs: { url: 'https://github.com/microsoft/vscode/wiki/Extension-API-guidelines' },
|
||||
messages: {
|
||||
noTypeDiscrimination: 'Do not use type descrimination properties'
|
||||
}
|
||||
};
|
||||
|
||||
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
|
||||
return {
|
||||
['TSPropertySignature[optional=undefined] TSTypeAnnotation TSLiteralType Literal']: (node: any) => {
|
||||
|
||||
const raw = String((<TSESTree.Literal>node).raw)
|
||||
|
||||
if (/^('|").*\1$/.test(raw)) {
|
||||
|
||||
context.report({
|
||||
node: node,
|
||||
messageId: 'noTypeDiscrimination'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
|
@ -130,6 +130,7 @@
|
|||
"rules": {
|
||||
"local/vscode-dts-create-func": "warn",
|
||||
"local/vscode-dts-literal-or-types": "warn",
|
||||
"local/vscode-dts-string-type-literals": "warn",
|
||||
"local/vscode-dts-interface-naming": "warn",
|
||||
"local/vscode-dts-cancellation": "warn",
|
||||
"local/vscode-dts-use-thenable": "warn",
|
||||
|
|
|
@ -8,6 +8,7 @@ declare module 'vscode' {
|
|||
// See https://github.com/microsoft/vscode/issues/63943
|
||||
|
||||
export interface ThreadFocus {
|
||||
// eslint-disable-next-line local/vscode-dts-string-type-literals
|
||||
kind: 'thread';
|
||||
|
||||
/**
|
||||
|
@ -22,6 +23,7 @@ declare module 'vscode' {
|
|||
}
|
||||
|
||||
export interface StackFrameFocus {
|
||||
// eslint-disable-next-line local/vscode-dts-string-type-literals
|
||||
kind: 'stackFrame';
|
||||
|
||||
/**
|
||||
|
|
|
@ -159,6 +159,7 @@ declare module 'vscode' {
|
|||
}
|
||||
|
||||
export interface InteractiveSessionVoteAction {
|
||||
// eslint-disable-next-line local/vscode-dts-string-type-literals
|
||||
kind: 'vote';
|
||||
responseId: string;
|
||||
direction: InteractiveSessionVoteDirection;
|
||||
|
@ -171,6 +172,7 @@ declare module 'vscode' {
|
|||
}
|
||||
|
||||
export interface InteractiveSessionCopyAction {
|
||||
// eslint-disable-next-line local/vscode-dts-string-type-literals
|
||||
kind: 'copy';
|
||||
responseId: string;
|
||||
codeBlockIndex: number;
|
||||
|
@ -181,6 +183,7 @@ declare module 'vscode' {
|
|||
}
|
||||
|
||||
export interface InteractiveSessionInsertAction {
|
||||
// eslint-disable-next-line local/vscode-dts-string-type-literals
|
||||
kind: 'insert';
|
||||
responseId: string;
|
||||
codeBlockIndex: number;
|
||||
|
@ -189,6 +192,7 @@ declare module 'vscode' {
|
|||
}
|
||||
|
||||
export interface InteractiveSessionTerminalAction {
|
||||
// eslint-disable-next-line local/vscode-dts-string-type-literals
|
||||
kind: 'runInTerminal';
|
||||
responseId: string;
|
||||
codeBlockIndex: number;
|
||||
|
@ -196,6 +200,7 @@ declare module 'vscode' {
|
|||
}
|
||||
|
||||
export interface InteractiveSessionCommandAction {
|
||||
// eslint-disable-next-line local/vscode-dts-string-type-literals
|
||||
kind: 'command';
|
||||
command: InteractiveResponseCommand;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ declare module 'vscode' {
|
|||
export interface ResourceLabelFormatting {
|
||||
label: string; // myLabel:/${path}
|
||||
// For historic reasons we use an or string here. Once we finalize this API we should start using enums instead and adopt it in extensions.
|
||||
// eslint-disable-next-line local/vscode-dts-literal-or-types
|
||||
// eslint-disable-next-line local/vscode-dts-literal-or-types, local/vscode-dts-string-type-literals
|
||||
separator: '/' | '\\' | '';
|
||||
tildify?: boolean;
|
||||
normalizeDriveLetter?: boolean;
|
||||
|
|
Loading…
Reference in New Issue
Block a user