eslint-plugin-curry
provides a curry-detecting replacement of ESLint's standard arrow-parens
rule. It works completely the
same as vanilla arrow-parens
, except it can detect and apply specific rules to currying.
For example, with vanilla arrow-parens
following airbnb style guide:
/* eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }] */
// bad
const fn = (x) => x
const fn = x => {}
const fn = a => b => c => {}
// good
const fn = x => x
const fn = (x) => {}
const fn = a => b => (c) => {}
Currying is not considered a special case. However, with this plugin, it is:
/* eslint curry/arrow-parens: [2, "as-needed", { "requireForBlockBody": true, "curry": "never" }] */
// bad
const fn = (x) => x
const fn = x => {}
const fn = a => b => (c) => {}
// good
const fn = x => x
const fn = (x) => {}
const fn = a => b => c => {}
// Or, vice-versa:
/* eslint curry/arrow-parens: [2, "as-needed", { "requireForBlockBody": true, "curry": "always" }] */
const fn = (a) => (b) => (c) => {}
Install ESLint either locally or globally. Install eslint-plugin-curry.
With Yarn:
$ yarn add -D eslint eslint-plugin-curry
Or, if you prefer npm:
$ npm install --save-dev eslint eslint-plugin-curry
Add a plugins
section and specify eslint-plugin-curry as a plugin.
{
"plugins": [
"curry"
]
}
Enable the rules.
This rule works like vanilla arrow-parens, but provides an additional setting for functions that use currying.
/* eslint curry/arrow-parens: [2, "as-needed", { "requireForBlockBody": true, "curry": "never" }] */
// bad
const fn = (x) => x
const fn = x => {}
const fn = (x) => (y) => (z) => {}
// good
const fn = x => x
const fn = (x) => {}
const fn = x => y => z => {}
/* eslint curry/arrow-parens: [2, "as-needed", { "curry": "always" }] */
// bad
const fn = (x) => x
const fn = (x) => {}
const fn = x => y => z => {}
// good
const fn = x => x
const fn = x => {}
const fn = (x) => (y) => (z) => {}