Skip to content

Commit

Permalink
feat(linter): promote no-new-array to correctness with better help me…
Browse files Browse the repository at this point in the history
…ssage (#2123)

relates #1735
  • Loading branch information
Boshen authored Jan 22, 2024
1 parent 20a34b5 commit d90db3a
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 115 deletions.
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/rules/unicorn/no_new_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule, AstNode};

#[derive(Debug, Error, Diagnostic)]
#[error("eslint-plugin-unicorn(no-new-array): Do not use `new Array()`.")]
#[diagnostic(severity(warning), help(r#"If the argument is the array's length, consider using `Array.from({{ length: n }})` instead. If the argument is the only element, use `[element]` instead."#))]
#[error("eslint-plugin-unicorn(no-new-array): Do not use `new Array(singleArgument)`.")]
#[diagnostic(severity(warning), help(r#"It's not clear whether the argument is meant to be the length of the array or the only element. If the argument is the array's length, consider using `Array.from({{ length: n }})`. If the argument is the only element, use `[element]`."#))]
struct NoNewArrayDiagnostic(#[label] pub Span);

#[derive(Debug, Default, Clone)]
Expand All @@ -37,7 +37,7 @@ declare_oxc_lint!(
/// const array = [42];
/// ```
NoNewArray,
suspicious
correctness
);

impl Rule for NoNewArray {
Expand Down
Loading

0 comments on commit d90db3a

Please sign in to comment.