biome correctness/useImportExtensions
labelled safe
Analysis Nemotron 3 Super
Flags relative imports missing file extensions.
Fix: Adds the file extension of the resolved target file; if forceJsExtensions is true, uses .js; otherwise uses the actual extension (.ts, .jsx, etc.) based on extensionMappings or filesystem resolution.
10 hazards
- Rewriting `import "./dir"` to `import "./dir.js"` fails if `./dir` is a directory with an index file, changing the resolved module.
- If the import points to a file without an extension (e.g., `import "./data"` where `./data` exists), adding `.js` may point to a non-existent file, causing a runtime error.
- In projects with `extensionMappings` like {"ts": "js"}, rewriting `import "./foo.ts"` to `import "./foo.js"` assumes the bundled output uses .js, but if the file isn't actually emitted as .js, the import breaks.
- When `forceJsExtensions: true`, rewriting `import "./component.jsx"` to `import "./component.js"` may fail if the bundler expects .jsx and does not map .js to JSX parsing.
- The fix may drop inline comments attached to the import statement (e.g., `import "./foo" // init`) because the literal is replaced and comments are not reattached.
- If the import is inside a conditional block (e.g., `if (true) import "./mod"`), the rewritten static import may be hoisted, altering execution timing relative to side effects.
- Dynamic imports like `import(`locale/${lang}`)` are not flagged by this rule, but if mistakenly rewritten due to overbroad matching, it would break interpolation and cause syntax errors.
- In ES modules, changing `import "./lib"` to `import "./lib.js"` may alter how the module is cached if another import refers to the same file via a different path (e.g., symlink), leading to duplicate execution.
- If the resolved file is a .mjs file, the fix may incorrectly suggest .js instead of .mjs, breaking module type expectations in Node.js.
- When the import uses a URL (e.g., `import "./foo?query"`), the fix naively appends .js, corrupting the URL and causing a fetch failure.
Programs
| id | result | title | hazard |
|---|