-
-
Notifications
You must be signed in to change notification settings - Fork 55
Description
The import-x/extensions rule fails to check file extensions for Node.js subpath imports.
Current Behavior
When using subpath imports defined in package.json:
{
"imports": {
"#utils/*": "./src/utils/*.js"
}
}The import-x/extensions rule doesn't validate extensions:
import { helper } from '#utils/helper'; // ✓ No error (but should check extension)
import { helper } from '#utils/helper.js'; // Rule doesn't verify this eitherExpected Behavior
The rule should check file extensions for subpath imports the same way it does for regular imports:
// With "import-x/extensions": ["error", "always"]
import { helper } from '#utils/helper'; // ❌ Should error: missing extension
import { helper } from '#utils/helper.js'; // ✓ Should passRoot Cause
The parsePath function treats # as a URL hash fragment, causing the pathname to be extracted incorrectly:
export const parsePath = (path: string): ParsedPath => {
const hashIndex = path.indexOf('#')
const queryIndex = path.indexOf('?')
const hasHash = hashIndex !== -1
const hash = hasHash ? path.slice(hashIndex) : ''
const pathname = hasHash ? path.slice(0, hashIndex) : path
// For '#utils/helper', this results in pathname: '' and hash: '#utils/helper'
}This causes the import-x/extensions rule (and potentially other rules) to skip validation since it doesn't see a valid pathname.
Suggested Fix
The parsePath function should not treat URLs started with the symbol # as hash fragments.
export const parsePath = (path: string): ParsedPath => {
const hashIndex = path.indexOf('#')
const hasHash = hashIndex > 0
// ... rest of the existing logic
}Environment
- Node.js version: v24.11.0
- eslint-plugin-import-x version: v4.16.1 (latest at the moment)
Additional Context
Resolution appears to work correctly, but path parsing for rule validation is broken.
Other rules that depend on parsePath might also be affected.