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

View file

@ -2,7 +2,7 @@
source: crates/oxc_linter/src/tester.rs source: crates/oxc_linter/src/tester.rs
expression: no_sparse_arrays 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] ╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [,]; 1 │ var a = [,];
· ▲ · ▲
@ -10,7 +10,7 @@ expression: no_sparse_arrays
╰──── ╰────
help: remove the comma or insert `undefined` 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] ╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1,, 2]; 1 │ var a = [ 1,, 2];
· ▲ · ▲
@ -18,7 +18,7 @@ expression: no_sparse_arrays
╰──── ╰────
help: remove the comma or insert `undefined` 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] ╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1,,,, 2]; 1 │ var a = [ 1,,,, 2];
· ▲▲▲ · ▲▲▲
@ -28,7 +28,7 @@ expression: no_sparse_arrays
╰──── ╰────
help: remove the comma or insert `undefined` 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] ╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2]; 1 │ var a = [ 1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 2];
· ──────────────────┬────────────────── · ──────────────────┬──────────────────
@ -36,7 +36,7 @@ expression: no_sparse_arrays
╰──── ╰────
help: remove the comma or insert `undefined` 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] ╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 2]; 1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 2];
· ▲ · ▲
@ -44,7 +44,7 @@ expression: no_sparse_arrays
╰──── ╰────
help: remove the comma or insert `undefined` 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] ╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , hello, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 2]; 1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , hello, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 2];
· ▲ · ▲
@ -52,7 +52,7 @@ expression: no_sparse_arrays
╰──── ╰────
help: remove the comma or insert `undefined` 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] ╭─[no_sparse_arrays.tsx:1:1]
1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , , 1 │ var a = [ 1, , , , , , , , , , , , , , , , , , , , , , , , , ,
· ▲ · ▲