unicorn/prefer-array-flat
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-array-flat": "error",
},
},
];Prefer Array#flat() over legacy techniques to flatten arrays.
const foo = array.flatMap(x => x);const foo = array.reduce((a, b) => a.concat(b), []);const foo = [].concat(...array);const foo = array.reduce((a, b) => [...a, ...b], []);const foo = array.flat();Examples from the ESLint documentation.
unicorn/prefer-array-flat
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-array-flat": "error",
},
},
];unicorn/prefer-array-flat
unicorn plugin · pedantic
{
"rules": {
"unicorn/prefer-array-flat": "error"
}
}Biome does not have this rule.
Prefer .find(…) and .findLast(…) over the first or last element from .filter(…).
Prefer Blob#arrayBuffer() over FileReader#readAsArrayBuffer(…) and Blob#text() over FileReader#readAsText(…).
Prefer .addEventListener() and .removeEventListener() over on-functions.
Prefer class field declarations over this assignments in constructors.
Disallow returning/yielding Promise.resolve/reject() in async functions or promise callbacks
Prefer using Element#classList.toggle() to toggle class names.