Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-extraneous-function-wrapping option to curry/partially apply a function #7

Open
jfmengels opened this issue Apr 14, 2016 · 0 comments

Comments

@jfmengels
Copy link
Owner

jfmengels commented Apr 14, 2016

Add an option to no-extraneous-function-wrapping to error when a function, wrapping a non-Lodash function, can be made extraneous using curry.

Options

This rule supports the following options:

curry (name TBD...): When set to true, will lint an error even for non-Lodash functions, encouraging the practice of methods like _.curry, _.partial. Default is false. Note that this will probably lead to more false positives, as in some cases:

  • it will not be possible (adding a last function argument to _.flow/_compose)
  • or will need additional safe-guards like _.ary. For instance, array.map(parseInt) will probably cause you unexpected behavior, as parseInt will get called with parseInt(value, index) and parseInt takes two parameters (value and radix). Most Lodash-fp methods such as map therefore only pass one argument to their iteratee.

You can set the option in configuration like this:

"lodash-fp/no-extraneous-function-wrapping": ["error", {"curry": true}]
a.map((y) => foo(x, y))

// -->

// either
var _foo = _.curry(foo)
a.map(_foo(x))

// or
var _foo = _.partial(foo, x)
a.map(_foo)

a.map((x) => foo(x, y))
// -->
var _foo = _.curry(foo)
a.map(_foo(_, x))
// or
var _foo = _.partial(foo, _, y)
a.map(_foo);

Another option "placeholder": true could be given to enhance the normal and the curryed behavior by using a Lodash placeholder for curried functions

a.map((x) => _.find(x, y))
// -->
a.map(_.find(_, y))

// With `curry`
a.map((x) => foo(x, y))
// -->
a.map(_.curry(foo)(_, y))
// or
a.map(_.partial(foo, _, y))
@jfmengels jfmengels changed the title prefer-partial-application rule no-extraneous-function-wrapping option to curry/partially apply a function Apr 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant