Skip to content

ESLint 10 compatibility: context.getSourceCode() is removed #2378

@aklkv

Description

@aklkv

Summary

eslint-plugin-ember fails with ESLint 10 due to the removed context.getSourceCode() API.

Error

TypeError: Error while loading rule 'ember/avoid-leaking-state-in-ember-objects': context.getSourceCode is not a function
Occurred while linting /path/to/file.gts
    at Object.create (/node_modules/eslint-plugin-ember/lib/rules/avoid-leaking-state-in-ember-objects.js:83:32)

Environment

  • eslint-plugin-ember: 12.7.5
  • eslint: 10.0.0

Details

ESLint 10 removed the deprecated context.getSourceCode() method. Rules should use context.sourceCode property instead.

See ESLint migration guide: https://eslint.org/docs/latest/use/migrate-to-10.0.0

Suggested Fix

Replace all occurrences of context.getSourceCode() with backward-compatible access:

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

// After (works with ESLint 8, 9, and 10)
const sourceCode = context.sourceCode ?? context.getSourceCode();

// Or if dropping ESLint <9 support:
const sourceCode = context.sourceCode;

Affected files likely include any rule using getSourceCode() in lib/rules/.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions