close

no-unnecessary-array-flat-depth

Added in v0.9.1

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-flat-depth': 'error',
    },
  },
]);

Rule Details

Disallow passing 1 as the depth argument to Array#flat().

The default depth of Array#flat() is already 1, so writing the argument explicitly is redundant.

Examples of incorrect code for this rule:

const nested = [1, [2, 3]];
nested.flat(1);

Examples of correct code for this rule:

const nested = [1, [2, 3]];
nested.flat();

Depths other than the numeric literal 1 are left unchanged:

nested.flat(2);
nested.flat(Infinity);
nested.flat(depth);

Original Documentation