From e671153dde6406bee8955c0e2f56d76cdd3461f4 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 20 Oct 2023 21:04:37 +0000 Subject: [PATCH 1/7] chore(utils): deprecate `Context#parserServices` --- packages/utils/src/ts-eslint/Rule.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts index 172ee4b2dfcc..e4f74870daee 100644 --- a/packages/utils/src/ts-eslint/Rule.ts +++ b/packages/utils/src/ts-eslint/Rule.ts @@ -195,6 +195,8 @@ interface RuleContext< parserOptions: Linter.ParserOptions; /** * An object containing parser-provided services for rules + * + * @deprecated in favor of `SourceCode#parserServices` */ parserServices?: ParserServices; /** From 847f454807546c08f3680859bd08dcdc3d35f45c Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 20 Oct 2023 21:08:12 +0000 Subject: [PATCH 2/7] feat(utils): define new methods on `SourceCode` --- packages/utils/src/ts-eslint/SourceCode.ts | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/utils/src/ts-eslint/SourceCode.ts b/packages/utils/src/ts-eslint/SourceCode.ts index 03b9c9dd2896..bda114afadf3 100644 --- a/packages/utils/src/ts-eslint/SourceCode.ts +++ b/packages/utils/src/ts-eslint/SourceCode.ts @@ -299,6 +299,31 @@ declare class SourceCodeBase extends TokenStore { * @deprecated in favor of isSpaceBetween */ isSpaceBetweenTokens(first: TSESTree.Token, second: TSESTree.Token): boolean; + /** + * Returns the scope of the given node. + * This information can be used track references to variables. + * @since 8.37.0 + */ + getScope(node: TSESTree.Node): Scope.Scope; + /** + * Returns an array of the ancestors of the given node, starting at + * the root of the AST and continuing through the direct parent of the current node. + * This array does not include the currently-traversed node itself. + * @since 8.38.0 + */ + getScope(node: TSESTree.Node): TSESTree.Node[]; + /** + * Returns a list of variables declared by the given node. + * This information can be used to track references to variables. + * @since 8.38.0 + */ + getDeclaredVariables(node: TSESTree.Node): readonly Scope.Variable[]; + /** + * Marks a variable with the given name in the current scope as used. + * This affects the no-unused-vars rule. + * @since 8.39.0 + */ + markVariableAsUsed(name: string, node: TSESTree.Node): boolean; /** * The source code split into lines according to ECMA-262 specification. * This is done to avoid each rule needing to do so separately. From 0889310ebf9b21f42523a4882dfd4e8a6cfd0729 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 20 Oct 2023 21:11:21 +0000 Subject: [PATCH 3/7] chore(utils): mark `Context` properties and methods as deprecated --- packages/utils/src/ts-eslint/Rule.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts index e4f74870daee..e530bb6fb72b 100644 --- a/packages/utils/src/ts-eslint/Rule.ts +++ b/packages/utils/src/ts-eslint/Rule.ts @@ -209,12 +209,16 @@ interface RuleContext< * Returns an array of the ancestors of the currently-traversed node, starting at * the root of the AST and continuing through the direct parent of the current node. * This array does not include the currently-traversed node itself. + * + * @deprecated in favor of `SourceCode#getAncestors` */ getAncestors(): TSESTree.Node[]; /** * Returns a list of variables declared by the given node. * This information can be used to track references to variables. + * + * @deprecated in favor of `SourceCode#getDeclaredVariables` */ getDeclaredVariables(node: TSESTree.Node): readonly Scope.Variable[]; @@ -222,6 +226,7 @@ interface RuleContext< * Returns the current working directory passed to Linter. * It is a path to a directory that should be considered as the current working directory. * @since 6.6.0 + * @deprecated in favor of `RuleContext#cwd` */ getCwd(): string; @@ -234,6 +239,8 @@ interface RuleContext< /** * Returns the filename associated with the source. + * + * @deprecated in favor of `RuleContext#filename` */ getFilename(): string; @@ -246,6 +253,7 @@ interface RuleContext< /** * Returns the full path of the file on disk without any code block information (unlike `getFilename()`). * @since 7.28.0 + * @deprecated in favor of `RuleContext#physicalFilename` */ getPhysicalFilename?(): string; @@ -258,12 +266,16 @@ interface RuleContext< /** * Returns the scope of the currently-traversed node. * This information can be used track references to variables. + * + * @deprecated in favor of `SourceCode#getScope` */ getScope(): Scope.Scope; /** * Returns a SourceCode object that you can use to work with the source that * was passed to ESLint. + * + * @deprecated in favor of `RuleContext#sourceCode` */ getSourceCode(): Readonly; @@ -277,6 +289,8 @@ interface RuleContext< /** * Marks a variable with the given name in the current scope as used. * This affects the no-unused-vars rule. + * + * @deprecated in favor of `SourceCode#markVariableAsUsed` */ markVariableAsUsed(name: string): boolean; From 2fd1389592f12d29184b382b9092a13650c7929b Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 21 Oct 2023 12:20:24 +1300 Subject: [PATCH 4/7] fix(utils): `getAncestors` not `getScope` --- packages/utils/src/ts-eslint/SourceCode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/ts-eslint/SourceCode.ts b/packages/utils/src/ts-eslint/SourceCode.ts index bda114afadf3..cfc1b88268ac 100644 --- a/packages/utils/src/ts-eslint/SourceCode.ts +++ b/packages/utils/src/ts-eslint/SourceCode.ts @@ -311,7 +311,7 @@ declare class SourceCodeBase extends TokenStore { * This array does not include the currently-traversed node itself. * @since 8.38.0 */ - getScope(node: TSESTree.Node): TSESTree.Node[]; + getAncestors(node: TSESTree.Node): TSESTree.Node[]; /** * Returns a list of variables declared by the given node. * This information can be used to track references to variables. From a19a9f144fc92e3c829edf0281bb5cda2df842cb Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 21 Oct 2023 18:48:35 +0000 Subject: [PATCH 5/7] chore: ignore usage of deprecated property for now --- packages/utils/src/eslint-utils/getParserServices.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/utils/src/eslint-utils/getParserServices.ts b/packages/utils/src/eslint-utils/getParserServices.ts index 6b4d50b88638..03a9f7e56c85 100644 --- a/packages/utils/src/eslint-utils/getParserServices.ts +++ b/packages/utils/src/eslint-utils/getParserServices.ts @@ -67,7 +67,9 @@ function getParserServices( // This check allows us to handle bad user setups whilst providing a nice user-facing // error message explaining the problem. if ( + // eslint-disable-next-line deprecation/deprecation context.parserServices?.esTreeNodeToTSNodeMap == null || + // eslint-disable-next-line deprecation/deprecation context.parserServices.tsNodeToESTreeNodeMap == null ) { throw new Error(ERROR_MESSAGE); @@ -76,12 +78,14 @@ function getParserServices( // if a rule requires full type information, then hard fail if it doesn't exist // this forces the user to supply parserOptions.project if ( + // eslint-disable-next-line deprecation/deprecation context.parserServices.program == null && !allowWithoutFullTypeInformation ) { throw new Error(ERROR_MESSAGE); } + // eslint-disable-next-line deprecation/deprecation return context.parserServices; } /* eslint-enable @typescript-eslint/unified-signatures */ From 1992c0cc22007e550d9481bc3323a0b9c81a5c09 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 10 Nov 2023 20:13:03 +0000 Subject: [PATCH 6/7] fix(utils): mark new methods as optional --- packages/utils/src/ts-eslint/SourceCode.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/utils/src/ts-eslint/SourceCode.ts b/packages/utils/src/ts-eslint/SourceCode.ts index cfc1b88268ac..a1410e0928e0 100644 --- a/packages/utils/src/ts-eslint/SourceCode.ts +++ b/packages/utils/src/ts-eslint/SourceCode.ts @@ -304,26 +304,26 @@ declare class SourceCodeBase extends TokenStore { * This information can be used track references to variables. * @since 8.37.0 */ - getScope(node: TSESTree.Node): Scope.Scope; + getScope?(node: TSESTree.Node): Scope.Scope; /** * Returns an array of the ancestors of the given node, starting at * the root of the AST and continuing through the direct parent of the current node. * This array does not include the currently-traversed node itself. * @since 8.38.0 */ - getAncestors(node: TSESTree.Node): TSESTree.Node[]; + getAncestors?(node: TSESTree.Node): TSESTree.Node[]; /** * Returns a list of variables declared by the given node. * This information can be used to track references to variables. * @since 8.38.0 */ - getDeclaredVariables(node: TSESTree.Node): readonly Scope.Variable[]; + getDeclaredVariables?(node: TSESTree.Node): readonly Scope.Variable[]; /** * Marks a variable with the given name in the current scope as used. * This affects the no-unused-vars rule. * @since 8.39.0 */ - markVariableAsUsed(name: string, node: TSESTree.Node): boolean; + markVariableAsUsed?(name: string, node: TSESTree.Node): boolean; /** * The source code split into lines according to ECMA-262 specification. * This is done to avoid each rule needing to do so separately. From 892321b9790c7b140138dadfda22fa504332d70b Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Fri, 10 Nov 2023 19:09:30 -0800 Subject: [PATCH 7/7] Update getParserServices.ts --- packages/utils/src/eslint-utils/getParserServices.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/utils/src/eslint-utils/getParserServices.ts b/packages/utils/src/eslint-utils/getParserServices.ts index 03a9f7e56c85..6d36e26b4db9 100644 --- a/packages/utils/src/eslint-utils/getParserServices.ts +++ b/packages/utils/src/eslint-utils/getParserServices.ts @@ -67,9 +67,9 @@ function getParserServices( // This check allows us to handle bad user setups whilst providing a nice user-facing // error message explaining the problem. if ( - // eslint-disable-next-line deprecation/deprecation + // eslint-disable-next-line deprecation/deprecation -- TODO - support for ESLint v9 with backwards-compatible support for ESLint v8 context.parserServices?.esTreeNodeToTSNodeMap == null || - // eslint-disable-next-line deprecation/deprecation + // eslint-disable-next-line deprecation/deprecation -- TODO - support for ESLint v9 with backwards-compatible support for ESLint v8 context.parserServices.tsNodeToESTreeNodeMap == null ) { throw new Error(ERROR_MESSAGE); @@ -78,14 +78,14 @@ function getParserServices( // if a rule requires full type information, then hard fail if it doesn't exist // this forces the user to supply parserOptions.project if ( - // eslint-disable-next-line deprecation/deprecation + // eslint-disable-next-line deprecation/deprecation -- TODO - support for ESLint v9 with backwards-compatible support for ESLint v8 context.parserServices.program == null && !allowWithoutFullTypeInformation ) { throw new Error(ERROR_MESSAGE); } - // eslint-disable-next-line deprecation/deprecation + // eslint-disable-next-line deprecation/deprecation -- TODO - support for ESLint v9 with backwards-compatible support for ESLint v8 return context.parserServices; } /* eslint-enable @typescript-eslint/unified-signatures */