Skip to content

Conversation

@Pixel998
Copy link
Contributor

@Pixel998 Pixel998 commented Nov 2, 2025

Prerequisites checklist

What is the purpose of this pull request?

ESLint v10 will remove several methods from the context and SourceCode objects:

From context:

  • parserOptions → use context.languageOptions.parserOptions
  • getCwd() → use context.cwd
  • getFilename() → use context.filename
  • getPhysicalFilename() → use context.physicalFilename
  • getSourceCode() → use context.sourceCode

From SourceCode:

  • getTokenOrCommentBefore() → use getTokenBefore({ includeComments: true })
  • getTokenOrCommentAfter() → use getTokenAfter({ includeComments: true })
  • isSpaceBetweenTokens() → use isSpaceBetween()
  • getJSDocComment() → removed entirely (no direct replacement)

This change patches those methods to maintain backward compatibility so existing ESLint v9 rules and plugins continue to work with @eslint/compat.

What changes did you make? (Give an overview)

  • Added compatibility patches in fixupRule() to restore these methods when missing.
  • Updated fixupPluginRules() and fixupConfigRules() to wrap affected rules automatically.
  • Added tests verifying parity with ESLint v9 behavior for each patched method.

Related Issues

Fixes #279

Is there anything you'd like reviewers to focus on?

@mdjermanovic
Copy link
Member

Can we also patch context.parserOptions?

@aladdin-add aladdin-add moved this from Needs Triage to Implementing in Triage Nov 5, 2025
@aladdin-add aladdin-add requested a review from Copilot November 5, 2025 09:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the @eslint/compat package to adapt ESLint v9.x rules/plugins for use in ESLint v10.x. The main changes involve rewriting the compatibility layer to restore deprecated context and sourceCode methods using a Proxy-based approach instead of wrapping visitor methods.

  • Replaces the visitor-wrapping approach with a Proxy-based context wrapper
  • Restores deprecated context methods (getCwd, getFilename, getPhysicalFilename, getSourceCode) and sourceCode methods (getTokenOrCommentBefore/After, isSpaceBetweenTokens, getJSDocComment)
  • Updates documentation to reflect ESLint v9.x → v10.x compatibility (previously v8.x → v9.x)

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/compat/src/fixup-rules.js Implements new Proxy-based compatibility layer for context and sourceCode objects, replacing the previous visitor-wrapping approach
packages/compat/tests/fixup-rules.test.js Updates test suite to verify restoration of deprecated methods, replacing legacy schema and method compatibility tests
packages/compat/README.md Updates documentation to reference ESLint v9.x → v10.x compatibility instead of v8.x → v9.x

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Pixel998 Pixel998 changed the title feat!: patch missing context and SourceCode methods for v10 feat: patch missing context and SourceCode methods for v10 Nov 5, 2025
@Pixel998 Pixel998 removed the breaking label Nov 5, 2025
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

The tests will really be checking the new features only when we update ESLint to v10 in this repo, but I verified manually that they are passing and that generally everything works well when the methods/properties this PR patches are removed from ESLint.

Since this is a feature, it needs a second review before merging.

@mdjermanovic mdjermanovic moved this from Implementing to Second Review Needed in Triage Nov 10, 2025
@nzakas nzakas marked this pull request as ready for review November 11, 2025 15:46
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@nzakas nzakas merged commit a40d8c6 into main Nov 11, 2025
25 checks passed
@nzakas nzakas deleted the issue279 branch November 11, 2025 15:47
@github-project-automation github-project-automation bot moved this from Second Review Needed to Complete in Triage Nov 11, 2025
@github-actions github-actions bot mentioned this pull request Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Change Request: Patch removed SourceCode methods for ESLint v10 compatibility

5 participants