From 5e28949e88617f4994b3e93a14213c7eec640ec4 Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:15:12 -0400 Subject: [PATCH 01/12] feat: add CodePath interfaces --- packages/ast-spec/src/base/CodePath.ts | 17 +++++++++++++++++ packages/ast-spec/src/index.ts | 1 + 2 files changed, 18 insertions(+) create mode 100644 packages/ast-spec/src/base/CodePath.ts diff --git a/packages/ast-spec/src/base/CodePath.ts b/packages/ast-spec/src/base/CodePath.ts new file mode 100644 index 000000000000..f86f2ff4ee8b --- /dev/null +++ b/packages/ast-spec/src/base/CodePath.ts @@ -0,0 +1,17 @@ +export interface CodePath { + id: string; + initialSegment: CodePathSegment; + finalSegments: CodePathSegment[]; + returnedSegments: CodePathSegment[]; + thrownSegments: CodePathSegment[]; + currentSegments: CodePathSegment[]; + upper: CodePath | null; + childCodePaths: CodePath[]; +} + +export interface CodePathSegment { + id: string; + nextSegments: CodePathSegment[]; + prevSegments: CodePathSegment[]; + reachable: boolean; +} diff --git a/packages/ast-spec/src/index.ts b/packages/ast-spec/src/index.ts index 3ca95ed64176..cfa828363119 100644 --- a/packages/ast-spec/src/index.ts +++ b/packages/ast-spec/src/index.ts @@ -1,5 +1,6 @@ export * from './base/Accessibility'; export * from './base/BaseNode'; // this is exported so that the `types` package can merge the decl and add the `parent` property +export * from './base/CodePath'; export * from './base/NodeOrTokenData'; export * from './base/OptionalRangeAndLoc'; export * from './base/Position'; From f3f8389511e3fb0bb1e1682482b1a476cd1002cf Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:10:18 -0400 Subject: [PATCH 02/12] feat: enable code path methods --- packages/ast-spec/src/base/CodePath.ts | 18 ++++++++++++++ .../eslint-plugin/typings/eslint-rules.d.ts | 24 ++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/ast-spec/src/base/CodePath.ts b/packages/ast-spec/src/base/CodePath.ts index f86f2ff4ee8b..28257249eabc 100644 --- a/packages/ast-spec/src/base/CodePath.ts +++ b/packages/ast-spec/src/base/CodePath.ts @@ -1,3 +1,12 @@ +/** + * Part of the code path analysis feature of ESLint: + * https://eslint.org/docs/latest/extend/code-path-analysis + * + * These are used in the `onCodePathStart` and `onCodePathEnd` methods. + * + * Note that the `node` parameter of these methods is intentionally typed as + * `never`: https://github.com/typescript-eslint/typescript-eslint/issues/6993 + */ export interface CodePath { id: string; initialSegment: CodePathSegment; @@ -9,6 +18,15 @@ export interface CodePath { childCodePaths: CodePath[]; } +/** + * Part of the code path analysis feature of ESLint: + * https://eslint.org/docs/latest/extend/code-path-analysis + * + * These are used in the `onCodePathStart` and `onCodePathEnd` methods. + * + * Note that the `node` parameter of these methods is intentionally typed as + * `never`: https://github.com/typescript-eslint/typescript-eslint/issues/6993 + */ export interface CodePathSegment { id: string; nextSegments: CodePathSegment[]; diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 295dd4d757c5..1f9331c54338 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -806,6 +806,7 @@ declare module 'eslint/lib/rules/init-declarations' { } declare module 'eslint/lib/rules/no-invalid-this' { + import type { CodePath } from '@typescript-eslint/ast-spec'; import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< @@ -825,9 +826,26 @@ declare module 'eslint/lib/rules/no-invalid-this' { 'FunctionExpression:exit'?: (node: TSESTree.FunctionExpression) => void; // for ESLint >= v8.7.0 - // We don't use it and we don't have the CodePath types, so comment out it. - // onCodePathStart?: (codePath: unknown, node: TSESTree.Node) => void - // onCodePathEnd?: (codePath: unknown, node: TSESTree.Node) => void + /** + * The second parameter of `node` is intentionally typed as `never` in + * order to prevent TypeScript errors: + * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * + * If you want to use this method, you can either ignore the `node` or + * manually type assert it to something else, depending on what you want + * to do. + */ + onCodePathStart?: (codePath: CodePath, node: never) => void; + /** + * The second parameter of `node` is intentionally typed as `never` in + * order to prevent TypeScript errors: + * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * + * If you want to use this method, you can either ignore the `node` or + * manually type assert it to something else, depending on what you want + * to do. + */ + onCodePathEnd?: (codePath: CodePath, node: never) => void; // Common ThisExpression(node: TSESTree.ThisExpression): void; From c7771510b7d0d7688459439fe81ae0146132534f Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:25:42 -0400 Subject: [PATCH 03/12] fix: build --- packages/ast-spec/src/base/CodePath.ts | 12 ++-- .../eslint-plugin/typings/eslint-rules.d.ts | 56 +++++++++++++++---- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/packages/ast-spec/src/base/CodePath.ts b/packages/ast-spec/src/base/CodePath.ts index 28257249eabc..63798efb33f1 100644 --- a/packages/ast-spec/src/base/CodePath.ts +++ b/packages/ast-spec/src/base/CodePath.ts @@ -2,10 +2,10 @@ * Part of the code path analysis feature of ESLint: * https://eslint.org/docs/latest/extend/code-path-analysis * - * These are used in the `onCodePathStart` and `onCodePathEnd` methods. + * These are used in the `onCodePath*` methods. (Note that the `node` parameter + * of these methods is intentionally typed as `unknown`.) * - * Note that the `node` parameter of these methods is intentionally typed as - * `never`: https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 */ export interface CodePath { id: string; @@ -22,10 +22,10 @@ export interface CodePath { * Part of the code path analysis feature of ESLint: * https://eslint.org/docs/latest/extend/code-path-analysis * - * These are used in the `onCodePathStart` and `onCodePathEnd` methods. + * These are used in the `onCodePath*` methods. (Note that the `node` parameter + * of these methods is intentionally typed as `unknown`.) * - * Note that the `node` parameter of these methods is intentionally typed as - * `never`: https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 */ export interface CodePathSegment { id: string; diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 1f9331c54338..b8fda174083a 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -818,34 +818,70 @@ declare module 'eslint/lib/rules/no-invalid-this' { ], { // for ESLint < v8.7.0 + Program?: (node: TSESTree.Program) => void; 'Program:exit'?: (node: TSESTree.Program) => void; + FunctionDeclaration?: (node: TSESTree.FunctionDeclaration) => void; 'FunctionDeclaration:exit'?: (node: TSESTree.FunctionDeclaration) => void; + FunctionExpression?: (node: TSESTree.FunctionExpression) => void; 'FunctionExpression:exit'?: (node: TSESTree.FunctionExpression) => void; // for ESLint >= v8.7.0 + + /** + * The second parameter of `node` is intentionally omitted in order to + * prevent TypeScript errors: + * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * + * If you want to use this method, you can either ignore the `node` or + * specify it with a type assertion, depending on what you want to do. + */ + onCodePathStart?: (codePath: CodePath) => void; + + /** + * The second parameter of `node` is intentionally omitted in order to + * prevent TypeScript errors: + * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * + * If you want to use this method, you can either ignore the `node` or + * specify it with a type assertion, depending on what you want to do. + */ + onCodePathEnd?: (codePath: CodePath) => void; + + /** + * The second parameter of `node` is intentionally omitted in order to + * prevent TypeScript errors: + * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * + * If you want to use this method, you can either ignore the `node` or + * specify it with a type assertion, depending on what you want to do. + */ + onCodePathSegmentStart?: (segment: CodePathSegment) => void; + /** - * The second parameter of `node` is intentionally typed as `never` in - * order to prevent TypeScript errors: + * The second parameter of `node` is intentionally omitted in order to + * prevent TypeScript errors: * https://github.com/typescript-eslint/typescript-eslint/issues/6993 * * If you want to use this method, you can either ignore the `node` or - * manually type assert it to something else, depending on what you want - * to do. + * specify it with a type assertion, depending on what you want to do. */ - onCodePathStart?: (codePath: CodePath, node: never) => void; + onCodePathSegmentEnd?: (segment: CodePathSegment) => void; + /** - * The second parameter of `node` is intentionally typed as `never` in - * order to prevent TypeScript errors: + * The third parameter of `node` is intentionally omitted in order to + * prevent TypeScript errors: * https://github.com/typescript-eslint/typescript-eslint/issues/6993 * * If you want to use this method, you can either ignore the `node` or - * manually type assert it to something else, depending on what you want - * to do. + * specify it with a type assertion, depending on what you want to do. */ - onCodePathEnd?: (codePath: CodePath, node: never) => void; + onCodePathSegmentLoop?: ( + fromSegment: CodePathSegment, + toSegment: CodePathSegment, + ) => void; // Common ThisExpression(node: TSESTree.ThisExpression): void; From e20db45ed10acbc16b7d26d2dd12f5d5501ab7c4 Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:30:50 -0400 Subject: [PATCH 04/12] feat: export CodePathFunction --- packages/ast-spec/src/base/CodePath.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/ast-spec/src/base/CodePath.ts b/packages/ast-spec/src/base/CodePath.ts index 63798efb33f1..0220ef438f91 100644 --- a/packages/ast-spec/src/base/CodePath.ts +++ b/packages/ast-spec/src/base/CodePath.ts @@ -1,9 +1,11 @@ +import type { TSESTree } from '@typescript-eslint/types'; + /** * Part of the code path analysis feature of ESLint: * https://eslint.org/docs/latest/extend/code-path-analysis * * These are used in the `onCodePath*` methods. (Note that the `node` parameter - * of these methods is intentionally typed as `unknown`.) + * of these methods is intentionally omitted.) * * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 */ @@ -23,7 +25,7 @@ export interface CodePath { * https://eslint.org/docs/latest/extend/code-path-analysis * * These are used in the `onCodePath*` methods. (Note that the `node` parameter - * of these methods is intentionally typed as `unknown`.) + * of these methods is intentionally omitted.) * * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 */ @@ -33,3 +35,22 @@ export interface CodePathSegment { prevSegments: CodePathSegment[]; reachable: boolean; } + +/** + * Part of the code path analysis feature of ESLint: + * https://eslint.org/docs/latest/extend/code-path-analysis + * + * This type is unused in the `typescript-eslint` codebase since putting it on + * the `nodeSelector` for `RuleListener` would break the existing definition. + * However, it is exported here for the purposes of manual type-assertion. + * + * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 + */ +export type CodePathFunction = + | (( + fromSegment: CodePathSegment, + toSegment: CodePathSegment, + node: TSESTree.Node, + ) => void) + | ((codePath: CodePath, node: TSESTree.Node) => void) + | ((segment: CodePathSegment, node: TSESTree.Node) => void); From 3d92607b895c87e5a0a563f637d6d03ba81151dd Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:35:47 -0400 Subject: [PATCH 05/12] fix: build --- packages/ast-spec/src/base/CodePath.ts | 56 ------------------------- packages/ast-spec/src/index.ts | 1 - packages/utils/src/ts-eslint/Rule.ts | 58 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 57 deletions(-) delete mode 100644 packages/ast-spec/src/base/CodePath.ts diff --git a/packages/ast-spec/src/base/CodePath.ts b/packages/ast-spec/src/base/CodePath.ts deleted file mode 100644 index 0220ef438f91..000000000000 --- a/packages/ast-spec/src/base/CodePath.ts +++ /dev/null @@ -1,56 +0,0 @@ -import type { TSESTree } from '@typescript-eslint/types'; - -/** - * Part of the code path analysis feature of ESLint: - * https://eslint.org/docs/latest/extend/code-path-analysis - * - * These are used in the `onCodePath*` methods. (Note that the `node` parameter - * of these methods is intentionally omitted.) - * - * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 - */ -export interface CodePath { - id: string; - initialSegment: CodePathSegment; - finalSegments: CodePathSegment[]; - returnedSegments: CodePathSegment[]; - thrownSegments: CodePathSegment[]; - currentSegments: CodePathSegment[]; - upper: CodePath | null; - childCodePaths: CodePath[]; -} - -/** - * Part of the code path analysis feature of ESLint: - * https://eslint.org/docs/latest/extend/code-path-analysis - * - * These are used in the `onCodePath*` methods. (Note that the `node` parameter - * of these methods is intentionally omitted.) - * - * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 - */ -export interface CodePathSegment { - id: string; - nextSegments: CodePathSegment[]; - prevSegments: CodePathSegment[]; - reachable: boolean; -} - -/** - * Part of the code path analysis feature of ESLint: - * https://eslint.org/docs/latest/extend/code-path-analysis - * - * This type is unused in the `typescript-eslint` codebase since putting it on - * the `nodeSelector` for `RuleListener` would break the existing definition. - * However, it is exported here for the purposes of manual type-assertion. - * - * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 - */ -export type CodePathFunction = - | (( - fromSegment: CodePathSegment, - toSegment: CodePathSegment, - node: TSESTree.Node, - ) => void) - | ((codePath: CodePath, node: TSESTree.Node) => void) - | ((segment: CodePathSegment, node: TSESTree.Node) => void); diff --git a/packages/ast-spec/src/index.ts b/packages/ast-spec/src/index.ts index cfa828363119..3ca95ed64176 100644 --- a/packages/ast-spec/src/index.ts +++ b/packages/ast-spec/src/index.ts @@ -1,6 +1,5 @@ export * from './base/Accessibility'; export * from './base/BaseNode'; // this is exported so that the `types` package can merge the decl and add the `parent` property -export * from './base/CodePath'; export * from './base/NodeOrTokenData'; export * from './base/OptionalRangeAndLoc'; export * from './base/Position'; diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts index 172ee4b2dfcc..fa352e9a8e39 100644 --- a/packages/utils/src/ts-eslint/Rule.ts +++ b/packages/utils/src/ts-eslint/Rule.ts @@ -284,6 +284,61 @@ interface RuleContext< report(descriptor: ReportDescriptor): void; } +/** + * Part of the code path analysis feature of ESLint: + * https://eslint.org/docs/latest/extend/code-path-analysis + * + * These are used in the `onCodePath*` methods. (Note that the `node` parameter + * of these methods is intentionally omitted.) + * + * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 + */ +interface CodePath { + id: string; + initialSegment: CodePathSegment; + finalSegments: CodePathSegment[]; + returnedSegments: CodePathSegment[]; + thrownSegments: CodePathSegment[]; + currentSegments: CodePathSegment[]; + upper: CodePath | null; + childCodePaths: CodePath[]; +} + +/** + * Part of the code path analysis feature of ESLint: + * https://eslint.org/docs/latest/extend/code-path-analysis + * + * These are used in the `onCodePath*` methods. (Note that the `node` parameter + * of these methods is intentionally omitted.) + * + * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 + */ +interface CodePathSegment { + id: string; + nextSegments: CodePathSegment[]; + prevSegments: CodePathSegment[]; + reachable: boolean; +} + +/** + * Part of the code path analysis feature of ESLint: + * https://eslint.org/docs/latest/extend/code-path-analysis + * + * This type is unused in the `typescript-eslint` codebase since putting it on + * the `nodeSelector` for `RuleListener` would break the existing definition. + * However, it is exported here for the purposes of manual type-assertion. + * + * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 + */ +type CodePathFunction = + | (( + fromSegment: CodePathSegment, + toSegment: CodePathSegment, + node: TSESTree.Node, + ) => void) + | ((codePath: CodePath, node: TSESTree.Node) => void) + | ((segment: CodePathSegment, node: TSESTree.Node) => void); + // This isn't the correct signature, but it makes it easier to do custom unions within reusable listeners // never will break someone's code unless they specifically type the function argument type RuleFunction = ( @@ -494,6 +549,9 @@ type AnyRuleCreateFunction = RuleCreateFunction; export { AnyRuleCreateFunction, AnyRuleModule, + CodePath, + CodePathFunction, + CodePathSegment, ReportDescriptor, ReportDescriptorMessageData, ReportFixFunction, From 2aabcc614ab938af91a553ab1dac347e03b89eab Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:48:06 -0400 Subject: [PATCH 06/12] fix: build --- .../eslint-plugin/typings/eslint-rules.d.ts | 83 ++++++++++++------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index b8fda174083a..2af351796e20 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -806,7 +806,6 @@ declare module 'eslint/lib/rules/init-declarations' { } declare module 'eslint/lib/rules/no-invalid-this' { - import type { CodePath } from '@typescript-eslint/ast-spec'; import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< @@ -831,56 +830,76 @@ declare module 'eslint/lib/rules/no-invalid-this' { // for ESLint >= v8.7.0 /** - * The second parameter of `node` is intentionally omitted in order to - * prevent TypeScript errors: - * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * The second parameter of `node` (with a type of `TSESTree.Node`) is + * [intentionally omitted in order to prevent TypeScript + * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). * - * If you want to use this method, you can either ignore the `node` or - * specify it with a type assertion, depending on what you want to do. + * If you want to use this method, you can either ignore the `node` + * parameter or specify it with a type assertion, depending on what you + * want to do. */ - onCodePathStart?: (codePath: CodePath) => void; + onCodePathStart?: ( + codePath: TSESLint.CodePath, + // node: TSESTree.Node, + ) => void; /** - * The second parameter of `node` is intentionally omitted in order to - * prevent TypeScript errors: - * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * The second parameter of `node` (with a type of `TSESTree.Node`) is + * [intentionally omitted in order to prevent TypeScript + * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). * - * If you want to use this method, you can either ignore the `node` or - * specify it with a type assertion, depending on what you want to do. + * If you want to use this method, you can either ignore the `node` + * parameter or specify it with a type assertion, depending on what you + * want to do. */ - onCodePathEnd?: (codePath: CodePath) => void; + onCodePathEnd?: ( + codePath: TSESLint.CodePath, + // node: TSESTree.Node, + ) => void; /** - * The second parameter of `node` is intentionally omitted in order to - * prevent TypeScript errors: - * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * The second parameter of `node` (with a type of `TSESTree.Node`) is + * [intentionally omitted in order to prevent TypeScript + * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). * - * If you want to use this method, you can either ignore the `node` or - * specify it with a type assertion, depending on what you want to do. + * If you want to use this method, you can either ignore the `node` + * parameter or specify it with a type assertion, depending on what you + * want to do. */ - onCodePathSegmentStart?: (segment: CodePathSegment) => void; + onCodePathSegmentStart?: ( + segment: TSESLint.CodePathSegment, + // node: TSESTree.Node, + ) => void; /** - * The second parameter of `node` is intentionally omitted in order to - * prevent TypeScript errors: - * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * The second parameter of `node` (with a type of `TSESTree.Node`) is + * [intentionally omitted in order to prevent TypeScript + * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). * - * If you want to use this method, you can either ignore the `node` or - * specify it with a type assertion, depending on what you want to do. + * If you want to use this method, you can either ignore the `node` + * parameter or specify it with a type assertion, depending on what you + * want to do. */ - onCodePathSegmentEnd?: (segment: CodePathSegment) => void; + onCodePathSegmentEnd?: ( + segment: TSESLint.CodePathSegment, + // node: TSESTree.Node, + ) => void; /** - * The third parameter of `node` is intentionally omitted in order to - * prevent TypeScript errors: - * https://github.com/typescript-eslint/typescript-eslint/issues/6993 + * The second parameter of `toSegment` (with a type of + * `TSESLint.CodePathSegment`) and the third parameter of `node` (with a + * type of `TSESTree.Node`) is [intentionally omitted in order to prevent + * TypeScript + * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). * - * If you want to use this method, you can either ignore the `node` or - * specify it with a type assertion, depending on what you want to do. + * If you want to use this method, you can either ignore those parameters + * or specify them with a type assertion, depending on what you want to + * do. */ onCodePathSegmentLoop?: ( - fromSegment: CodePathSegment, - toSegment: CodePathSegment, + fromSegment: TSESLint.CodePathSegment, + // toSegment: TSESLint.CodePathSegment, + // node: TSESTree.Node, ) => void; // Common From a7099463a76d311cb2a6767996ccc10c5d97e77b Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:16:02 -0400 Subject: [PATCH 07/12] fix: grammar --- packages/eslint-plugin/typings/eslint-rules.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 2af351796e20..7a4ad8bc7ddd 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -888,7 +888,7 @@ declare module 'eslint/lib/rules/no-invalid-this' { /** * The second parameter of `toSegment` (with a type of * `TSESLint.CodePathSegment`) and the third parameter of `node` (with a - * type of `TSESTree.Node`) is [intentionally omitted in order to prevent + * type of `TSESTree.Node`) are [intentionally omitted in order to prevent * TypeScript * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). * From 334db9cca0ac95458e92e8f805c2aa55ed6aac7c Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Fri, 15 Sep 2023 22:39:47 -0400 Subject: [PATCH 08/12] feat: add jsdoc --- packages/utils/src/ts-eslint/Rule.ts | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts index fa352e9a8e39..b0a4e37bf5e4 100644 --- a/packages/utils/src/ts-eslint/Rule.ts +++ b/packages/utils/src/ts-eslint/Rule.ts @@ -294,13 +294,34 @@ interface RuleContext< * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 */ interface CodePath { + /** + * A unique string. Respective rules can use `id` to save additional + * information for each code path. + */ id: string; + initialSegment: CodePathSegment; + + /** The final segments which includes both returned and thrown. */ finalSegments: CodePathSegment[]; + + /** The final segments which includes only returned. */ returnedSegments: CodePathSegment[]; + + /** The final segments which includes only thrown. */ thrownSegments: CodePathSegment[]; + + /** + * Segments of the current traversal position. + * + * @deprecated + */ currentSegments: CodePathSegment[]; + + /** The code path of the upper function/global scope. */ upper: CodePath | null; + + /** Code paths of functions this code path contains. */ childCodePaths: CodePath[]; } @@ -314,9 +335,28 @@ interface CodePath { * @see https://github.com/typescript-eslint/typescript-eslint/issues/6993 */ interface CodePathSegment { + /** + * A unique string. Respective rules can use `id` to save additional + * information for each segment. + */ id: string; + + /** + * The next segments. If forking, there are two or more. If final, there is + * nothing. + */ nextSegments: CodePathSegment[]; + + /** + * The previous segments. If merging, there are two or more. If initial, there + * is nothing. + */ prevSegments: CodePathSegment[]; + + /** + * A flag which shows whether it is reachable. This becomes `false` when + * preceded by `return`, `throw`, `break`, or `continue`. + */ reachable: boolean; } From f8cbe1ea085bd8963056318524fac4627f30779e Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Fri, 15 Sep 2023 23:39:16 -0400 Subject: [PATCH 09/12] fix: prettier --- packages/utils/src/ts-eslint/Rule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts index b0a4e37bf5e4..f34104c49625 100644 --- a/packages/utils/src/ts-eslint/Rule.ts +++ b/packages/utils/src/ts-eslint/Rule.ts @@ -315,7 +315,7 @@ interface CodePath { * Segments of the current traversal position. * * @deprecated - */ + */ currentSegments: CodePathSegment[]; /** The code path of the upper function/global scope. */ From f1b8ebe83aeaee2c5b8364149d9b32a31dd0ce16 Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Sat, 16 Sep 2023 22:46:45 -0400 Subject: [PATCH 10/12] refactor: comment out types --- .../eslint-plugin/typings/eslint-rules.d.ts | 73 +++++-------------- 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 7a4ad8bc7ddd..f7eebb8f477a 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -829,78 +829,45 @@ declare module 'eslint/lib/rules/no-invalid-this' { // for ESLint >= v8.7.0 - /** - * The second parameter of `node` (with a type of `TSESTree.Node`) is - * [intentionally omitted in order to prevent TypeScript - * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). - * - * If you want to use this method, you can either ignore the `node` - * parameter or specify it with a type assertion, depending on what you - * want to do. - */ + // The code path functions below are intentionally commented out because + // they cause unresolvable compiler errors: + // https://github.com/typescript-eslint/typescript-eslint/issues/6993 + + /* onCodePathStart?: ( codePath: TSESLint.CodePath, - // node: TSESTree.Node, + node: TSESTree.Node, ) => void; + */ - /** - * The second parameter of `node` (with a type of `TSESTree.Node`) is - * [intentionally omitted in order to prevent TypeScript - * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). - * - * If you want to use this method, you can either ignore the `node` - * parameter or specify it with a type assertion, depending on what you - * want to do. - */ + /* onCodePathEnd?: ( codePath: TSESLint.CodePath, - // node: TSESTree.Node, + node: TSESTree.Node, ) => void; + */ - /** - * The second parameter of `node` (with a type of `TSESTree.Node`) is - * [intentionally omitted in order to prevent TypeScript - * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). - * - * If you want to use this method, you can either ignore the `node` - * parameter or specify it with a type assertion, depending on what you - * want to do. - */ + /* onCodePathSegmentStart?: ( segment: TSESLint.CodePathSegment, - // node: TSESTree.Node, + node: TSESTree.Node, ) => void; + */ - /** - * The second parameter of `node` (with a type of `TSESTree.Node`) is - * [intentionally omitted in order to prevent TypeScript - * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). - * - * If you want to use this method, you can either ignore the `node` - * parameter or specify it with a type assertion, depending on what you - * want to do. - */ + /* onCodePathSegmentEnd?: ( segment: TSESLint.CodePathSegment, - // node: TSESTree.Node, + node: TSESTree.Node, ) => void; + */ - /** - * The second parameter of `toSegment` (with a type of - * `TSESLint.CodePathSegment`) and the third parameter of `node` (with a - * type of `TSESTree.Node`) are [intentionally omitted in order to prevent - * TypeScript - * errors](https://github.com/typescript-eslint/typescript-eslint/issues/6993). - * - * If you want to use this method, you can either ignore those parameters - * or specify them with a type assertion, depending on what you want to - * do. - */ + /* onCodePathSegmentLoop?: ( fromSegment: TSESLint.CodePathSegment, - // toSegment: TSESLint.CodePathSegment, - // node: TSESTree.Node, + toSegment: TSESLint.CodePathSegment, + node: TSESTree.Node, ) => void; + */ // Common ThisExpression(node: TSESTree.ThisExpression): void; From aa3f504f5d9054f26b75aa85ed53847ca02441ac Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Sun, 17 Sep 2023 11:40:13 -0400 Subject: [PATCH 11/12] Update eslint-rules.d.ts --- packages/eslint-plugin/typings/eslint-rules.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index f7eebb8f477a..40faed3c99f3 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -832,6 +832,9 @@ declare module 'eslint/lib/rules/no-invalid-this' { // The code path functions below are intentionally commented out because // they cause unresolvable compiler errors: // https://github.com/typescript-eslint/typescript-eslint/issues/6993 + // Note that plugin authors can copy-paste these functions into their own + // code as selectors and they will still work as long as the second argument + // is omitted. /* onCodePathStart?: ( From acef4cb500ffb3e9cc84d464c89c4bd4709c2cc1 Mon Sep 17 00:00:00 2001 From: James <5511220+Zamiell@users.noreply.github.com> Date: Fri, 10 Nov 2023 07:52:14 -0500 Subject: [PATCH 12/12] fix: comment location --- .../eslint-plugin/typings/eslint-rules.d.ts | 45 ------------------- packages/utils/src/ts-eslint/Rule.ts | 41 ++++++++++++++++- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 40faed3c99f3..46c06aacc915 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -827,51 +827,6 @@ declare module 'eslint/lib/rules/no-invalid-this' { FunctionExpression?: (node: TSESTree.FunctionExpression) => void; 'FunctionExpression:exit'?: (node: TSESTree.FunctionExpression) => void; - // for ESLint >= v8.7.0 - - // The code path functions below are intentionally commented out because - // they cause unresolvable compiler errors: - // https://github.com/typescript-eslint/typescript-eslint/issues/6993 - // Note that plugin authors can copy-paste these functions into their own - // code as selectors and they will still work as long as the second argument - // is omitted. - - /* - onCodePathStart?: ( - codePath: TSESLint.CodePath, - node: TSESTree.Node, - ) => void; - */ - - /* - onCodePathEnd?: ( - codePath: TSESLint.CodePath, - node: TSESTree.Node, - ) => void; - */ - - /* - onCodePathSegmentStart?: ( - segment: TSESLint.CodePathSegment, - node: TSESTree.Node, - ) => void; - */ - - /* - onCodePathSegmentEnd?: ( - segment: TSESLint.CodePathSegment, - node: TSESTree.Node, - ) => void; - */ - - /* - onCodePathSegmentLoop?: ( - fromSegment: TSESLint.CodePathSegment, - toSegment: TSESLint.CodePathSegment, - node: TSESTree.Node, - ) => void; - */ - // Common ThisExpression(node: TSESTree.ThisExpression): void; } diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts index f34104c49625..b42dd9c6e090 100644 --- a/packages/utils/src/ts-eslint/Rule.ts +++ b/packages/utils/src/ts-eslint/Rule.ts @@ -550,7 +550,46 @@ type RuleListenerExitSelectors = { type RuleListenerCatchAllBaseCase = Record; // Interface to merge into for anyone that wants to add more selectors // eslint-disable-next-line @typescript-eslint/no-empty-interface -interface RuleListenerExtension {} +interface RuleListenerExtension { + // The code path functions below were introduced in ESLint v8.7.0 but are + // intentionally commented out because they cause unresolvable compiler + // errors: + // https://github.com/typescript-eslint/typescript-eslint/issues/6993 + // Note that plugin authors can copy-paste these functions into their own code + // as selectors and they will still work as long as the second argument is + // omitted. + /* + onCodePathStart?: ( + codePath: TSESLint.CodePath, + node: TSESTree.Node, + ) => void; + */ + /* + onCodePathEnd?: ( + codePath: TSESLint.CodePath, + node: TSESTree.Node, + ) => void; + */ + /* + onCodePathSegmentStart?: ( + segment: TSESLint.CodePathSegment, + node: TSESTree.Node, + ) => void; + */ + /* + onCodePathSegmentEnd?: ( + segment: TSESLint.CodePathSegment, + node: TSESTree.Node, + ) => void; + */ + /* + onCodePathSegmentLoop?: ( + fromSegment: TSESLint.CodePathSegment, + toSegment: TSESLint.CodePathSegment, + node: TSESTree.Node, + ) => void; + */ +} type RuleListener = RuleListenerBaseSelectors & RuleListenerCatchAllBaseCase & pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy