Skip to content

Latest commit

Β 

History

History
38 lines (29 loc) Β· 993 Bytes

File metadata and controls

38 lines (29 loc) Β· 993 Bytes

Prefer consistent types when spreading a ternary in an array literal

πŸ’ΌπŸš« This rule is enabled in the βœ… recommended config. This rule is disabled in the β˜‘οΈ unopinionated config.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

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.

Examples

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

// ❌
const array = [
	a,
	...(foo ? 'bc' : []),
];

// βœ…
const array = [
	a,
	...(foo ? [b, c] : []),
];

// βœ…
const array = [
	a,
	...(foo ? 'bc' : ''),
];