kylin-code/.eslintplugin/vscode-dts-string-type-lite...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-06-14 14:37:10 +08:00
/*---------------------------------------------------------------------------------------------
* 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';
2024-04-30 20:57:13 +08:00
export = new class ApiTypeDiscrimination implements eslint.Rule.RuleModule {
2022-06-14 14:37:10 +08:00
readonly meta: eslint.Rule.RuleMetaData = {
2024-04-30 20:57:13 +08:00
docs: { url: 'https://github.com/microsoft/vscode/wiki/Extension-API-guidelines' },
messages: {
noTypeDiscrimination: 'Do not use type descrimination properties'
}
2022-06-14 14:37:10 +08:00
};
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
return {
2024-04-30 20:57:13 +08:00
['TSPropertySignature[optional=undefined] TSTypeAnnotation TSLiteralType Literal']: (node: any) => {
const raw = String((<TSESTree.Literal>node).raw)
if (/^('|").*\1$/.test(raw)) {
2022-06-14 14:37:10 +08:00
context.report({
node: node,
2024-04-30 20:57:13 +08:00
messageId: 'noTypeDiscrimination'
2022-06-14 14:37:10 +08:00
});
}
}
2024-04-30 20:57:13 +08:00
}
2022-06-14 14:37:10 +08:00
}
};