From d80eba6ea9968a4c974020755fd23c2e7dd3c4d9 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Wed, 13 Feb 2019 11:10:18 -0800 Subject: [PATCH 1/2] feat(eslint-plugin): update types to allow parameter type inferrence By adding a all of the possible members with specific RuleFunction type this is allowing rule authors to write rules without specifying parameter types in their token methods Also updates all of the existing rules to not specify type of node when it is inferred --- .../eslint-plugin/src/rules/array-type.ts | 2 +- packages/eslint-plugin/src/rules/camelcase.ts | 2 +- .../src/rules/generic-type-naming.ts | 3 +- .../src/rules/interface-name-prefix.ts | 3 +- .../src/rules/member-ordering.ts | 8 +- .../rules/no-angle-bracket-type-assertion.ts | 3 +- .../src/rules/no-empty-interface.ts | 3 +- .../src/rules/no-extraneous-class.ts | 2 +- .../src/rules/no-for-in-array.ts | 3 +- .../src/rules/no-non-null-assertion.ts | 3 +- .../src/rules/no-parameter-properties.ts | 2 +- .../src/rules/no-require-imports.ts | 2 +- .../src/rules/no-triple-slash-reference.ts | 3 +- .../eslint-plugin/src/rules/no-type-alias.ts | 2 +- .../rules/no-unnecessary-type-assertion.ts | 6 +- .../src/rules/no-useless-constructor.ts | 2 +- .../src/rules/no-var-requires.ts | 4 +- .../src/rules/prefer-function-type.ts | 2 +- .../src/rules/prefer-namespace-keyword.ts | 5 +- .../src/rules/type-annotation-spacing.ts | 4 +- packages/eslint-plugin/typings/ts-eslint.d.ts | 216 +++++++++++++++++- 21 files changed, 241 insertions(+), 39 deletions(-) diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index 39b3715c47c1..f6d9a5bf126e 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -147,7 +147,7 @@ export default util.createRule({ } return { - TSArrayType(node: TSESTree.TSArrayType) { + TSArrayType(node) { if ( option === 'array' || (option === 'array-simple' && isSimpleType(node.elementType)) diff --git a/packages/eslint-plugin/src/rules/camelcase.ts b/packages/eslint-plugin/src/rules/camelcase.ts index c155052ba11f..130181f7b5bf 100644 --- a/packages/eslint-plugin/src/rules/camelcase.ts +++ b/packages/eslint-plugin/src/rules/camelcase.ts @@ -89,7 +89,7 @@ export default util.createRule({ } return { - Identifier(node: TSESTree.Identifier) { + Identifier(node) { /* * Leading and trailing underscores are commonly used to flag * private/protected identifiers, strip them diff --git a/packages/eslint-plugin/src/rules/generic-type-naming.ts b/packages/eslint-plugin/src/rules/generic-type-naming.ts index 473fa6bc812f..5789b290b2f0 100644 --- a/packages/eslint-plugin/src/rules/generic-type-naming.ts +++ b/packages/eslint-plugin/src/rules/generic-type-naming.ts @@ -2,7 +2,6 @@ * @fileoverview Enforces naming of generic type variables. */ -import { TSESTree } from '@typescript-eslint/typescript-estree'; import * as util from '../util'; type Options = [string?]; @@ -34,7 +33,7 @@ export default util.createRule({ const regex = new RegExp(rule!); return { - TSTypeParameter(node: TSESTree.TSTypeParameter) { + TSTypeParameter(node) { const name = node.name.name; if (name && !regex.test(name)) { diff --git a/packages/eslint-plugin/src/rules/interface-name-prefix.ts b/packages/eslint-plugin/src/rules/interface-name-prefix.ts index 0f895774ffbf..69f428c34e66 100644 --- a/packages/eslint-plugin/src/rules/interface-name-prefix.ts +++ b/packages/eslint-plugin/src/rules/interface-name-prefix.ts @@ -3,7 +3,6 @@ * @author Danny Fritz */ -import { TSESTree } from '@typescript-eslint/typescript-estree'; import * as util from '../util'; type Options = ['never' | 'always']; @@ -45,7 +44,7 @@ export default util.createRule({ } return { - TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration): void { + TSInterfaceDeclaration(node): void { if (never) { if (isPrefixedWithI(node.id.name)) { context.report({ diff --git a/packages/eslint-plugin/src/rules/member-ordering.ts b/packages/eslint-plugin/src/rules/member-ordering.ts index b16c878bc718..2057c10e3618 100644 --- a/packages/eslint-plugin/src/rules/member-ordering.ts +++ b/packages/eslint-plugin/src/rules/member-ordering.ts @@ -353,28 +353,28 @@ export default util.createRule({ } return { - ClassDeclaration(node: TSESTree.ClassDeclaration) { + ClassDeclaration(node) { validateMembers( node.body.body, options.classes || options.default!, true ); }, - ClassExpression(node: TSESTree.ClassExpression) { + ClassExpression(node) { validateMembers( node.body.body, options.classExpressions || options.default!, true ); }, - TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration) { + TSInterfaceDeclaration(node) { validateMembers( node.body.body, options.interfaces || options.default!, false ); }, - TSTypeLiteral(node: TSESTree.TSTypeLiteral) { + TSTypeLiteral(node) { validateMembers( node.members, options.typeLiterals || options.default!, diff --git a/packages/eslint-plugin/src/rules/no-angle-bracket-type-assertion.ts b/packages/eslint-plugin/src/rules/no-angle-bracket-type-assertion.ts index 65ae3cd0d837..7bdf2d8ad5a2 100644 --- a/packages/eslint-plugin/src/rules/no-angle-bracket-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-angle-bracket-type-assertion.ts @@ -3,7 +3,6 @@ * @author Patricio Trevino */ -import { TSESTree } from '@typescript-eslint/typescript-estree'; import * as util from '../util'; export default util.createRule({ @@ -27,7 +26,7 @@ export default util.createRule({ create(context) { const sourceCode = context.getSourceCode(); return { - TSTypeAssertion(node: TSESTree.TSTypeAssertion) { + TSTypeAssertion(node) { context.report({ node, messageId: 'preferAs', diff --git a/packages/eslint-plugin/src/rules/no-empty-interface.ts b/packages/eslint-plugin/src/rules/no-empty-interface.ts index 52e1d0ddf9ab..919647aa45f9 100644 --- a/packages/eslint-plugin/src/rules/no-empty-interface.ts +++ b/packages/eslint-plugin/src/rules/no-empty-interface.ts @@ -3,7 +3,6 @@ * @author Patricio Trevino */ -import { TSESTree } from '@typescript-eslint/typescript-estree'; import * as util from '../util'; export default util.createRule({ @@ -26,7 +25,7 @@ export default util.createRule({ defaultOptions: [], create(context) { return { - TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration) { + TSInterfaceDeclaration(node) { if (node.body.body.length !== 0) { return; } diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index cb6c58de86c4..9dfc4fc290ae 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -57,7 +57,7 @@ export default util.createRule({ ], create(context, [{ allowConstructorOnly, allowEmpty, allowStaticOnly }]) { return { - ClassBody(node: TSESTree.ClassBody) { + ClassBody(node) { const parent = node.parent as | TSESTree.ClassDeclaration | TSESTree.ClassExpression diff --git a/packages/eslint-plugin/src/rules/no-for-in-array.ts b/packages/eslint-plugin/src/rules/no-for-in-array.ts index c958d39670f9..620b05b6624b 100644 --- a/packages/eslint-plugin/src/rules/no-for-in-array.ts +++ b/packages/eslint-plugin/src/rules/no-for-in-array.ts @@ -3,7 +3,6 @@ * @author Benjamin Lichtman */ -import { TSESTree } from '@typescript-eslint/typescript-estree'; import ts from 'typescript'; import * as util from '../util'; @@ -26,7 +25,7 @@ export default util.createRule({ defaultOptions: [], create(context) { return { - ForInStatement(node: TSESTree.ForInStatement) { + ForInStatement(node) { const parserServices = util.getParserServices(context); const checker = parserServices.program.getTypeChecker(); const originalNode = parserServices.esTreeNodeToTSNodeMap.get< diff --git a/packages/eslint-plugin/src/rules/no-non-null-assertion.ts b/packages/eslint-plugin/src/rules/no-non-null-assertion.ts index 3abe06f71a25..b7a26ad0d6f5 100644 --- a/packages/eslint-plugin/src/rules/no-non-null-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-non-null-assertion.ts @@ -3,7 +3,6 @@ * @author Macklin Underdown */ -import { TSESTree } from '@typescript-eslint/typescript-estree'; import * as util from '../util'; export default util.createRule({ @@ -25,7 +24,7 @@ export default util.createRule({ defaultOptions: [], create(context) { return { - TSNonNullExpression(node: TSESTree.TSNonNullExpression) { + TSNonNullExpression(node) { context.report({ node, messageId: 'noNonNull' diff --git a/packages/eslint-plugin/src/rules/no-parameter-properties.ts b/packages/eslint-plugin/src/rules/no-parameter-properties.ts index cce3af7b3620..d8e4fd128ea6 100644 --- a/packages/eslint-plugin/src/rules/no-parameter-properties.ts +++ b/packages/eslint-plugin/src/rules/no-parameter-properties.ts @@ -84,7 +84,7 @@ export default util.createRule({ } return { - TSParameterProperty(node: TSESTree.TSParameterProperty) { + TSParameterProperty(node) { const modifiers = getModifiers(node); if (allows.indexOf(modifiers) === -1) { diff --git a/packages/eslint-plugin/src/rules/no-require-imports.ts b/packages/eslint-plugin/src/rules/no-require-imports.ts index 0985c6a91f45..2fae56737cbe 100644 --- a/packages/eslint-plugin/src/rules/no-require-imports.ts +++ b/packages/eslint-plugin/src/rules/no-require-imports.ts @@ -30,7 +30,7 @@ export default util.createRule({ messageId: 'noRequireImports' }); }, - TSExternalModuleReference(node: TSESTree.TSExternalModuleReference) { + TSExternalModuleReference(node) { context.report({ node, messageId: 'noRequireImports' diff --git a/packages/eslint-plugin/src/rules/no-triple-slash-reference.ts b/packages/eslint-plugin/src/rules/no-triple-slash-reference.ts index 9691edb201ed..9a16b8852e32 100644 --- a/packages/eslint-plugin/src/rules/no-triple-slash-reference.ts +++ b/packages/eslint-plugin/src/rules/no-triple-slash-reference.ts @@ -3,7 +3,6 @@ * @author Danny Fritz */ -import { TSESTree } from '@typescript-eslint/typescript-estree'; import * as util from '../util'; export default util.createRule({ @@ -27,7 +26,7 @@ export default util.createRule({ const sourceCode = context.getSourceCode(); return { - Program(program: TSESTree.Program): void { + Program(program): void { const commentsBefore = sourceCode.getCommentsBefore(program); commentsBefore.forEach(comment => { diff --git a/packages/eslint-plugin/src/rules/no-type-alias.ts b/packages/eslint-plugin/src/rules/no-type-alias.ts index d73d436a0022..904e9f7c68f3 100644 --- a/packages/eslint-plugin/src/rules/no-type-alias.ts +++ b/packages/eslint-plugin/src/rules/no-type-alias.ts @@ -290,7 +290,7 @@ export default util.createRule({ } return { - TSTypeAliasDeclaration(node: TSESTree.TSTypeAliasDeclaration) { + TSTypeAliasDeclaration(node) { if (isComposition(node.typeAnnotation)) { validateCompositions(node.typeAnnotation); } else { diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts index 98dcf3f05979..39095113f0e7 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts @@ -158,13 +158,13 @@ export default util.createRule({ const checker = parserServices.program.getTypeChecker(); return { - TSNonNullExpression(node: TSESTree.TSNonNullExpression) { + TSNonNullExpression(node) { checkNonNullAssertion(node, checker); }, - TSTypeAssertion(node: TSESTree.TSTypeAssertion) { + TSTypeAssertion(node) { verifyCast(node, checker); }, - TSAsExpression(node: TSESTree.TSAsExpression) { + TSAsExpression(node) { verifyCast(node, checker); } }; diff --git a/packages/eslint-plugin/src/rules/no-useless-constructor.ts b/packages/eslint-plugin/src/rules/no-useless-constructor.ts index 944ad6ff0c68..f8398c69df43 100644 --- a/packages/eslint-plugin/src/rules/no-useless-constructor.ts +++ b/packages/eslint-plugin/src/rules/no-useless-constructor.ts @@ -61,7 +61,7 @@ export default util.createRule({ create(context) { const rules = baseRule.create(context); return { - MethodDefinition(node: TSESTree.MethodDefinition) { + MethodDefinition(node) { if ( node.value && node.value.type === AST_NODE_TYPES.FunctionExpression && diff --git a/packages/eslint-plugin/src/rules/no-var-requires.ts b/packages/eslint-plugin/src/rules/no-var-requires.ts index 243bfcd4640d..2d28bc12af64 100644 --- a/packages/eslint-plugin/src/rules/no-var-requires.ts +++ b/packages/eslint-plugin/src/rules/no-var-requires.ts @@ -3,7 +3,7 @@ * @author Macklin Underdown */ -import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree'; +import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree'; import * as util from '../util'; type Options = []; @@ -28,7 +28,7 @@ export default util.createRule({ defaultOptions: [], create(context) { return { - CallExpression(node: TSESTree.CallExpression) { + CallExpression(node) { if ( node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === 'require' && diff --git a/packages/eslint-plugin/src/rules/prefer-function-type.ts b/packages/eslint-plugin/src/rules/prefer-function-type.ts index 71bd2a880977..61519e47cd85 100644 --- a/packages/eslint-plugin/src/rules/prefer-function-type.ts +++ b/packages/eslint-plugin/src/rules/prefer-function-type.ts @@ -147,7 +147,7 @@ export default util.createRule({ } return { - TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration) { + TSInterfaceDeclaration(node) { if (!hasOneSupertype(node) && node.body.body.length === 1) { checkMember(node.body.body[0], node); } diff --git a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts index 83b668a1b8da..3170b4840ebe 100644 --- a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts +++ b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts @@ -6,8 +6,7 @@ import { AST_NODE_TYPES, - AST_TOKEN_TYPES, - TSESTree + AST_TOKEN_TYPES } from '@typescript-eslint/typescript-estree'; import * as util from '../util'; @@ -34,7 +33,7 @@ export default util.createRule({ const sourceCode = context.getSourceCode(); return { - TSModuleDeclaration(node: TSESTree.TSModuleDeclaration) { + TSModuleDeclaration(node) { // Do nothing if the name is a string. if (!node.id || node.id.type === AST_NODE_TYPES.Literal) { return; diff --git a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts index 391f6523095f..2e237a6db625 100644 --- a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts +++ b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts @@ -192,12 +192,12 @@ export default util.createRule({ } return { - TSMappedType(node: TSESTree.TSMappedType) { + TSMappedType(node) { if (node.typeAnnotation) { checkTypeAnnotationSpacing(node.typeAnnotation); } }, - TSTypeAnnotation(node: TSESTree.TSTypeAnnotation) { + TSTypeAnnotation(node) { checkTypeAnnotationSpacing(node.typeAnnotation); } }; diff --git a/packages/eslint-plugin/typings/ts-eslint.d.ts b/packages/eslint-plugin/typings/ts-eslint.d.ts index 9ab6ff35e213..7497159d3106 100644 --- a/packages/eslint-plugin/typings/ts-eslint.d.ts +++ b/packages/eslint-plugin/typings/ts-eslint.d.ts @@ -10,7 +10,7 @@ The def is wrapped up in a fake module so that it can be used in eslint-rules.d. declare module 'ts-eslint' { import { TSESTree } from '@typescript-eslint/typescript-estree'; import { ParserServices } from '@typescript-eslint/parser'; - import { AST, Linter } from 'eslint'; + import { AST, Linter, Rule } from 'eslint'; import { JSONSchema4 } from 'json-schema'; //#region SourceCode @@ -397,8 +397,218 @@ declare module 'ts-eslint' { // This isn't the correct signature, but it makes it easier to do custom unions within reusable listneers // never will break someone's code unless they specifically type the function argument - type RuleFunction = (node: never) => void; - type RuleListener = Record; + type RuleFunction = (node: T) => void; + + type CodePathFunction = ( + codePath: Rule.CodePath, + node: TSESTree.BaseNode + ) => void; + + type CodePathSegmentFunction = ( + codePathSegment: Rule.CodePathSegment, + node: TSESTree.BaseNode + ) => void; + + type CodePathSegmentLoopFunction< + T extends TSESTree.BaseNode = TSESTree.Node + > = ( + fromCodePathSegment: Rule.CodePathSegment, + toCodePathSegment: Rule.CodePathSegment, + node: TSESTree.BaseNode + ) => void; + + interface RuleListener { + [nodeSelector: string]: + | RuleFunction + | CodePathFunction + | CodePathSegmentFunction + | CodePathSegmentLoopFunction + | undefined; + ArrayExpression?: RuleFunction; + ArrayPattern?: RuleFunction; + ArrowFunctionExpression?: RuleFunction; + AssignmentPattern?: RuleFunction; + AwaitExpression?: RuleFunction; + BlockStatement?: RuleFunction; + BreakStatement?: RuleFunction; + CallExpression?: RuleFunction; + CatchClause?: RuleFunction; + ClassBody?: RuleFunction; + ClassDeclaration?: RuleFunction; + ClassExpression?: RuleFunction; + Comment?: RuleFunction; + ConditionalExpression?: RuleFunction; + ContinueStatement?: RuleFunction; + DebuggerStatement?: RuleFunction; + Decorator?: RuleFunction; + DoWhileStatement?: RuleFunction; + EmptyStatement?: RuleFunction; + ExportAllDeclaration?: RuleFunction; + ExportDefaultDeclaration?: RuleFunction; + ExportNamedDeclaration?: RuleFunction; + ExportSpecifier?: RuleFunction; + ExpressionStatement?: RuleFunction; + ForInStatement?: RuleFunction; + ForOfStatement?: RuleFunction; + ForStatement?: RuleFunction; + Identifier?: RuleFunction; + IfStatement?: RuleFunction; + Import?: RuleFunction; + ImportDeclaration?: RuleFunction; + ImportDefaultSpecifier?: RuleFunction; + ImportNamespaceSpecifier?: RuleFunction; + ImportSpecifier?: RuleFunction; + JSXAttribute?: RuleFunction; + JSXClosingElement?: RuleFunction; + JSXClosingFragment?: RuleFunction; + JSXElement?: RuleFunction; + JSXEmptyExpression?: RuleFunction; + JSXExpressionContainer?: RuleFunction; + JSXFragment?: RuleFunction; + JSXIdentifier?: RuleFunction; + JSXMemberExpression?: RuleFunction; + JSXOpeningElement?: RuleFunction; + JSXOpeningFragment?: RuleFunction; + JSXSpreadAttribute?: RuleFunction; + JSXSpreadChild?: RuleFunction; + JSXText?: RuleFunction; + LabeledStatement?: RuleFunction; + MemberExpression?: RuleFunction; + MetaProperty?: RuleFunction; + MethodDefinition?: RuleFunction; + NewExpression?: RuleFunction; + ObjectExpression?: RuleFunction; + ObjectPattern?: RuleFunction; + Program?: RuleFunction; + Property?: RuleFunction; + RestElement?: RuleFunction; + ReturnStatement?: RuleFunction; + SequenceExpression?: RuleFunction; + SpreadElement?: RuleFunction; + Super?: RuleFunction; + SwitchCase?: RuleFunction; + SwitchStatement?: RuleFunction; + TaggedTemplateExpression?: RuleFunction; + TemplateElement?: RuleFunction; + TemplateLiteral?: RuleFunction; + ThisExpression?: RuleFunction; + ThrowStatement?: RuleFunction; + Token?: RuleFunction; + TryStatement?: RuleFunction; + TSAbstractKeyword?: RuleFunction; + TSAnyKeyword?: RuleFunction; + TSArrayType?: RuleFunction; + TSAsExpression?: RuleFunction; + TSAsyncKeyword?: RuleFunction; + TSBigIntKeyword?: RuleFunction; + TSBooleanKeyword?: RuleFunction; + TSConditionalType?: RuleFunction; + TSDeclareKeyword?: RuleFunction; + TSEnumDeclaration?: RuleFunction; + TSEnumMember?: RuleFunction; + TSExportAssignment?: RuleFunction; + TSExportKeyword?: RuleFunction; + TSExternalModuleReference?: RuleFunction< + TSESTree.TSExternalModuleReference + >; + TSImportEqualsDeclaration?: RuleFunction< + TSESTree.TSImportEqualsDeclaration + >; + TSImportType?: RuleFunction; + TSIndexedAccessType?: RuleFunction; + TSIndexSignature?: RuleFunction; + TSInferType?: RuleFunction; + TSInterfaceBody?: RuleFunction; + TSInterfaceDeclaration?: RuleFunction; + TSIntersectionType?: RuleFunction; + TSLiteralType?: RuleFunction; + TSMappedType?: RuleFunction; + TSMethodSignature?: RuleFunction; + TSModuleBlock?: RuleFunction; + TSModuleDeclaration?: RuleFunction; + TSNamespaceExportDeclaration?: RuleFunction< + TSESTree.TSNamespaceExportDeclaration + >; + TSNeverKeyword?: RuleFunction; + TSNonNullExpression?: RuleFunction; + TSNullKeyword?: RuleFunction; + TSNumberKeyword?: RuleFunction; + TSObjectKeyword?: RuleFunction; + TSOptionalType?: RuleFunction; + TSParameterProperty?: RuleFunction; + TSParenthesizedType?: RuleFunction; + TSPrivateKeyword?: RuleFunction; + TSPropertySignature?: RuleFunction; + TSProtectedKeyword?: RuleFunction; + TSPublicKeyword?: RuleFunction; + TSQualifiedName?: RuleFunction; + TSReadonlyKeyword?: RuleFunction; + TSRestType?: RuleFunction; + TSStaticKeyword?: RuleFunction; + TSStringKeyword?: RuleFunction; + TSSymbolKeyword?: RuleFunction; + TSThisType?: RuleFunction; + TSTupleType?: RuleFunction; + TSTypeAliasDeclaration?: RuleFunction; + TSTypeAnnotation?: RuleFunction; + TSTypeAssertion?: RuleFunction; + TSTypeLiteral?: RuleFunction; + TSTypeOperator?: RuleFunction; + TSTypeParameter?: RuleFunction; + TSTypeParameterDeclaration?: RuleFunction< + TSESTree.TSTypeParameterDeclaration + >; + TSTypeParameterInstantiation?: RuleFunction< + TSESTree.TSTypeParameterInstantiation + >; + TSTypePredicate?: RuleFunction; + TSTypeQuery?: RuleFunction; + TSTypeReference?: RuleFunction; + TSUndefinedKeyword?: RuleFunction; + TSUnionType?: RuleFunction; + TSUnknownKeyword?: RuleFunction; + TSVoidKeyword?: RuleFunction; + VariableDeclaration?: RuleFunction; + VariableDeclarator?: RuleFunction; + WhileStatement?: RuleFunction; + WithStatement?: RuleFunction; + YieldExpression?: RuleFunction; + + // CodePath and CodePath segment methods + /** + * This is called at the start of analyzing a code path. + * In this time, the code path object has only the initial segment. + */ + onCodePathStart?: CodePathFunction; + + /** + * This is called at the end of analyzing a code path. + * In this time, the code path object is complete. + */ + onCodePathEnd?: CodePathFunction; + + /** + * This is called when a code path segment was created. + * It meant the code path is forked or merged. + * In this time, the segment has the previous segments and has been + * judged reachable or not. + */ + onCodePathSegmentStart?: CodePathSegmentFunction; + + /** + * This is called when a code path segment was leaved. + * In this time, the segment does not have the next segments yet. + */ + onCodePathSegmentEnd?: CodePathSegmentFunction; + + /** + * This is called when a code path segment was looped. + * Usually segments have each previous segments when created, + * but when looped, a segment is added as a new previous segment into a + * existing segment. + */ + onCodePathSegmentLoop?: CodePathSegmentLoopFunction; + } interface RuleModule< TMessageIds extends string, From a855f0c797d33b510f410769b532682de5ee1369 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Fri, 15 Feb 2019 10:13:32 -0800 Subject: [PATCH 2/2] undo adding types for codePath selectors --- packages/eslint-plugin/typings/ts-eslint.d.ts | 60 +------------------ 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/packages/eslint-plugin/typings/ts-eslint.d.ts b/packages/eslint-plugin/typings/ts-eslint.d.ts index 7497159d3106..0b10e4754db2 100644 --- a/packages/eslint-plugin/typings/ts-eslint.d.ts +++ b/packages/eslint-plugin/typings/ts-eslint.d.ts @@ -399,31 +399,8 @@ declare module 'ts-eslint' { // never will break someone's code unless they specifically type the function argument type RuleFunction = (node: T) => void; - type CodePathFunction = ( - codePath: Rule.CodePath, - node: TSESTree.BaseNode - ) => void; - - type CodePathSegmentFunction = ( - codePathSegment: Rule.CodePathSegment, - node: TSESTree.BaseNode - ) => void; - - type CodePathSegmentLoopFunction< - T extends TSESTree.BaseNode = TSESTree.Node - > = ( - fromCodePathSegment: Rule.CodePathSegment, - toCodePathSegment: Rule.CodePathSegment, - node: TSESTree.BaseNode - ) => void; - interface RuleListener { - [nodeSelector: string]: - | RuleFunction - | CodePathFunction - | CodePathSegmentFunction - | CodePathSegmentLoopFunction - | undefined; + [nodeSelector: string]: RuleFunction | undefined; ArrayExpression?: RuleFunction; ArrayPattern?: RuleFunction; ArrowFunctionExpression?: RuleFunction; @@ -573,41 +550,6 @@ declare module 'ts-eslint' { WhileStatement?: RuleFunction; WithStatement?: RuleFunction; YieldExpression?: RuleFunction; - - // CodePath and CodePath segment methods - /** - * This is called at the start of analyzing a code path. - * In this time, the code path object has only the initial segment. - */ - onCodePathStart?: CodePathFunction; - - /** - * This is called at the end of analyzing a code path. - * In this time, the code path object is complete. - */ - onCodePathEnd?: CodePathFunction; - - /** - * This is called when a code path segment was created. - * It meant the code path is forked or merged. - * In this time, the segment has the previous segments and has been - * judged reachable or not. - */ - onCodePathSegmentStart?: CodePathSegmentFunction; - - /** - * This is called when a code path segment was leaved. - * In this time, the segment does not have the next segments yet. - */ - onCodePathSegmentEnd?: CodePathSegmentFunction; - - /** - * This is called when a code path segment was looped. - * Usually segments have each previous segments when created, - * but when looped, a segment is added as a new previous segment into a - * existing segment. - */ - onCodePathSegmentLoop?: CodePathSegmentLoopFunction; } interface RuleModule<