From caad1882b35cb83adf0edc5a9ee227a23b7caeb0 Mon Sep 17 00:00:00 2001 From: Duc Nghiem-Xuan Date: Mon, 24 Nov 2025 07:49:22 +0900 Subject: [PATCH 1/2] fix(linter): fix eslint/sort-imports allowSeparatedGroups not working with single empty line This fix #15990 --- crates/oxc_linter/src/rules/eslint/sort_imports.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/sort_imports.rs b/crates/oxc_linter/src/rules/eslint/sort_imports.rs index a127d2059e540..2fd0070250cbd 100644 --- a/crates/oxc_linter/src/rules/eslint/sort_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/sort_imports.rs @@ -458,22 +458,21 @@ fn get_first_local_member_name<'a>(decl: &ImportDeclaration<'a>) -> Option usize { if left.end >= right.start { return 0; } let between_span = Span::new(left.end, right.start); - let count = ctx.source_range(between_span).lines().count(); + let count = ctx.source_range(between_span).chars().filter(|c| *c == '\n').count(); - // In same line - if count < 2 { + if count < 1 { return 0; } // In different lines, need to subtract 2 because the count includes the first and last line. - count - 2 + count - 1 } #[test] @@ -581,7 +580,7 @@ fn test() { ( "import b from 'b'; - import a from 'a';", +import a from 'a';", Some(serde_json::json!([{ "allowSeparatedGroups": true }])), ), ( From ad331ae7727049fc45dec225d49c030f8111573c Mon Sep 17 00:00:00 2001 From: Duc Nghiem-Xuan Date: Mon, 24 Nov 2025 11:34:02 +0900 Subject: [PATCH 2/2] chore(lint): add test case for #15990 --- crates/oxc_linter/src/rules/eslint/sort_imports.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/eslint/sort_imports.rs b/crates/oxc_linter/src/rules/eslint/sort_imports.rs index 2fd0070250cbd..49d93664eebf6 100644 --- a/crates/oxc_linter/src/rules/eslint/sort_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/sort_imports.rs @@ -471,7 +471,8 @@ fn get_number_of_lines_between(left: Span, right: Span, ctx: &LintContext) -> us return 0; } - // In different lines, need to subtract 2 because the count includes the first and last line. + // In different lines, need to subtract 1, because we need new line 2 time to have 1 line + // between node count - 1 } @@ -580,6 +581,13 @@ fn test() { ( "import b from 'b'; + import a from 'a';", + Some(serde_json::json!([{ "allowSeparatedGroups": true }])), + ), + // No leading whitespaces - issue #15990 + ( + "import b from 'b'; + import a from 'a';", Some(serde_json::json!([{ "allowSeparatedGroups": true }])), ),