Skip to content

Support ESLint v10: use context.filename instead of removed context.getFilename() - #193

Open
takeshi-biz wants to merge 1 commit into
knowledge-work:mainfrom
takeshi-biz:fix/eslint-v10-context-filename
Open

Support ESLint v10: use context.filename instead of removed context.getFilename()#193
takeshi-biz wants to merge 1 commit into
knowledge-work:mainfrom
takeshi-biz:fix/eslint-v10-context-filename

Conversation

@takeshi-biz

Copy link
Copy Markdown

Problem

ESLint v10 removed the deprecated context.getFilename() (along with other legacy RuleContext methods).

strict-dependencies/index.js calls context.getFilename() directly, so the rule throws TypeError: context.getFilename is not a function on every lint run under ESLint v10, making the plugin unusable on v10.

Fix

Use context.filename (available since ESLint v8.40) and fall back to context.getFilename() for older versions:

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

This keeps full backward compatibility:

  • ESLint < 8.40 (no context.filename) → falls back to context.getFilename()
  • ESLint 8.40 – 9.x → uses context.filename (getFilename() still works but is deprecated)
  • ESLint 10.x → uses context.filename (getFilename() removed)

Test

  • Added a test verifying the rule works when context.getFilename is absent (the ESLint v10 case), i.e. only context.filename is provided.
  • All existing tests pass unchanged — their mock context provides getFilename but not filename, so the fallback path is still exercised.

npm test → 35 passed.

…etFilename()

ESLint v10 removed the deprecated context.getFilename(). The rule called it directly, throwing TypeError on every lint run under v10. Use context.filename (available since ESLint 8.40) with a fallback to context.getFilename() for older versions. Fully backward compatible (ESLint v8/v9/v10).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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