fix(linter): change severity of no-sparse-arrays to warnings

This commit is contained in:
Boshen 2024-01-09 14:41:42 +08:00
parent f6047b6531
commit 66e95a5968
No known key found for this signature in database
GPG key ID: 234DA6A7079C6801
2 changed files with 16 additions and 14 deletions

View file

@ -1,7 +1,7 @@
use miette::{miette, LabeledSpan};
use oxc_ast::{ast::ArrayExpressionElement, AstKind};
use oxc_diagnostics::{
miette::{self, Diagnostic},
miette::{self, Diagnostic, Severity},
thiserror::Error,
};
use oxc_macros::declare_oxc_lint;
@ -56,6 +56,7 @@ impl Rule for NoSparseArrays {
if !violations.is_empty() {
if violations.len() < 10 {
ctx.diagnostic(miette!(
severity = Severity::Warning,
labels = violations,
help = "remove the comma or insert `undefined`",
"eslint(no-sparse-arrays): Unexpected comma in middle of array"
@ -71,6 +72,7 @@ impl Rule for NoSparseArrays {
};
ctx.diagnostic(miette!(
severity = Severity::Warning,
labels = vec![span],
help = "remove the comma or insert `undefined`",
"eslint(no-sparse-arrays): {} unexpected commas in middle of array",
@ -96,11 +98,11 @@ fn test() {
"var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 2];",
"var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , hello, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 2];",
"var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , ,
hello, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
hello, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , 2];",
];

View file

@ -2,7 +2,7 @@
source: crates/oxc_linter/src/tester.rs
expression: no_sparse_arrays
---
× eslint(no-sparse-arrays): Unexpected comma in middle of array
eslint(no-sparse-arrays): Unexpected comma in middle of array
╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [,];
· ▲
@ -10,7 +10,7 @@ expression: no_sparse_arrays
╰────
help: remove the comma or insert `undefined`
× eslint(no-sparse-arrays): Unexpected comma in middle of array
eslint(no-sparse-arrays): Unexpected comma in middle of array
╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1,, 2];
· ▲
@ -18,7 +18,7 @@ expression: no_sparse_arrays
╰────
help: remove the comma or insert `undefined`
× eslint(no-sparse-arrays): Unexpected comma in middle of array
eslint(no-sparse-arrays): Unexpected comma in middle of array
╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1,,,, 2];
· ▲▲▲
@ -28,7 +28,7 @@ expression: no_sparse_arrays
╰────
help: remove the comma or insert `undefined`
× eslint(no-sparse-arrays): 30 unexpected commas in middle of array
eslint(no-sparse-arrays): 30 unexpected commas in middle of array
╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2];
· ──────────────────┬──────────────────
@ -36,7 +36,7 @@ expression: no_sparse_arrays
╰────
help: remove the comma or insert `undefined`
× eslint(no-sparse-arrays): 83 unexpected commas in middle of array
eslint(no-sparse-arrays): 83 unexpected commas in middle of array
╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 2];
· ▲
@ -44,7 +44,7 @@ expression: no_sparse_arrays
╰────
help: remove the comma or insert `undefined`
× eslint(no-sparse-arrays): 82 unexpected commas in middle of array
eslint(no-sparse-arrays): 82 unexpected commas in middle of array
╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , hello, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 2];
· ▲
@ -52,12 +52,12 @@ expression: no_sparse_arrays
╰────
help: remove the comma or insert `undefined`
× eslint(no-sparse-arrays): 81 unexpected commas in middle of array
eslint(no-sparse-arrays): 81 unexpected commas in middle of array
╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , ,
· ▲
· ╰── the array starting here
2 │
2 │
╰────
help: remove the comma or insert `undefined`