Socket
Book a DemoInstallSign in
Socket

eslint-plugin-prefer-arrow-functions

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-prefer-arrow-functions

Convert functions to arrow functions

3.6.1
Source
npmnpm
Version published
Weekly downloads
67K
-37.49%
Maintainers
1
Weekly downloads
 
Created
Source

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

Installation

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

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",
      {
        "allowedNames": [],
        "allowNamedFunctions": false,
        "allowObjectProperties": false,
        "classPropertiesAllowed": false,
        "disallowPrototype": false,
        "returnStyle": "unchanged",
        "singleReturnOnly": false
      }
    ]
  }
}

Options

allowedNames

An optional array of function names to ignore. When set, the rule won't report named functions such as function foo() {} whose name is identical to a member of this array.

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.

allowObjectProperties

If set to true, the rule won't report named methods such as

const myObj = {
  hello() {}
}

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.

Badges

Keywords

es6

FAQs

Package last updated on 12 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.