Skip to content
← Back to rules

unicorn/consistent-empty-array-spread Pedantic

💡 A suggestion is available for this rule.

What it does ​

When spreading a ternary in an array, we can use both [] and '' as fallbacks, but it's better to have consistent types in both branches.

Why is this bad? ​

Having consistent types in both branches makes the code easier to read and understand.

Examples ​

Examples of incorrect code for this rule:

javascript
const array = [a, ...(foo ? [b, c] : "")];

const array = [a, ...(foo ? "bc" : [])];

Examples of correct code for this rule:

javascript
const array = [a, ...(foo ? [b, c] : [])];

const array = [a, ...(foo ? "bc" : "")];

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/consistent-empty-array-spread": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/consistent-empty-array-spread": "error",
  },
});
bash
oxlint --deny unicorn/consistent-empty-array-spread

Version ​

This rule was added in v0.10.1.

References ​