# eslint-plugin-prefer-arrow

> Prefer arrow functions in most cases

Latest version **1.2.3** (published 2021-01-26) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2021-01-26 |
| First published | 2017-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 28 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 59 |
| Author | Triston Jones |
| Maintainers | tristonj |
| Keywords | eslint, eslint-plugin, es6 |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-prefer-arrow
- Repository: https://github.com/TristonJ/eslint-plugin-prefer-arrow
- Homepage: https://github.com/TristonJ/eslint-plugin-prefer-arrow#readme
- Issues: https://github.com/TristonJ/eslint-plugin-prefer-arrow/issues
- npm.io page: https://npm.io/package/eslint-plugin-prefer-arrow

## 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
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 1.2.3 (latest) — 2021-01-26
- 1.2.2 — 2020-07-21
- 1.2.1 — 2020-05-01
- 1.2.0 — 2020-04-07
- 1.1.7 — 2019-12-03
- 1.1.6 — 2019-09-04
- 1.1.5 — 2019-02-14
- 1.1.4 — 2019-01-16
- 1.1.3 — 2018-10-02
- 1.1.2 — 2018-05-25
- 1.1.1 — 2017-05-17
- 1.1.0 — 2017-05-16
- 1.0.4 — 2017-02-28
- 1.0.3 — 2017-02-23
- 1.0.2 — 2017-02-23
- … 2 more at https://npm.io/package/eslint-plugin-prefer-arrow/versions

## README

# eslint-plugin-prefer-arrow
ESLint plugin to prefer arrow functions. By default, the plugin allows usage of `function` as a member of an Object's prototype, but this can be changed with the property `disallowPrototype`. Functions referencing `this` will also be allowed. Alternatively, with the `singleReturnOnly` option, this plugin only reports functions where converting to an arrow function would dramatically simplify the code.

Class methods will not produce errors unless the `classPropertiesAllowed` flag is set.

This plugin will automatically fix your code using ESLint's `--fix` option, as long as you use the `singleReturnOnly` option.

# Installation

Install the npm package
```bash
# If eslint is installed globally
npm install -g eslint-plugin-prefer-arrow

# If eslint is installed locally
npm install -D eslint-plugin-prefer-arrow
```

Add the plugin to the `plugins` section and the rule to the `rules` section in your .eslintrc
```js
"plugins": [
  "prefer-arrow"
],
"rules": {
  "prefer-arrow/prefer-arrow-functions": [
    "warn",
    {
      "disallowPrototype": true,
      "singleReturnOnly": false,
      "classPropertiesAllowed": false
    }
  ]
}
```
# Configuration
 * `disallowPrototype`: If set to true, the plugin will warn if `function` is used anytime. Otherwise, the plugin allows usage of `function` if it is a member of an Object's prototype.
 * `singleReturnOnly`: If set to true, the plugin will only warn for `function` declarations which *only* contain a return statement. These often look much better when declared as arrow functions without braces. Works well in conjunction with ESLint's built-in [arrow-body-style](http://eslint.org/docs/rules/arrow-body-style) set to `as-needed`.
 * `classPropertiesAllowed`: If set to true, the plugin will warn about functions which could be replaced with arrow functions defined as [class instance fields](https://github.com/jeffmo/es-class-static-properties-and-fields). Enable if you're using Babel's [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) plugin.
 * `allowStandaloneDeclarations`: If set to true, the plugin will ignore top-level function declarations (the plugin will still warn about "inner" functions, for example, function declarations inside other functions).

# Autofixing

To autofix your code, simply run ESLint with the `--fix` option. Note that this only works when the `singleReturnOnly` option is set to true.
```bash
eslint --fix src
```

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