Support ESLint v10: use context.filename instead of removed context.getFilename() - #193
Open
takeshi-biz wants to merge 1 commit into
Open
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ESLint v10 removed the deprecated
context.getFilename()(along with other legacyRuleContextmethods).strict-dependencies/index.jscallscontext.getFilename()directly, so the rule throwsTypeError: context.getFilename is not a functionon every lint run under ESLint v10, making the plugin unusable on v10.Fix
Use
context.filename(available since ESLint v8.40) and fall back tocontext.getFilename()for older versions:This keeps full backward compatibility:
context.filename) → falls back tocontext.getFilename()context.filename(getFilename()still works but is deprecated)context.filename(getFilename()removed)Test
context.getFilenameis absent (the ESLint v10 case), i.e. onlycontext.filenameis provided.getFilenamebut notfilename, so the fallback path is still exercised.npm test→ 35 passed.