Package Exports
- eslint-plugin-prefer-arrow
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eslint-plugin-prefer-arrow) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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
. Alternatively, with the singleReturnOnly
option, this plugin only reports functions where converting to an arrow function would dramatically simplify the code.
Installation
Install the npm package
# 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
"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 iffunction
is used anytime. Otherwise, the plugin allows usage offunction
if it is a member of an Object's prototype.singleReturnOnly
: If set to true, the plugin will only warn forfunction
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 set toas-needed
.classPropertiesAllowed
: (Only takes effect ifsingleReturnOnly
is enabled) If set to true, the plugin will warn about functions which could be replaced with arrow functions defined as class instance fields. Enable if you're using Babel's transform-class-properties plugin.