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

Update: Add never option to arrow-body-style (fixes #6317) #6318

Merged
merged 4 commits into from Jun 9, 2016

Conversation

ajhyndman
Copy link
Contributor

Arrow functions that return object literals can look very similar to arrow functions with brace bodies. Some syntactic ambiguity can be avoided by disallowing block-style arrow functions in favour of ES5 function expressions.

Outcome

The following patterns are considered problems:

/*eslint arrow-body-style: ["error", "never"]*/
/*eslint-env es6*/

let foo = () => {
    return 0;
};

let foo = (retv, name) => {
    retv[name] = true;
    return retv;
};

The following patterns are not considered problems:

/*eslint arrow-body-style: ["error", "never"]*/
/*eslint-env es6*/

let foo = () => 0;

let foo = () => ({ key: 0 });

@eslintbot
Copy link

Thanks for the pull request, @ajhyndman! I took a look to make sure it's ready for merging and found some changes are needed:

  • Pull requests with code require an issue to be mentioned at the end of the commit summary, such as (fixes #1234). Please update the commit summary with an issue (file a new issue if one doesn't already exist).

Can you please update the pull request to address these?

(More information can be found in our pull request guide.)

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @vitorbal, @gyandeeps and @alberto to be potential reviewers

@jquerybot
Copy link

Thank you for your pull request. It looks like this may be your first contribution to a jQuery Foundation project, if so we need you to sign our Contributor License Agreement (CLA).

📝 Please visit http://contribute.jquery.org/CLA/ to sign.

After you signed, the PR is checked again automatically after a minute. If there's still an issue, please reply here to let us know.


If you've already signed our CLA, it's possible your git author information doesn't match your CLA signature (both your name and email have to match), for more information, check the status of your CLA check.

@eslintbot
Copy link

LGTM

Arrow functions that return object literals can look very similar to arrow functions with brace bodies.  Some syntactic ambiguity can be avoided by disallowing block-style arrow functions in favour of ES5 function expressions.

**Outcome**

The following patterns are considered problems:
```
/*eslint arrow-body-style: ["error", "never"]*/
/*eslint-env es6*/

let foo = () => {
    return 0;
};

let foo = (retv, name) => {
    retv[name] = true;
    return retv;
};
```

The following patterns are not considered problems:
```
/*eslint arrow-body-style: ["error", "never"]*/
/*eslint-env es6*/

let foo = () => 0;

let foo = () => ({ key: 0 });
```
@eslintbot
Copy link

LGTM

@vitorbal vitorbal added the do not merge This pull request should not be merged yet label Jun 3, 2016
@vitorbal
Copy link
Member

vitorbal commented Jun 3, 2016

thanks @ajhyndman! Marking this as "do not merge" just for now as the proposed enhancement hasn't been accepted yet.

@nzakas nzakas removed the do not merge This pull request should not be merged yet label Jun 6, 2016
@nzakas
Copy link
Member

nzakas commented Jun 6, 2016

Issue has been accepted so removing "do not merge"

@nzakas
Copy link
Member

nzakas commented Jun 6, 2016

@ajhyndman thanks for this. In order to be merged, can you please update the rule documentation and write some tests for the new option?

@ajhyndman
Copy link
Contributor Author

Of course, I'll assemble them when I get off work.

@eslintbot
Copy link

LGTM

4 similar comments
@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@ajhyndman
Copy link
Contributor Author

Sorry about the spam.

I tried to keep the documentation fairly consistent with what was already there, but I'm happy to adjust it, if need be. The tests just codify the documentation.

This rule can enforce the use of braces around arrow function body.
Arrow functions have two syntactic forms for their function bodies. They may be defined with a *block* body (denoted by curly braces) `() => { ... }` or with a single expression `() => ...`, whose value is implicitly returned.

This rule may be used to standardize your usage and thus avoid syntactic ambiguity.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe " This rule can enforce or disallow the use of braces around arrow function body." is a more easily understandable way of saying this.

@eslintbot
Copy link

LGTM

@ajhyndman
Copy link
Contributor Author

I think you're right. There was a bit of redundancy, and we lost the explicit description of the mechanics. I've applied your suggestions.

@nzakas
Copy link
Member

nzakas commented Jun 8, 2016

Thanks, LGTM!

The following patterns are not considered problems:

```js
/*eslint arrow-body-style: ["error", "as-needed"]*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option name should be "never" here

@alberto
Copy link
Member

alberto commented Jun 8, 2016

Other than the doc typo, LGTM.

@eslintbot
Copy link

LGTM

@ajhyndman
Copy link
Contributor Author

Whoops, good catch, thanks!

@ilyavolodin
Copy link
Member

LGTM. Thanks

@ilyavolodin ilyavolodin merged commit 6e03c4b into eslint:master Jun 9, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants