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.

arrow-body-style: [2, "as-needed"] should ignore function bodies that return another block/function

See original GitHub issue

Granted the below example could be achieved a number of different ways to produce the same results, it’s a use case that I think others might find useful if handled in the way I’m expecting.

The following code will fail ESLint v1.9.0 with arrow-body-style: [2, "as-needed"]:

function foo() {
  return (bar, baz) => { // Unexpected block statement surrounding arrow body. (arrow-body-style)
    return qux => {
      console.log(bar);
      console.log(baz);
      console.log(qux);
    };
  };
}

foo()("bar", "baz")("qux");

I expect the above (contrived currying example) to pass since, as far as I know, a block is required here.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

15reactions
bartekuscommented, Jan 28, 2016

I’ll second @mattkrick on that, and provide practical example in form of Login.js component:

import React, { PropTypes } from 'react';

const Login = (props) => {
  return <a onClick={props.onClick}>Login</a>;
};

Login.propTypes = {
  onClick: PropTypes.func.isRequired,
};

export default Login;

There is definitely need for such pattern and that need will only increase as we further push the envelope of possibilities that react&redux for example allow.

Please reconsider you position on this.

6reactions
mysticateacommented, Apr 1, 2016

@elgubenis It’s arrow-body-style’s warning. The arrow functions of your code have only a return statement in the body, so you can rewrite them with () => foo style.

Read more comments on GitHub >

github_iconTop Results From Across the Web

arrow-body-style: [2, "as-needed"] should ignore function ...
arrow-body-style : [2, "as-needed"] should ignore function bodies that return another block/function.
Read more >
arrow-body-style - ESLint - Pluggable JavaScript Linter
The rule takes one or two options. The first is a string, which can be: "always" enforces braces around the function body; "as-needed"...
Read more >
Unexpected block statement surrounding arrow body
This said, if arrow-body-style option is set to true, OP is correct. An other example would be something like this : return this.state.greetings.map((name) ......
Read more >
@getify/eslint-plugin-proper-arrows - npm
"object-return" : forbids => arrow functions from returning objects in the concise-expression-body form, such as x => ({ x }) .
Read more >
arrow-body-style - ESLint Config
This rule can enforce or disallow the use of braces around arrow function body. What ESLint should do when it catches the rule...
Read more >

github_iconTop Related Medium Post

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