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

[arrow-parens] Add a "when-brace" option #6557

Closed
nfroidure opened this issue Jun 29, 2016 · 17 comments
Closed

[arrow-parens] Add a "when-brace" option #6557

nfroidure opened this issue Jun 29, 2016 · 17 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@nfroidure
Copy link
Contributor

nfroidure commented Jun 29, 2016

Our team would like to adopt the AirBnb best practice for arrow functions parens but it appears the current options of this rule doesn't fit it. Since we want to rely on automated coding style rules only and found out it would be useful for others too, here is the PR that fulfill it.

See https://github.com/airbnb/javascript#arrows--one-arg-parens
Discussion: SimpliField/eslint-config-simplifield#14

  • The version of ESLint you are using

2.11.1
https://github.com/SimpliField/eslint-config-simplifield/blob/master/package.json#L20

  • The rule you want to change

'arrow-parens'

  • The code you want to be flagged as incorrect
a => { a } // (1)
(a) => a // (2)
  • What happens when the rule is applied to the code without your change

with 'as-needed' (1) is valid

with 'always' (2) is valid

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jun 29, 2016
nfroidure added a commit to nfroidure/eslint that referenced this issue Jun 29, 2016
…6557)

The when-brace option allows to require parens for arrow functions whose body is
 wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```

Otherwise, its behavior remains identical then with the as-needed option.
@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jun 29, 2016
@platinumazure
Copy link
Member

In order to facilitate acceptance of this issue and pull request, could you please edit your original post to answer the questions raised in the Proposing a Rule Change documentation? Thanks!

@nfroidure
Copy link
Contributor Author

@platinumazure done, missed that part.

@ilyavolodin
Copy link
Member

Since this is part of AirBnB styleguide, I think we should consider adding an option for this. I don't like proposed name, however. Don't really have any ideas on how to name it though. I'll 👍 this

@nfroidure
Copy link
Contributor Author

Agree on the naming, not convinced by it too but nothing better came to me ;).

@ilyavolodin
Copy link
Member

ilyavolodin commented Jul 15, 2016

@eslint/eslint-team We need some more +1s here. And suggestion for option name.

@kaicataldo
Copy link
Member

👍

1 similar comment
@mikesherov
Copy link
Contributor

👍

@IanVS
Copy link
Member

IanVS commented Jul 18, 2016

How about breaking this up a bit, and adding an option object with keys like one-arg and with-braces? The values for these could be always, or as-needed. I don't love this and I'd prefer to make them booleans, but I'm not sure how to do that in a way that makes sense. Hopefully this comment might spark a better idea.

The upshot would be making this a bit more flexible and still accommodating the AirBnB style mentioned by the OP. ({'one-arg': 'as-needed', 'with-braces': 'always'})

@nzakas
Copy link
Member

nzakas commented Jul 18, 2016

Do we have a champion for this?

I'd suggest we look at a configuration like:

arrow-parens: [ "error", "as-needed", {
    requireForBlockBody: true
}]

(Generally I think "block" is a more appropriate description, but could also be requireForBracedBody.)

@IanVS
Copy link
Member

IanVS commented Jul 18, 2016

@nzakas, I think we would also need requireForMultipleArguments, to match AirBnB style, but I like that strategy.

@nzakas
Copy link
Member

nzakas commented Jul 18, 2016

@IanVS hmmm, I'm not sure I understand. You can't have multiple parameters for an arrow function without parentheses (it's a syntax error). Can you explain a bit more?

@IanVS
Copy link
Member

IanVS commented Jul 18, 2016

Doh, of course. I was just reading the styleguide way too literally and trying to invert it without thinking about it:

If your function takes a single argument and doesn’t use braces, omit the parentheses.

@kaicataldo
Copy link
Member

I can champion this!

@alberto alberto added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jul 18, 2016
@alberto
Copy link
Member

alberto commented Jul 18, 2016

👍 to requireForBlockBody

@nzakas
Copy link
Member

nzakas commented Jul 20, 2016

Okay @kaicataldo, the power is yours!

@kaicataldo
Copy link
Member

kaicataldo commented Jul 20, 2016

Thanks! Have we decided that requireForBlockBody is the config option name we want? Sounds good to me, just want to make sure.

@nzakas
Copy link
Member

nzakas commented Jul 21, 2016

Yup!

nfroidure added a commit to nfroidure/eslint that referenced this issue Jul 22, 2016
…le (fixes eslint#6557)

The `'as-needed'` option can now be modified with the `{requireForBlockBody: true}` option allowing to
 require parentheses for arrow functions whose body is wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```
nfroidure added a commit to nfroidure/eslint that referenced this issue Jul 22, 2016
…le (fixes eslint#6557)

The `'as-needed'` option can now be modified with the `{requireForBlockBody: true}` option allowing to
 require parentheses for arrow functions whose body is wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```
nfroidure added a commit to nfroidure/eslint that referenced this issue Jul 22, 2016
…nt#6557)

The `'as-needed'` option can now be modified with the `{requireForBlockBody: true}` option allowing to
 require parentheses for arrow functions whose body is wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```
nfroidure added a commit to nfroidure/eslint that referenced this issue Jul 24, 2016
…nt#6557)

The `'as-needed'` option can now be modified with the `{requireForBlockBody: true}` option allowing to
 require parentheses for arrow functions whose body is wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```
nfroidure added a commit to nfroidure/eslint that referenced this issue Jul 25, 2016
…nt#6557)

The `'as-needed'` option can now be modified with the `{requireForBlockBody: true}` option allowing to
 require parentheses for arrow functions whose body is wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```
nfroidure added a commit to nfroidure/eslint that referenced this issue Aug 2, 2016
…nt#6557)

The `'as-needed'` option can now be modified with the `{requireForBlockBody: true}` option allowing to
 require parentheses for arrow functions whose body is wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```
nfroidure added a commit to nfroidure/eslint that referenced this issue Aug 2, 2016
…nt#6557)

The `'as-needed'` option can now be modified with the `{requireForBlockBody: true}` option allowing to
 require parentheses for arrow functions whose body is wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```
nfroidure added a commit to nfroidure/eslint that referenced this issue Aug 3, 2016
…nt#6557)

The `'as-needed'` option can now be modified with the `{requireForBlockBody: true}` option allowing to
 require parentheses for arrow functions whose body is wrapped into curly braces like the following:
 ```js
 (a) => {}
 ```
@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
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

9 participants