Skip to content

fix: support ESLint 10 by using context.filename with getFilename() fallback - #195

Closed
watarukino wants to merge 1 commit into
knowledge-work:mainfrom
watarukino:fix/eslint10-context-filename
Closed

fix: support ESLint 10 by using context.filename with getFilename() fallback#195
watarukino wants to merge 1 commit into
knowledge-work:mainfrom
watarukino:fix/eslint10-context-filename

Conversation

@watarukino

Copy link
Copy Markdown

Problem

ESLint 10 removed the long-deprecated context.getFilename() method. As a result, strict-dependencies crashes at rule execution time on ESLint 10:

TypeError: context.getFilename is not a function
Occurred while linting <file>
Rule: "strictDependencies/strict-dependencies"
    at checkImport (.../strict-dependencies/index.js:70:36)

Fix

Use context.filename (available since ESLint 8.40) when present, falling back to context.getFilename() for older ESLint versions:

const fileFullPath = context.filename ?? context.getFilename()

This is the only usage of a removed ESLint 10 context API in the plugin (checked against getFilename / getSourceCode / getScope / getAncestors / getPhysicalFilename / getCwd / parserOptions), so this one-line change restores ESLint 10 compatibility.

Testing

  • yarn test: 34/34 passed
  • Verified on a large monorepo (ESLint 10.7.0): the rule executes and reports violations correctly with this patch applied (we currently ship it via pnpm patch and would love to drop the patch once this lands 🙏)

…allback

ESLint 10 removed the deprecated context.getFilename() method, so the rule
crashes at execution time on ESLint 10:

  TypeError: context.getFilename is not a function

context.filename has been available since ESLint 8.40. Use it when present
and fall back to context.getFilename() to keep compatibility with older
ESLint versions.
@watarukino watarukino closed this Jul 17, 2026
@watarukino
watarukino deleted the fix/eslint10-context-filename branch July 17, 2026 05:38
@watarukino

Copy link
Copy Markdown
Author

duplicate #193

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.

1 participant