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