Skip to content

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
microsoft:mainfrom
cpruijsen:fix/issue-440-2cee7df6
Open

Christopher Pruijsen (cpruijsen) wants to merge 1 commit into
microsoft:mainfrom
cpruijsen:fix/issue-440-2cee7df6

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

Use context.filename ?? context.getFilename() in eslint-plugin/src/index.ts when filename is unavailable. This follows the existing fallbacks for sourceCode and cwd.

The plugin declares support for eslint >=7. ESLint 8.40.0 added the filename property. Before that version, path.resolve(undefined) causes the config warning reported in #440.

Tests in eslint-plugin/src/tests/plugin.test.ts cover 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.

…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

No deployments
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