oxc-project/oxc · error · OxcDiagnostic

Passing `{arg_str}` as the `end` argument is unnecessary.

Error message

Passing `{arg_str}` as the `end` argument is unnecessary.

What it means

Raised by unicorn/no-unnecessary-slice-end when `Array#slice`'s `end` argument is redundant (e.g. `array.length` or an out-of-bounds value equal to the default). The argument source text is interpolated; the faulting input is the redundant end argument at the labeled span.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_unnecessary_slice_end.rs:17

use std::borrow::Cow;

use oxc_ast::{
    AstKind,
    ast::{Argument, Expression, MemberExpression, StaticMemberExpression},
    match_member_expression,
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{
    AstNode, ast_util::is_method_call, context::LintContext, rule::Rule, utils::is_same_expression,
};

fn no_unnecessary_slice_end_diagnostic(span: Span, arg_str: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Passing `{arg_str}` as the `end` argument is unnecessary."))
        .with_help("Consider omitting the unnecessary end argument.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoUnnecessarySliceEnd;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows unnecessarily passing a second argument to `slice(...)`, for
    /// cases where it would not change the result.
    ///
    /// ### Why is this bad?
    ///
    /// When using `.slice(...)` without a second argument, the second argument
    /// defaults to the object's length. As such, passing the length explicitly
    /// - or using `Infinity` - is unnecessary.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Omit the `end` argument so slicing runs to the end of the array
  2. Pass the intended exclusive index if truncation was actually meant
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_unnecessary_slice_end.rs:17 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/134229e0a82cbda5. Report an issue: GitHub.