close

no-array-from-fill

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-array-from-fill': 'error',
    },
  },
]);

Rule Details

Disallow calling .fill() after Array.from({ length: … }). Prefer the mapping function argument of Array.from() when creating a fixed-length array with generated values.

Examples of incorrect code for this rule:

Array.from({ length: 3 }).fill().map((_, index) => index);
Array.from({ length: 3 }).fill({});

Examples of correct code for this rule:

Array.from({ length: 3 }, (_, index) => index);
Array.from({ length: 3 }, () => ({}));

Using a mapping function also avoids unintentionally sharing one mutable value between every array element.

Original Documentation