Giter VIP home page Giter VIP logo

jamiemason / eslint-plugin-prefer-arrow-functions Goto Github PK

View Code? Open in Web Editor NEW
41.0 3.0 9.0 352 KB

Auto-fix plain Functions into Arrow Functions, in all cases where conversion would result in the same behaviour

Home Page: https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions

License: MIT License

JavaScript 2.12% TypeScript 97.88%
eslint eslint-rule eslint-plugin arrow-functions javascript nodejs linter linting lint codemod

eslint-plugin-prefer-arrow-functions's Introduction

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).

NPM version NPM downloads Build Status Maintainability

Table of Contents

โ˜๏ธ Installation

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

๐Ÿ“ Playground

Try it yourself at ASTExplorer.net 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.

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

๐Ÿค” Options

allowNamedFunctions

If set to true, the rule won't report named functions such as function foo() {}. Anonymous function such as const foo = function() {} will still be reported.

classPropertiesAllowed

When true, functions defined as class instance fields 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 set to as-needed.

๐Ÿ‘๐Ÿป Credits

This project is a fork of https://github.com/TristonJ/eslint-plugin-prefer-arrow by Triston Jones.

๐Ÿ™‹๐Ÿฝโ€โ™€๏ธ Getting Help

Get help with issues by creating a Bug Report or discuss ideas by opening a Feature Request.

๐Ÿ‘€ Other Projects

If you find my Open Source projects useful, please share them โค๏ธ

  • eslint-formatter-git-log
    ESLint Formatter featuring Git Author, Date, and Hash
  • eslint-plugin-move-files
    Move and rename files while keeping imports up to date
  • ImageOptim-CLI
    Automates ImageOptim, ImageAlpha, and JPEGmini for Mac to make batch optimisation of images part of your automated build process.
  • Jasmine-Matchers
    Write Beautiful Specs with Custom Matchers
  • karma-benchmark
    Run Benchmark.js over multiple Browsers, with CI compatible output
  • self-help
    Interactive Q&A Guides for Web and the Command Line
  • syncpack
    Manage multiple package.json files, such as in Lerna Monorepos and Yarn Workspaces

๐Ÿค“ Author

I'm Jamie Mason from Leeds in England, I began Web Design and Development in 1999 and have been Contracting and offering Consultancy as Fold Left Ltd since 2012. Who I've worked with includes Sky Sports, Sky Bet, Sky Poker, The Premier League, William Hill, Shell, Betfair, and Football Clubs including Leeds United, Spurs, West Ham, Arsenal, and more.

Follow JamieMason on GitHubย ย ย ย ย ย Follow fold_left on Twitter

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.