diff --git a/crates/oxc_linter/src/rules/eslint/no_sparse_arrays.rs b/crates/oxc_linter/src/rules/eslint/no_sparse_arrays.rs index 1d2b2a322..45c1361d3 100644 --- a/crates/oxc_linter/src/rules/eslint/no_sparse_arrays.rs +++ b/crates/oxc_linter/src/rules/eslint/no_sparse_arrays.rs @@ -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];", ]; diff --git a/crates/oxc_linter/src/snapshots/no_sparse_arrays.snap b/crates/oxc_linter/src/snapshots/no_sparse_arrays.snap index 0e6160db0..7ec9bceb9 100644 --- a/crates/oxc_linter/src/snapshots/no_sparse_arrays.snap +++ b/crates/oxc_linter/src/snapshots/no_sparse_arrays.snap @@ -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`