Skip to content

Conversation

@patricktree
Copy link

@patricktree patricktree commented Jan 11, 2026

Created by Claude Code and reviewed by @patricktree

Fixes false negative when importing files like ./utils.client where actual file is utils.client.ts.

Problem

path.extname("./utils.client") returns .client, treating it as the extension. When the resolver can't find an exact match, it falls back to the raw path. The rule then sees currentExt === actualExt (both .client) and reports no error—missing that .ts should be required.

Same issue applies to directories with dots (e.g., my-things.client/index.ts).

Fix

When the resolved filePath doesn't exist as a file, search for files matching the full import basename and use the found file's actual extension.

Testing

  • Added fixtures: utils.client.ts, my-things.client/index.ts
  • Added test cases for both scenarios
  • npm run test:mocha tests/lib/rules/file-extension-in-import.js passes

When importing "./utils.client" where the actual file is "utils.client.ts",
path.extname() treats ".client" as an extension. The resolver falls back to
the raw path, causing the rule to think currentExt === actualExt (both ".client")
and report no error.

Fix: when resolved filePath doesn't exist as a file, search for files matching
the full import basename and use the found file's actual extension. Also handle
directory imports where the directory name contains dots (e.g., "my-things.client/index.ts").

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@patricktree patricktree force-pushed the fix-false-negative-because-of-dot-in-filename branch from 6e765ad to 97395e4 Compare January 13, 2026 14:44
@patricktree patricktree marked this pull request as ready for review January 13, 2026 15:12
Copy link

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@aladdin-add aladdin-add merged commit 600f3f2 into eslint-community:master Jan 13, 2026
29 checks passed
@patricktree patricktree deleted the fix-false-negative-because-of-dot-in-filename branch January 13, 2026 17:00
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.

2 participants