mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
parent
ba7dd0250c
commit
c26975ab76
2 changed files with 174 additions and 227 deletions
|
|
@ -5,10 +5,10 @@ use serde_json::Value;
|
|||
|
||||
use crate::{context::LintContext, rule::Rule};
|
||||
|
||||
fn max_lines_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::warn(format!("eslint(max-lines): {x0:?}"))
|
||||
.with_help("Reduce the number of lines in this file")
|
||||
.with_label(span1)
|
||||
fn max_lines_diagnostic(count: usize, max: usize, span: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::warn(format!("eslint(max-lines): File has too many lines ({count})."))
|
||||
.with_help(format!("Maximum allowed is {max}."))
|
||||
.with_label(span)
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
|
|
@ -120,24 +120,7 @@ impl Rule for MaxLines {
|
|||
};
|
||||
|
||||
if lines_in_file.saturating_sub(blank_lines).saturating_sub(comment_lines) > self.max {
|
||||
let error = format!(
|
||||
"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(max_lines_diagnostic(
|
||||
&error,
|
||||
Span::new(
|
||||
u32::try_from(start).unwrap_or(u32::MIN),
|
||||
u32::try_from(ctx.source_text().len()).unwrap_or(u32::MAX),
|
||||
),
|
||||
));
|
||||
ctx.diagnostic(max_lines_diagnostic(lines_in_file, self.max, Span::new(0, 0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,275 +1,239 @@
|
|||
---
|
||||
source: crates/oxc_linter/src/tester.rs
|
||||
---
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
⚠ eslint(max-lines): File has too many lines (3).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var xyz;
|
||||
· ▲
|
||||
2 │ var xyz;
|
||||
3 │ var xyz;
|
||||
· ────────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ that goes to many lines*/
|
||||
3 │ ╭─▶ var xy;
|
||||
4 │ ╰─▶ var xy;
|
||||
⚠ eslint(max-lines): File has too many lines (4).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ /* a multiline comment
|
||||
· ▲
|
||||
2 │ that goes to many lines*/
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
⚠ eslint(max-lines): File has too many lines (3).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ //a single line comment
|
||||
· ▲
|
||||
2 │ var xy;
|
||||
3 │ var xy;
|
||||
· ───────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (5). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │
|
||||
3 │ ╭─▶
|
||||
4 │ │
|
||||
5 │ ╰─▶ var y;
|
||||
⚠ eslint(max-lines): File has too many lines (5).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var x;
|
||||
· ▲
|
||||
2 │
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (8). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var xy;
|
||||
3 │ ╭─▶
|
||||
4 │ │ var xy;
|
||||
5 │ │
|
||||
6 │ │ /* a multiline
|
||||
7 │ │ really really
|
||||
8 │ ╰─▶ long comment*/
|
||||
⚠ eslint(max-lines): File has too many lines (8).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ //a single line comment
|
||||
· ▲
|
||||
2 │ var xy;
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
⚠ eslint(max-lines): File has too many lines (3).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var x; // inline comment
|
||||
· ▲
|
||||
2 │ var y;
|
||||
3 │ var z;
|
||||
· ──────────────────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ spanning multiple lines */
|
||||
3 │ ╭─▶ var y;
|
||||
4 │ ╰─▶ var z;
|
||||
⚠ eslint(max-lines): File has too many lines (4).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var x; /* inline comment
|
||||
· ▲
|
||||
2 │ spanning multiple lines */
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (8). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var xy;
|
||||
3 │ ╭─▶
|
||||
4 │ │ var xy;
|
||||
5 │ │
|
||||
6 │ │ /* a multiline
|
||||
7 │ │ really really
|
||||
8 │ ╰─▶ long comment*/
|
||||
⚠ eslint(max-lines): File has too many lines (8).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ //a single line comment
|
||||
· ▲
|
||||
2 │ var xy;
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (1). Maximum allowed is 0."
|
||||
⚠ eslint(max-lines): File has too many lines (1).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 0.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (1). Maximum allowed is 0."
|
||||
⚠ eslint(max-lines): File has too many lines (1).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │
|
||||
· ─
|
||||
· ▲
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 0.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (2). Maximum allowed is 0."
|
||||
⚠ eslint(max-lines): File has too many lines (2).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶
|
||||
2 │ ╰─▶
|
||||
1 │
|
||||
· ▲
|
||||
2 │
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 0.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (1). Maximum allowed is 0."
|
||||
⚠ eslint(max-lines): File has too many lines (1).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ A
|
||||
· ─
|
||||
· ▲
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 0.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (2). Maximum allowed is 0."
|
||||
⚠ eslint(max-lines): File has too many lines (2).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ A
|
||||
2 │ ╰─▶
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (2). Maximum allowed is 0."
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ ╭─▶ A
|
||||
2 │ ╰─▶
|
||||
╰────
|
||||
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:2:1]
|
||||
1 │ A
|
||||
· ▲
|
||||
2 │
|
||||
╰────
|
||||
help: Maximum allowed is 0.
|
||||
|
||||
⚠ eslint(max-lines): File has too many lines (2).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ A
|
||||
· ▲
|
||||
2 │
|
||||
· ─────────────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 0.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 1."
|
||||
╭─[max_lines.tsx:2:1]
|
||||
1 │ A
|
||||
2 │ ╭─▶
|
||||
3 │ ╰─▶
|
||||
⚠ eslint(max-lines): File has too many lines (2).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ A
|
||||
· ▲
|
||||
2 │
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 1.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ ╰─▶ console.log
|
||||
⚠ eslint(max-lines): File has too many lines (3).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ A
|
||||
· ▲
|
||||
2 │
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 1.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (3). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
⚠ eslint(max-lines): File has too many lines (4).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │ var x
|
||||
╰────
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): File has too many lines (3).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a',
|
||||
· ▲
|
||||
2 │ c,
|
||||
3 │ x;
|
||||
· ───────────────
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ c,
|
||||
3 │ ╭─▶ x;
|
||||
4 │ ╰─▶
|
||||
⚠ eslint(max-lines): File has too many lines (4).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a',
|
||||
· ▲
|
||||
2 │ c,
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (6). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │
|
||||
3 │ ╭─▶ var a = 'a',
|
||||
4 │ │ c,
|
||||
5 │ │ x;
|
||||
6 │ ╰─▶
|
||||
⚠ eslint(max-lines): File has too many lines (6).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │
|
||||
· ▲
|
||||
2 │
|
||||
3 │ var a = 'a',
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (6). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ │ console.log
|
||||
5 │ │ // some block
|
||||
6 │ ╰─▶ // comments
|
||||
⚠ eslint(max-lines): File has too many lines (6).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │ var x
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (5). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ │ console.log
|
||||
5 │ ╰─▶ /* block comments */
|
||||
⚠ eslint(max-lines): File has too many lines (5).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │ var x
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (6). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ │ console.log
|
||||
5 │ │ /* block comments */
|
||||
6 │ ╰─▶
|
||||
⚠ eslint(max-lines): File has too many lines (6).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │ var x
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (7). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶ var c;
|
||||
4 │ │ console.log
|
||||
5 │ │ /** block
|
||||
6 │ │
|
||||
7 │ ╰─▶ comments */
|
||||
⚠ eslint(max-lines): File has too many lines (7).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │ var x
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (4). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │
|
||||
3 │ ╭─▶
|
||||
4 │ ╰─▶ // comment
|
||||
⚠ eslint(max-lines): File has too many lines (4).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (8). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x
|
||||
3 │ ╭─▶
|
||||
4 │ │
|
||||
5 │ │ var c;
|
||||
6 │ │ console.log
|
||||
7 │ │
|
||||
8 │ ╰─▶
|
||||
⚠ eslint(max-lines): File has too many lines (8).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │ var x
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (8). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │
|
||||
3 │ ╭─▶
|
||||
4 │ │ var x
|
||||
5 │ │ var c;
|
||||
6 │ │ console.log
|
||||
7 │ │
|
||||
8 │ ╰─▶
|
||||
⚠ eslint(max-lines): File has too many lines (8).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (6). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ //
|
||||
3 │ ╭─▶ var x
|
||||
4 │ │ var c;
|
||||
5 │ │ console.log
|
||||
6 │ ╰─▶ //
|
||||
⚠ eslint(max-lines): File has too many lines (6).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ var a = 'a';
|
||||
· ▲
|
||||
2 │ //
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (9). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ /*hello
|
||||
3 │ ╭─▶ world 2 */
|
||||
4 │ │ var a,
|
||||
5 │ │ b
|
||||
6 │ │ // hh
|
||||
7 │ │ c,
|
||||
8 │ │ e,
|
||||
9 │ ╰─▶ f;
|
||||
⚠ eslint(max-lines): File has too many lines (9).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │ // hello world
|
||||
· ▲
|
||||
2 │ /*hello
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
help: Maximum allowed is 2.
|
||||
|
||||
⚠ eslint(max-lines): "File has too many lines (11). Maximum allowed is 2."
|
||||
╭─[max_lines.tsx:3:1]
|
||||
2 │ var x = '';
|
||||
3 │ ╭─▶
|
||||
4 │ │ // comment
|
||||
5 │ │
|
||||
6 │ │ var b = '',
|
||||
7 │ │ c,
|
||||
8 │ │ d,
|
||||
9 │ │ e
|
||||
10 │ │
|
||||
11 │ ╰─▶ // comment
|
||||
╰────
|
||||
help: Reduce the number of lines in this file
|
||||
⚠ eslint(max-lines): File has too many lines (11).
|
||||
╭─[max_lines.tsx:1:1]
|
||||
1 │
|
||||
· ▲
|
||||
2 │ var x = '';
|
||||
3 │
|
||||
╰────
|
||||
help: Maximum allowed is 2.
|
||||
|
|
|
|||
Loading…
Reference in a new issue