question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Higher order functions and the arrow-parens rule

See original GitHub issue

The arrow-parens rule requiring parentheses for blocks and no parentheses for one-liners takes no account of higher order functions.

I find it downright bizarre that I should be required to write code like the following:

return next => (action) => {
  // etc
};

I don’t know whether this is a config issue or an eslint issue.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
felixsanzcommented, Oct 10, 2016

Here is an example that doesn’t make any sense:

    ${headTags.scripts.map((script) => {
      if (script.src) return `<script src="${script.src}"></script>`
      return `<script>${script.content}</script>`
    }).join('\n')}

    ${headTags.links.map(link => (
      `<link ${Object.entries(link).map(([prop, value]) => (`${prop}="${value}"`)).join(' ')}>`
    )).join('\n')}

Where is the consistency between (script) and link? Looks so bad!

It should be always or never (i’m talking about single argument in function signature)

0reactions
TigerC10commented, Jan 24, 2017

Just now found this issue myself, taking a look at:

    // require parens in arrow function arguments
    // http://eslint.org/docs/rules/arrow-parens
    'arrow-parens': ['error', 'as-needed', {
      requireForBlockBody: true,
    }],

https://github.com/airbnb/javascript/blob/7e865a4e8ab5e26062fcdc9437166c6e1c269599/packages/eslint-config-airbnb-base/rules/es6.js#L25

Yeah, I gotta admit I’m a bit bewildered by requireForBlockBody being true. But I guess I fall into the camp where arrow-parens are always required. Helps me visually associate that arg to the arrow function rather than to the wrapping function. 1 char diff between arrow function and assignment is not sufficient for my tastes.

Thank goodness for overrides. 🙄

Read more comments on GitHub >

github_iconTop Results From Across the Web

arrow-parens - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Higher Order Functions: Reduce() - Medium
A higher order function is a function that takes in a function as an argument or returns a function. With ES6 syntax this...
Read more >
Expected parentheses around arrow function argument ...
Parentheses around the parameter to an arrow function are optional in ES6 when there's ... This is controlled by the arrow-parens option.
Read more >
Understanding Higher-Order Functions in JavaScript
Although it may sound complicated, it isn't. What makes JavaScript suitable for functional programming is that it accepts Higher-Order Functions ...
Read more >
arrow-parens - Rule
Rule: arrow-parens. Requires parentheses around the parameters of arrow function definitions. Rationale. Maintains stylistic consistency with other arrow ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found