mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(linter/max-lines): only report codes that exceed the line limit (#2778)
closes: #2775
This commit is contained in:
parent
a2cfc867cb
commit
64e4de7861
2 changed files with 88 additions and 95 deletions
|
|
@ -126,9 +126,19 @@ impl Rule for MaxLines {
|
|||
"File has too many lines ({}). Maximum allowed is {}.",
|
||||
lines_in_file, self.max,
|
||||
));
|
||||
|
||||
let start = ctx
|
||||
.source_text()
|
||||
.lines()
|
||||
.take(self.max)
|
||||
.map(|line| line.chars().count() + 1) // padding 1 each line for '\n'
|
||||
.sum::<usize>();
|
||||
ctx.diagnostic(MaxLinesDiagnostic(
|
||||
error,
|
||||
Span::new(0, u32::try_from(ctx.source_text().len()).unwrap_or(u32::MAX)),
|
||||
Span::new(
|
||||
u32::try_from(start).unwrap_or(u32::MIN),
|
||||
u32::try_from(ctx.source_text().len()).unwrap_or(u32::MAX),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,45 +3,42 @@ source: crates/oxc_linter/src/tester.rs
|
|||
expression: max_lines
|
||||
---
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var xyz;
|
||||
2 │ │ var xyz;
|
||||
3 │ ╰─▶ var xyz;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var xyz;
|
||||
3 │ var xyz;
|
||||
· ────────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ /* a multiline comment
|
||||
2 │ │ that goes to many lines*/
|
||||
3 │ │ var xy;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ that goes to many lines*/
|
||||
3 │ ╭─▶ var xy;
|
||||
4 │ ╰─▶ var xy;
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ //a single line comment
|
||||
2 │ │ var xy;
|
||||
3 │ ╰─▶ var xy;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var xy;
|
||||
3 │ var xy;
|
||||
· ───────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (5). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var x;
|
||||
2 │ │
|
||||
3 │ │
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │
|
||||
3 │ ╭─▶
|
||||
4 │ │
|
||||
5 │ ╰─▶ var y;
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (8). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ //a single line comment
|
||||
2 │ │ var xy;
|
||||
3 │ │
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var xy;
|
||||
3 │ ╭─▶
|
||||
4 │ │ var xy;
|
||||
5 │ │
|
||||
6 │ │ /* a multiline
|
||||
|
|
@ -51,27 +48,25 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var x; // inline comment
|
||||
2 │ │ var y;
|
||||
3 │ ╰─▶ var z;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var y;
|
||||
3 │ var z;
|
||||
· ──────────────────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var x; /* inline comment
|
||||
2 │ │ spanning multiple lines */
|
||||
3 │ │ var y;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ spanning multiple lines */
|
||||
3 │ ╭─▶ var y;
|
||||
4 │ ╰─▶ var z;
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (8). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ //a single line comment
|
||||
2 │ │ var xy;
|
||||
3 │ │
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var xy;
|
||||
3 │ ╭─▶
|
||||
4 │ │ var xy;
|
||||
5 │ │
|
||||
6 │ │ /* a multiline
|
||||
|
|
@ -121,51 +116,49 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (2). Maximum allowed is 1."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ A
|
||||
2 │ ╰─▶
|
||||
╭─[max_lines.tsx:2:1]
|
||||
1 │ A
|
||||
2 │
|
||||
· ─────────────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 1."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ A
|
||||
2 │ │
|
||||
╭─[max_lines.tsx:2:1]
|
||||
1 │ A
|
||||
2 │ ╭─▶
|
||||
3 │ ╰─▶
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │ var x
|
||||
3 │ │ var c;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ ╰─▶ console.log
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a',
|
||||
2 │ │ c,
|
||||
3 │ ╰─▶ x;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ c,
|
||||
3 │ x;
|
||||
· ───────────────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a',
|
||||
2 │ │ c,
|
||||
3 │ │ x;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ c,
|
||||
3 │ ╭─▶ x;
|
||||
4 │ ╰─▶
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (6). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶
|
||||
2 │ │
|
||||
3 │ │ var a = 'a',
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │
|
||||
3 │ ╭─▶ var a = 'a',
|
||||
4 │ │ c,
|
||||
5 │ │ x;
|
||||
6 │ ╰─▶
|
||||
|
|
@ -173,10 +166,9 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (6). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │ var x
|
||||
3 │ │ var c;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ │ console.log
|
||||
5 │ │ // some block
|
||||
6 │ ╰─▶ // comments
|
||||
|
|
@ -184,20 +176,18 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (5). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │ var x
|
||||
3 │ │ var c;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ │ console.log
|
||||
5 │ ╰─▶ /* block comments */
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (6). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │ var x
|
||||
3 │ │ var c;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ │ console.log
|
||||
5 │ │ /* block comments */
|
||||
6 │ ╰─▶
|
||||
|
|
@ -205,10 +195,9 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (7). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │ var x
|
||||
3 │ │ var c;
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ │ console.log
|
||||
5 │ │ /** block
|
||||
6 │ │
|
||||
|
|
@ -217,19 +206,17 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │
|
||||
3 │ │
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │
|
||||
3 │ ╭─▶
|
||||
4 │ ╰─▶ // comment
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (8). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │ var x
|
||||
3 │ │
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶
|
||||
4 │ │
|
||||
5 │ │ var c;
|
||||
6 │ │ console.log
|
||||
|
|
@ -239,10 +226,9 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (8). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │
|
||||
3 │ │
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │
|
||||
3 │ ╭─▶
|
||||
4 │ │ var x
|
||||
5 │ │ var c;
|
||||
6 │ │ console.log
|
||||
|
|
@ -252,10 +238,9 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (6). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ var a = 'a';
|
||||
2 │ │ //
|
||||
3 │ │ var x
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ //
|
||||
3 │ ╭─▶ var x
|
||||
4 │ │ var c;
|
||||
5 │ │ console.log
|
||||
6 │ ╰─▶ //
|
||||
|
|
@ -263,10 +248,9 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (9). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ // hello world
|
||||
2 │ │ /*hello
|
||||
3 │ │ world 2 */
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ /*hello
|
||||
3 │ ╭─▶ world 2 */
|
||||
4 │ │ var a,
|
||||
5 │ │ b
|
||||
6 │ │ // hh
|
||||
|
|
@ -277,10 +261,9 @@ expression: max_lines
|
|||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (11). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶
|
||||
2 │ │ var x = '';
|
||||
3 │ │
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x = '';
|
||||
3 │ ╭─▶
|
||||
4 │ │ // comment
|
||||
5 │ │
|
||||
6 │ │ var b = '',
|
||||
|
|
|
|||
Loading…
Reference in a new issue