Skip to content

fix: add ESLint 10 compatibility by replacing deprecated context.getSourceCode()#2379

Open
aklkv wants to merge 8 commits intoember-cli:masterfrom
aklkv:fix/eslint-10-compat
Open

fix: add ESLint 10 compatibility by replacing deprecated context.getSourceCode()#2379
aklkv wants to merge 8 commits intoember-cli:masterfrom
aklkv:fix/eslint-10-compat

Conversation

@aklkv
Copy link

@aklkv aklkv commented Feb 8, 2026

Summary

Adds ESLint 10 compatibility by replacing the deprecated context.getSourceCode() API with the backward-compatible pattern context.sourceCode ?? context.getSourceCode().

Fixes #2378

Changes

  • Updated 60 occurrences of context.getSourceCode() across 35 files to use the backward-compatible pattern
  • Added CI job to test against ESLint 8, 9, and 10

Details

ESLint 10 removed the deprecated context.getSourceCode() method. The new pattern works with ESLint 8, 9, and 10:

// Before
const sourceCode = context.getSourceCode();

// After
const sourceCode = context.sourceCode ?? context.getSourceCode();

@NullVoxPopuli
Copy link
Contributor

The eslint matrix failed. Tyty for doing this!

@aklkv
Copy link
Author

aklkv commented Feb 8, 2026

I will circle back to it once typescript-eslint/typescript-eslint#11952 is resolved as it doesn't even seem to be feasible to upgrade just yet

@saracope
Copy link

saracope commented Mar 2, 2026

@aklkv This one is blocking me to. Is it able to move forward?

@aklkv
Copy link
Author

aklkv commented Mar 2, 2026

@saracope I will check situation upstream

@aklkv aklkv force-pushed the fix/eslint-10-compat branch from 0343d31 to aebd4f2 Compare March 3, 2026 09:21
@aklkv aklkv force-pushed the fix/eslint-10-compat branch from aebd4f2 to 5fad65a Compare March 3, 2026 09:27
aklkv added 2 commits March 3, 2026 13:01
- Update context.getFilename() to context.filename ?? context.getFilename() across 18 rule files and lib/utils/ember.js
- Add error property normalization in eslint-compat.js for ESLint 10's stricter test assertions
- Add isESLint10OrLater detection for version-specific handling
@aklkv
Copy link
Author

aklkv commented Mar 3, 2026

ESLint 10 Compatibility Update

Summary

Added ESLint 10 compatibility layer to the test infrastructure and updated rules to handle API changes.

Changes Made

  1. Updated 18 rule files to use context.filename ?? context.getFilename() pattern (ESLint 10 removed context.getFilename())
  2. Enhanced tests/helpers/eslint-compat.js with:
    • ESLint 10 detection (isESLint10OrLater)
    • Error property normalization (ESLint 10 only allows specific error properties)
    • Valid test case output property stripping (disallowed in ESLint 10)

Test Results

ESLint Version Status Tests
ESLint 8 ✅ Pass 3868/3868
ESLint 9 ✅ Pass 3868/3868
ESLint 10 ⚠️ Blocked 1846/3868

ESLint 10 Blocker

The remaining ESLint 10 failures are caused by @babel/eslint-parser@7 using scopeManager.addGlobals() which was removed in ESLint 10. This is an upstream dependency issue.

With @babel/[email protected]: 3808/3841 tests pass (33 failures are autofix whitespace differences, not rule logic issues).

However, Babel 8 requires ESLint ≥9 as a peer dependency, so we can't use it without dropping ESLint 8 support.

Related Babel Issues/PRs

Issue Status Notes
#17791 - babel/eslint parser failing with ESLint 10 Closed Closed 2 weeks ago
#17804 - @babel/eslint-parser incompatible with ESLint 10 Duplicate Marked as duplicate, closed 2 weeks ago
#17821 - [@babel/[email protected]] Broken Types Open Type issues with Babel 8 rc2
#17819 - Bump @eslint/js to 10.0.1 Merged ESLint 10 support merged 2 weeks ago

Next Steps

  • Wait for @babel/eslint-parser stable Babel 8 release (ESLint 10 support has been merged)
  • Alternatively, drop ESLint 8 support and upgrade to Babel 8 rc2 now

@NullVoxPopuli thoughts?

@NullVoxPopuli
Copy link
Contributor

Wait for @babel/eslint-parser stable Babel 8 release (ESLint 10 support has been merged)

we can widen the range on @babel/eslint-parser and test against both supportetd and upcoming.

as in -- when testing eslint 10, we should also use @babel/eslint-parser 8

# Update .babelrc for Babel 8
echo '{"plugins": ["@babel/plugin-transform-class-properties", ["@babel/plugin-proposal-decorators", {"version": "2023-11"}]]}' > .babelrc
# Update .babelrc for Babel 8 with legacy decorators
echo '{"plugins": [["@babel/plugin-proposal-decorators", {"version": "legacy"}], "@babel/plugin-transform-class-properties"]}' > .babelrc
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it better to specify decorator-transforms here?

these babel plugins are generally considered bad for the legacy transform 🤔

Copy link
Author

Choose a reason for hiding this comment

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

updated

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESLint 10 compatibility: context.getSourceCode() is removed

3 participants