Giter VIP home page Giter VIP logo

eslint-plugin-prefer-arrow's Introduction

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.

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

# 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 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 set to as-needed.
  • classPropertiesAllowed: (Only takes effect if singleReturnOnly 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.

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.

eslint --fix src

eslint-plugin-prefer-arrow's People

Contributors

keithkml avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.