Skip to content

fix: replace deprecated ESLint context methods for v10 compatibility#2946

Open
roli-lpci wants to merge 1 commit intographql-hive:masterfrom
roli-lpci:fix/eslint-10-compat
Open

fix: replace deprecated ESLint context methods for v10 compatibility#2946
roli-lpci wants to merge 1 commit intographql-hive:masterfrom
roli-lpci:fix/eslint-10-compat

Conversation

@roli-lpci
Copy link
Copy Markdown

Summary

Replaces all occurrences of the deprecated context.getSourceCode() method with the context.sourceCode property (with ?? fallback) across 9 rule files. This fixes the TypeError: context.getSourceCode is not a function crash when using @graphql-eslint/eslint-plugin with ESLint 10.

What changed

All 9 rule files that called context.getSourceCode() were updated to use context.sourceCode ?? context.getSourceCode():

  • alphabetize/index.ts
  • description-style/index.ts
  • graphql-js-validation.ts
  • no-anonymous-operations/index.ts
  • no-hashtag-description/index.ts
  • no-unused-fields/index.ts
  • require-import-fragment/index.ts
  • require-nullable-result-in-root/index.ts
  • selection-set-depth/index.ts

Why

context.getSourceCode() was deprecated in ESLint v8.40 and removed in ESLint v10. The context.sourceCode property 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-date are pre-existing (time-sensitive fixture) and unrelated to this change.

Fixes #2945

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>
@sroebert
Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

The alphabetize rule is broken with ESLint v10

2 participants