Skip to content

Commit

Permalink
fix(linter): fix line calculation for eslint/max-lines in diagnosti…
Browse files Browse the repository at this point in the history
…cs (#7962)

closes #7961
  • Loading branch information
pumano authored Dec 17, 2024
1 parent 1314c97 commit ec2128e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
6 changes: 5 additions & 1 deletion crates/oxc_linter/src/rules/eslint/max_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ impl Rule for MaxLines {
if lines_in_file.saturating_sub(blank_lines).saturating_sub(comment_lines) > self.max {
// Point to end of the file for `eslint-disable max-lines` to work.
let end = ctx.source_text().len().saturating_sub(1) as u32;
ctx.diagnostic(max_lines_diagnostic(lines_in_file, self.max, Span::new(end, end)));
ctx.diagnostic(max_lines_diagnostic(
lines_in_file.saturating_sub(blank_lines).saturating_sub(comment_lines),
self.max,
Span::new(end, end),
));
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions crates/oxc_linter/src/snapshots/eslint_max_lines.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/oxc_linter/src/tester.rs
snapshot_kind: text
---
eslint(max-lines): File has too many lines (3).
╭─[max_lines.tsx:3:8]
Expand Down Expand Up @@ -34,7 +33,7 @@ snapshot_kind: text
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (8).
eslint(max-lines): File has too many lines (4).
╭─[max_lines.tsx:8:18]
7really really
8long comment*/
Expand All @@ -50,15 +49,15 @@ snapshot_kind: text
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (4).
eslint(max-lines): File has too many lines (3).
╭─[max_lines.tsx:4:9]
3var y;
4var z;
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (8).
eslint(max-lines): File has too many lines (6).
╭─[max_lines.tsx:8:18]
7really really
8long comment*/
Expand Down Expand Up @@ -149,87 +148,87 @@ snapshot_kind: text
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (6).
eslint(max-lines): File has too many lines (3).
╭─[max_lines.tsx:6:3]
5x;
6
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (6).
eslint(max-lines): File has too many lines (4).
╭─[max_lines.tsx:6:14]
5// some block
6// comments
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (5).
eslint(max-lines): File has too many lines (4).
╭─[max_lines.tsx:5:23]
4console.log
5/* block comments */
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (6).
eslint(max-lines): File has too many lines (5).
╭─[max_lines.tsx:6:3]
5/* block comments */
6
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (7).
eslint(max-lines): File has too many lines (4).
╭─[max_lines.tsx:7:15]
6
7comments */
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (4).
eslint(max-lines): File has too many lines (3).
╭─[max_lines.tsx:4:13]
3
4// comment
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (8).
eslint(max-lines): File has too many lines (4).
╭─[max_lines.tsx:8:3]
7
8
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (8).
eslint(max-lines): File has too many lines (4).
╭─[max_lines.tsx:8:3]
7
8
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (6).
eslint(max-lines): File has too many lines (4).
╭─[max_lines.tsx:6:5]
5console.log
6//
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (9).
eslint(max-lines): File has too many lines (5).
╭─[max_lines.tsx:9:5]
8e,
9f;
· ▲
╰────
help: Maximum allowed is 2.

eslint(max-lines): File has too many lines (11).
eslint(max-lines): File has too many lines (5).
╭─[max_lines.tsx:11:13]
10
11// comment
Expand Down

0 comments on commit ec2128e

Please sign in to comment.