Repository navigation
fix(eslint-plugin-tsdoc): fall back to context.getFilename() when context.filename is unavailable - #499
Open
Christopher Pruijsen (cpruijsen) wants to merge 1 commit into
Conversation
…text.filename is unavailable ESLint only added the context.filename property in 8.40.0; on older versions it is undefined, so ConfigCache.getForSourceFile() called path.resolve(undefined) and the rule reported an "error-loading-config-file" warning on every file. Use the same property ?? method fallback already applied to context.sourceCode and context.cwd so the rule works on every ESLint version in the peer dependency range (eslint >=7). Add regression tests covering a method-only (ESLint 7 style) rule context and a property-only rule context.
This branch has not been deployed
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.
Use
context.filename ?? context.getFilename()ineslint-plugin/src/index.tswhenfilenameis unavailable. This follows the existing fallbacks forsourceCodeandcwd.The plugin declares support for
eslint >=7. ESLint 8.40.0 added thefilenameproperty. Before that version,path.resolve(undefined)causes the config warning reported in #440.Tests in
eslint-plugin/src/tests/plugin.test.tscover valid and malformed comments with a context that exposes only methods. A third test covers a context that exposes only properties.Both method-context tests fail without the fix and pass with it.