Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 796 Bytes

no-extraneous-function-wrapping.md

File metadata and controls

39 lines (27 loc) · 796 Bytes

Avoid unnecessary function wrapping

This rule disallows declaring a function f that only calls another function g, when:

  • the only argument of f is the last argument of g
  • g is a curried Lodash method

This is disallowed by the rule as f can be removed. See this for further explanation and examples of pointfree style.

Fail

function isNotZero(x) {
  return x !== 0;
}

_.filter(function(x) {
  return isNotZero(x);
}, array);

_.filter((x) => isNotZero(x), array);

function getAtABC(x) {
  return _.get('a.b.c', x);
}

Pass

function isNotZero(x) {
  return x !== 0;
}

_.filter(isNotZero, array);

_.map((x) => add(x, x), array);

const getAtABC = _.get('a.b.c');