Skip to main content

prefer-arrow-function-property

Require arrow-function properties when this is not required.

Targeted pattern scopeโ€‹

This rule targets object-literal properties implemented with a function expression or method shorthand.

What this rule reportsโ€‹

This rule reports object property functions that do not declare a this parameter and can be represented as arrow-function properties.

Why this rule existsโ€‹

Arrow-function properties make this behavior explicit: they capture lexical this and avoid accidental rebinding through call-site context. For codebases that avoid object-method this semantics, this rule enforces a consistent, low-ambiguity style.

โŒ Incorrectโ€‹

const handlers = {
onClick() {
return "clicked";
},
onHover: function () {
return "hovered";
},
};

โœ… Correctโ€‹

const handlers = {
onClick: () => "clicked",
onHover: () => "hovered",
withThis(this: void) {
return "ok";
},
};

Behavior and migration notesโ€‹

This rule has no options.

When migrating, convert method shorthand and function-expression properties to arrow-function properties where this is not used. If a function intentionally uses method-style this, keep it as a method and annotate this explicitly.

Additional examplesโ€‹

const formatter = {
prefix: "#",
format(this: { prefix: string }, value: number) {
return `${this.prefix}${value}`;
},
};
// โœ… valid: explicit `this` parameter is allowed by this rule

const formatter2 = {
format(value: number) {
return String(value);
},
};
// โŒ reported

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/prefer-arrow-function-property": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your team intentionally prefers method shorthand for object APIs or relies on method-style this semantics.

Package documentationโ€‹

Rule catalog ID: R055

Further readingโ€‹

Adoption resourcesโ€‹

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.