# eslint-plugin-prefer-arrow-functions

> Convert functions to arrow functions

Latest version **3.10.2** (published 2026-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-prefer-arrow-functions
pnpm add eslint-plugin-prefer-arrow-functions
yarn add eslint-plugin-prefer-arrow-functions
bun add eslint-plugin-prefer-arrow-functions
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.10.2 |
| Published | 2026-08-09 |
| First published | 2019-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^20.19.0 \|\| ^22.13.0 \|\| >=24.0.0 |
| Dependencies | 2 |
| Unpacked size | 103.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 77 |
| Author | Jamie Mason |
| Maintainers | fold_left |
| Keywords | es6, eslint, eslint-plugin |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions
- Repository: https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions
- Issues: https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions/issues
- npm.io page: https://npm.io/package/eslint-plugin-prefer-arrow-functions

## Dependencies (2)

- [@typescript-eslint/types](https://npm.io/package/@typescript-eslint/types.md) ^8.66.0
- [@typescript-eslint/utils](https://npm.io/package/@typescript-eslint/utils.md) ^8.66.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 3.10.2 (latest) — 2026-08-09
- 3.10.1 — 2026-07-03
- 3.10.0 — 2026-07-03
- 3.9.1 — 2025-09-28
- 3.9.0 — 2025-09-28
- 3.8.1 — 2025-09-14
- 3.8.0 — 2025-09-14
- 3.7.0 — 2025-09-14
- 3.6.2 — 2025-01-13
- 3.6.1 — 2025-01-12
- 3.6.0 — 2025-01-09
- 3.5.0 — 2025-01-09
- 3.4.2 — 2025-01-09
- 3.4.1 — 2024-08-14
- 3.4.0 — 2024-08-13
- … 8 more at https://npm.io/package/eslint-plugin-prefer-arrow-functions/versions

## README

# eslint-plugin-prefer-arrow-functions

> An ESLint Plugin to Lint and auto-fix plain Functions into Arrow Functions, in all cases where conversion would result
> in the same behaviour (Arrow Functions do not support `this`, `arguments`, or `new.target` for example).

## Installation

```bash
npm install --save-dev eslint eslint-plugin-prefer-arrow-functions
```

## Configuration

### Flat

For ESLint 9 and above, use the shared config `all` in `eslint.config.mjs`:

```js
import pluginJs from '@eslint/js';
import preferArrowFunctions from 'eslint-plugin-prefer-arrow-functions';

export default [
  pluginJs.configs.all,
  preferArrowFunctions.configs.all,
];
```

Or configure the rule(s) on your own:

```js
import pluginJs from '@eslint/js';
import preferArrowFunctions from 'eslint-plugin-prefer-arrow-functions';

export default [
  pluginJs.configs.all,
  {
    plugins: {
      'prefer-arrow-functions': preferArrowFunctions
    },
    rules: {
      'prefer-arrow-functions/prefer-arrow-functions': [
        'warn',
        {
          allowedNames: [],
          allowNamedFunctions: false,
          allowObjectProperties: false,
          classPropertiesAllowed: false,
          disallowPrototype: false,
          returnStyle: 'unchanged',
          singleReturnOnly: false,
        },
      ],
    },
  },
];
```

### Legacy

For ESLint 8 (8.57.0 or newer).

Add the plugin to the `plugins` section and the rule to the `rules` section in your `.eslintrc`. The default values for
options are listed in this example.

```json
{
  "plugins": ["prefer-arrow-functions"],
  "rules": {
    "prefer-arrow-functions/prefer-arrow-functions": [
      "warn",
      {
        "allowedNames": [],
        "allowNamedFunctions": false,
        "allowObjectProperties": false,
        "classPropertiesAllowed": false,
        "disallowPrototype": false,
        "returnStyle": "unchanged",
        "singleReturnOnly": false
      }
    ]
  }
}
```

## Options

### `allowedNames`

An optional array of function names to ignore. When set, the rule won't report named functions such as
`function foo() {}` whose name is identical to a member of this array.

For compatibility with [@angular-eslint/require-lifecycle-on-prototype](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/require-lifecycle-on-prototype.md), you can do:

```js
import { ASTUtils } from "@angular-eslint/utils"

// ...
  {
    rules: {
      'prefer-arrow-functions/prefer-arrow-functions': [
        'warn',
        {
          // ...
          allowedNames: [...ASTUtils.ANGULAR_LIFECYCLE_METHODS],
        },
      ],
    },
  },
```

### `allowNamedFunctions`

Controls how named functions are handled:

- When `true`, the rule won't report any named functions such as `function foo() {}`. Anonymous functions such as
  `const foo = function() {}` will still be reported.
- When `"only-expressions"`, the rule will allow named function expressions (like `callback(function namedFn() {})`) but
  will still transform named function declarations (like `function foo() {}`).
- When `false` (default), all functions will be transformed to arrow functions when safe to do so.

### `allowObjectProperties`

If set to true, the rule won't report named methods such as

```js
const myObj = {
  hello() {},
};
```

### `classPropertiesAllowed`

When `true`, functions defined as
[class instance fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Field_declarations)
will be converted to arrow functions when doing so would not alter or break their behaviour.

### `disallowPrototype`

When `true`, functions assigned to a `prototype` will be converted to arrow functions when doing so would not alter or
break their behaviour.

### `returnStyle`

- When `"implicit"`, arrow functions such as `x => { return x; }` will be converted to `x => x`.
- When `"explicit"`, arrow functions such as `x => x` will be converted to `x => { return x; }`.
- When `"unchanged"` or not set, arrow functions will be left as they were.

### `singleReturnOnly`

When `true`, only `function` declarations which _only_ contain a return statement will be converted. Functions
containing block statements will be ignored.

> This option works well in conjunction with ESLint's built-in
> [arrow-body-style](http://eslint.org/docs/rules/arrow-body-style) set to `as-needed`.

## Credits

This project is a fork of <https://github.com/TristonJ/eslint-plugin-prefer-arrow> by
[Triston Jones](https://github.com/TristonJ).

## Badges

- [![support on ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/C0C4PY4P)
- [![NPM version](http://img.shields.io/npm/v/eslint-plugin-prefer-arrow-functions.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions)
- [![NPM downloads](http://img.shields.io/npm/dm/eslint-plugin-prefer-arrow-functions.svg?style=flat-square)](https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions)
- [![Build Status](https://img.shields.io/github/actions/workflow/status/JamieMason/eslint-plugin-prefer-arrow-functions/ci.yaml?branch=main)](https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions/actions)

---
_Source: https://npm.io/package/eslint-plugin-prefer-arrow-functions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
