Skip to content

Commit 525cc0d

Browse files
committed
chore(lint): add test case for #15990
1 parent caad188 commit 525cc0d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crates/oxc_linter/src/rules/eslint/sort_imports.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,14 @@ fn get_number_of_lines_between(left: Span, right: Span, ctx: &LintContext) -> us
465465
return 0;
466466
}
467467
let between_span = Span::new(left.end, right.start);
468-
let count = ctx.source_range(between_span).chars().filter(|c| *c == '\n').count();
468+
let count = ctx.source_range(between_span).lines().count();
469469

470470
if count < 1 {
471471
return 0;
472472
}
473473

474-
// In different lines, need to subtract 2 because the count includes the first and last line.
474+
// In different lines, need to subtract 1, because we need new line 2 time to have 1 line
475+
// between node
475476
count - 1
476477
}
477478

@@ -580,6 +581,13 @@ fn test() {
580581
(
581582
"import b from 'b';
582583
584+
import a from 'a';",
585+
Some(serde_json::json!([{ "allowSeparatedGroups": true }])),
586+
),
587+
// No leading whitespaces - issue #15990
588+
(
589+
"import b from 'b';
590+
583591
import a from 'a';",
584592
Some(serde_json::json!([{ "allowSeparatedGroups": true }])),
585593
),

0 commit comments

Comments
 (0)