|
| 1 | +import { ESLintUtils } from '@typescript-eslint/utils'; |
| 2 | + |
| 3 | +const createRule = ESLintUtils.RuleCreator(name => `https://example.com/rule/${name}`) |
| 4 | + |
| 5 | +export default createRule({ |
| 6 | + name: 'invalid-node-types', |
| 7 | + create(context) { |
| 8 | + return { |
| 9 | + 'ArrowFunctionExpression, FunctionDeclaration, FunctionExpression, TSFunctionType, TSEmptyBodyFunctionExpression, TSDeclareFunction, MethodDefinition'(node) { |
| 10 | + context.report({ node, messageId: 'function' }) |
| 11 | + }, |
| 12 | + 'DoWhileStatement, ForInStatement, ForOfStatement, ForStatement, WhileStatement'(node) { |
| 13 | + context.report({ node, messageId: 'loop' }) |
| 14 | + }, |
| 15 | + 'CatchClause, ThrowStatement, TryStatement'(node) { |
| 16 | + context.report({ node, messageId: 'exception' }) |
| 17 | + }, |
| 18 | + 'TSAsyncKeyword, AwaitExpression'(node) { |
| 19 | + context.report({ node, messageId: 'async' }) |
| 20 | + }, |
| 21 | + 'SwitchStatement, SwitchCase, ConditionalExpression, IfStatement, TSConditionalType'(node) { |
| 22 | + context.report({ node, messageId: 'condition' }) |
| 23 | + }, |
| 24 | + TSUndefinedKeyword(node) { |
| 25 | + context.report({ node, messageId: 'undefined' }) |
| 26 | + }, |
| 27 | + TSNeverKeyword(node) { |
| 28 | + context.report({ node, messageId: 'never' }) |
| 29 | + }, |
| 30 | + } |
| 31 | + }, |
| 32 | + meta: { |
| 33 | + docs: { |
| 34 | + description: 'The Elasticsearch specification only uses a subset of the TypeScript language, primarily classes, interfaces, enums and type aliases.', |
| 35 | + }, |
| 36 | + messages: { |
| 37 | + function: 'Functions are not supported by the Elasticsearch specification', |
| 38 | + loop: 'Loops are not supported by the Elasticsearch specification', |
| 39 | + exception: 'Exception management is not supported by the Elasticsearch specification', |
| 40 | + async: 'Async/await syntax is not supported by the Elasticsearch specification', |
| 41 | + condition: 'Conditional expressions are not supported by the Elasticsearch specification', |
| 42 | + undefined: '`undefined` is not a valid type in the Elasticsearch specification', |
| 43 | + never: '`never` is not a valid type in the Elasticsearch specification', |
| 44 | + }, |
| 45 | + type: 'suggestion', |
| 46 | + }, |
| 47 | + defaultOptions: [] |
| 48 | +}) |
0 commit comments