Skip to content

Commit

Permalink
fix(linter): improve the span message for no-accumulating-spread
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 12, 2023
1 parent ea293c4 commit 117d95f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 75 deletions.
17 changes: 4 additions & 13 deletions crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,13 @@ use crate::{
enum NoAccumulatingSpreadDiagnostic {
#[error("oxc(no-accumulating-spread): Do not spread accumulators in Array.prototype.reduce()")]
#[diagnostic(severity(warning), help("It looks like you're spreading an `Array`. Consider using the `Array.push` or `Array.concat` methods to mutate the accumulator instead.\nUsing spreads within accumulators leads to `O(n^2)` time complexity."))]
LikelyArray(
#[label("The accumulator is spread here.")] Span,
#[label("From a reduce call here.")] Span,
),
LikelyArray(#[label("From this spread")] Span, #[label("For this reduce")] Span),
#[error("oxc(no-accumulating-spread): Do not spread accumulators in Array.prototype.reduce()")]
#[diagnostic(severity(warning), help("It looks like you're spreading an `Object`. Consider using the `Object.assign` or assignment operators to mutate the accumulator instead.\nUsing spreads within accumulators leads to `O(n^2)` time complexity."))]
LikelyObject(
#[label("The accumulator is spread here.")] Span,
#[label("From a reduce call here.")] Span,
),
LikelyObject(#[label("From this spread")] Span, #[label("For this reduce")] Span),
#[error("oxc(no-accumulating-spread): Do not spread accumulators in Array.prototype.reduce()")]
#[diagnostic(severity(warning), help("Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.\nUsing spreads within accumulators leads to `O(n^2)` time complexity."))]
Unknown(
#[label("The accumulator is spread here.")] Span,
#[label("From a reduce call here.")] Span,
),
Unknown(#[label("From this spread")] Span, #[label("For this reduce")] Span),
}

#[derive(Debug, Default, Clone)]
Expand All @@ -62,7 +53,7 @@ declare_oxc_lint!(
/// function fn (x) {
/// // ...
/// }
///
///
/// arr.reduce((acc, x) => acc.push(fn(x)), [])
/// Object.keys(obj).reduce((acc, el) => {
/// acc[el] = fn(el)
Expand Down
Loading

0 comments on commit 117d95f

Please sign in to comment.