File tree Expand file tree Collapse file tree 4 files changed +210
-162
lines changed
tests/specs/correctness/useImportExtensions Expand file tree Collapse file tree 4 files changed +210
-162
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @biomejs/biome " : patch
3+ ---
4+
5+ Resolved an overcorrection in [ ` useImportExtensions ` ] ( https://biomejs.dev/linter/rules/use-import-extensions/ ) when importing explicit index files.
6+
7+ Imports that explicitly reference an index file are now preserved and no longer rewritten to nested index paths.
8+
9+ #### Example
10+
11+ ``` diff
12+ // Before
13+ - import "./sub/index";
14+ + import "./sub/index/index.js";
15+
16+ // After
17+ - import "./sub/index";
18+ + import "./sub/index.js";
19+ ```
Original file line number Diff line number Diff line change @@ -251,8 +251,9 @@ fn get_extensionless_import(
251251 } ;
252252
253253 let is_index_file = resolved_stem. is_some_and ( |stem| stem == "index" ) ;
254+ let import_path_ends_with_index = path. file_name ( ) . is_some_and ( |name| name == "index" ) ;
254255
255- let new_path = if is_index_file {
256+ let new_path = if is_index_file && !import_path_ends_with_index {
256257 let mut path_parts = path. as_str ( ) . split ( '/' ) ;
257258
258259 // Remove trailing slash and useless path segment.
Original file line number Diff line number Diff line change 11import "./sub/foo" ;
22import "./sub/bar/" ;
3+ import "./sub/index" ;
34
45// Guaranteed resolve to 'index.js' file
56import './sub/bar/../'
You can’t perform that action at this time.
0 commit comments