close

no-unnecessary-array-splice-count

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-unnecessary-array-splice-count': 'error',
    },
  },
]);

Rule Details

Remove a redundant .length, Infinity, or Number.POSITIVE_INFINITY count from a two-argument splice or toSpliced call.

Calls with additional insertion arguments are left unchanged. Receivers known not to be arrays are excluded; the receiver classification also accepts typed arrays, matching upstream.

Examples of incorrect code:

array.splice(1, array.length);

Examples of correct code:

array.splice(1);

Options

This rule has no options. It is enabled at error severity in unicornPlugin.configs.recommended.

Differences from upstream

Locally shadowed, disabled, or previously reassigned Infinity and Number globals are not assumed to be built-ins. For .length rewrites, known getter-backed receiver paths or a first argument that can change the receiver are skipped. In checker-less source-only runs, member-chain receivers are also left unchanged because the rule cannot prove that their properties are getter-free. These guards avoid semantics-changing autofixes that Unicorn v75.0.0 can still offer.

Original Documentation