fix: replace deprecated ESLint context methods for v10 compatibility#2946
Open
roli-lpci wants to merge 1 commit intographql-hive:masterfrom
Open
fix: replace deprecated ESLint context methods for v10 compatibility#2946roli-lpci wants to merge 1 commit intographql-hive:masterfrom
roli-lpci wants to merge 1 commit intographql-hive:masterfrom
Conversation
Replace all 9 occurrences of `context.getSourceCode()` with the backward-compatible fallback `context.sourceCode ?? context.getSourceCode()`. This ensures the plugin works with ESLint 10 (which removes the deprecated `getSourceCode()` method) while maintaining backward compatibility with ESLint 8.44+ and 9.x. Closes graphql-hive#2945 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Been quite a while since this one is open, can we get this merged? This is the only dependency preventing us to update to eslint 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces all occurrences of the deprecated
context.getSourceCode()method with thecontext.sourceCodeproperty (with??fallback) across 9 rule files. This fixes theTypeError: context.getSourceCode is not a functioncrash when using@graphql-eslint/eslint-pluginwith ESLint 10.What changed
All 9 rule files that called
context.getSourceCode()were updated to usecontext.sourceCode ?? context.getSourceCode():alphabetize/index.tsdescription-style/index.tsgraphql-js-validation.tsno-anonymous-operations/index.tsno-hashtag-description/index.tsno-unused-fields/index.tsrequire-import-fragment/index.tsrequire-nullable-result-in-root/index.tsselection-set-depth/index.tsWhy
context.getSourceCode()was deprecated in ESLint v8.40 and removed in ESLint v10. Thecontext.sourceCodeproperty has been available since v8.40 and is already used elsewhere in the codebase (e.g.,utils.ts).The
??fallback ensures backward compatibility with all currently supported ESLint versions.Reference: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/
Testing
All 78 targeted rule tests pass. The 2 failures in
require-deprecation-dateare pre-existing (time-sensitive fixture) and unrelated to this change.Fixes #2945