Eslint: arrow-body-style function short syntax when returning object.

Created on 9 Apr 2016  路  3Comments  路  Source: eslint/eslint

The thing is, if I remove return and curly brackets I will have syntax error because of function short syntax.

(c: ChoiceType): ChoiceType => {
return { ...c, id: uniqid() };
}

archived due to age needs info triage

Most helpful comment

If you want to return an object you have to enclose it in parens

var foo = () => ({a: 1});

All 3 comments

Hi @idchlife, thanks for the issue. It looks like there's not enough information for us to know how to help you. If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

If it's something else, please just provide as much additional information as possible. Thanks!

If you want to return an object you have to enclose it in parens

var foo = () => ({a: 1});

@alberto this is true. Despite this syntax, is it ok for linter to say that there is no need for a body when using return {}...

I'm sticking to 50/50, because of short functions syntax. Will checking of it and it's return value will change in future, or will it stay the same.

Was this page helpful?
0 / 5 - 0 ratings