unicorn/prefer-short-arrow-method
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-short-arrow-method": "error",
},
},
];Prefer arrow function properties over methods with a single return.
const api = {
getUrl() {
return 'https://api.example.com';
},
};const calculator = {
add(a, b) {
return a + b;
},
};const asyncApi = {
async fetchData(url) {
return fetch(url);
},
};const api = {
getUrl: () => 'https://api.example.com',
};const calculator = {
add: (a, b) => a + b,
};const asyncApi = {
fetchData: async (url) => fetch(url),
};Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
unicorn/prefer-short-arrow-method
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-short-arrow-method": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer RegExp.escape() for escaping strings to use in regular expressions.
Prefer Uint8Array#toBase64() and Uint8Array.fromBase64() over legacy base64 conversions and manual postprocessing.
Prefer Uint8Array#toHex() and Uint8Array.fromHex() over manual and Buffer hex conversions.
Prefer JSON imports over reading and parsing JSON files.
Prefer Iterator.concat(…) over temporary spread arrays.