diff --git a/crates/oxc_linter/src/rules/eslint/sort_imports.rs b/crates/oxc_linter/src/rules/eslint/sort_imports.rs index a127d2059e540..49d93664eebf6 100644 --- a/crates/oxc_linter/src/rules/eslint/sort_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/sort_imports.rs @@ -458,22 +458,22 @@ 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 + // In different lines, need to subtract 1, because we need new line 2 time to have 1 line + // between node + count - 1 } #[test] @@ -584,6 +584,13 @@ fn test() { 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 }])), + ), ( "import a from 'a';