Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jamiemason/eslint-plugin-prefer-arrow-functions
Auto-fix plain Functions into Arrow Functions, in all cases where conversion would result in the same behaviour
https://github.com/jamiemason/eslint-plugin-prefer-arrow-functions
arrow-functions codemod eslint eslint-plugin eslint-rule javascript lint linter linting nodejs
Last synced: 7 days ago
JSON representation
Auto-fix plain Functions into Arrow Functions, in all cases where conversion would result in the same behaviour
- Host: GitHub
- URL: https://github.com/jamiemason/eslint-plugin-prefer-arrow-functions
- Owner: JamieMason
- License: mit
- Created: 2019-08-04T17:53:29.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-08-14T10:36:27.000Z (3 months ago)
- Last Synced: 2024-10-18T19:35:46.219Z (18 days ago)
- Topics: arrow-functions, codemod, eslint, eslint-plugin, eslint-rule, javascript, lint, linter, linting, nodejs
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions
- Size: 393 KB
- Stars: 50
- Watchers: 3
- Forks: 11
- Open Issues: 12
-
Metadata Files:
- Readme: .github/README_CONTENT.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
## ☁️ Installation
```
npm install --save-dev eslint eslint-plugin-prefer-arrow-functions
```## 🏓 Playground
Try it yourself at
[ASTExplorer.net](https://astexplorer.net/#/gist/7c36fe8c604945df27df210cf79dcc3c/12f01bed4dcf08f32a85f72db0851440b7e45cdd)
by pasting code snippets in the top left panel, the results will appear in the
bottom right panel.## ⚖️ Configuration
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",
{
"classPropertiesAllowed": false,
"disallowPrototype": false,
"returnStyle": "unchanged",
"singleReturnOnly": false
}
]
}
}
```## 🤔 Options
### `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).