Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

akxcv/eslint-plugin-curry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-curry

styled with prettier

What is it?

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) => {}

Installation

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

Configuration

Add a plugins section and specify eslint-plugin-curry as a plugin.

{
  "plugins": [
    "curry"
  ]
}

Enable the rules.

Rules

arrow-parens

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) => {}

About

Extra ESLint rules for currying functions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published