-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Add arrow function rules to eslint #4813
Conversation
lgtm |
LGTM |
2 similar comments
LGTM |
LGTM |
This is truly only temporary from being used to ES5, it does go away but… I've been thinking about the issue of arrow function parens a bit recently and I think there's a good case for a middle ground. Perhaps consider this instead:
Having more than one argument messes up terseness/simplicity of single line arrows anyway. Also found you're far more likely to need to add multiple args for something that's already a multi-line function, so this pre-empts that and removes annoying need to add parens around just because you're adding one argument. So trivial things like this remain nice and terse: items.map(item => item.price) but adding a second arg messes the terseness of a single line up even before using the arg in a function body: items.map((item, index) => item.price) Instead, the proposed option would force a multi-line structure for multi-args, like so: items.map((item, index) => {
return item.price
}) Not sure if there's a rule for this in eslint. |
LGTM. |
lgtm |
LGTM, but I'm also ok with @timoxley proposal. |
## Enforce parens around arrow function arguments | ||
arrow-parens: [2, "always"] | ||
## Require a space on each side of arrow operator | ||
arrow-spacing: [2, { "before": true, "after": true }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no spaces inside braces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and technically the quotes are optional but we don't have consistent use of them in this file...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I wasn't aware that quotes are optional in most cases YAML. I'll investigate if we can remove all quotes.
LGTM. Definitely agree on this |
So, am I the only one who finds parens around a single argument arrow function ugly? |
Nope. I am with you on that @bnoordhuis. |
Better to have less options here for the sake of new people who will inevitably become confused by the like 5 different cases of style for arrow functions. LGTM |
Personally, I prefer to only use arrow functions in the single line, paren free style, and with short argument names. The needing to explicitly return in multi line arrow functions but not single line ones is super confusing to new people, so I'd avoid that style entirely. |
Sure, but chances are we'll care more about the speed of the context capturing vs |
CI failures look unrelated. There are more than enough signoffs to land but given the discussion it may be worth while holding this one open for another day. |
@bnoordhuis ... I personally find arrow functions ugly in general along with the parens, but I'd rather we had consistency |
going to mark this one as do not land in v4 tho... can revisit that if folks feel strongly about it tho |
@jasnell If we do not backport linter rules, landing code which follow this would be difficult in the future, no? |
yes, if those rules are less restrictive or change an existing rule. In this case, not adding this rule shouldn't impact anything (tho I could be wrong) |
Yes, but I am thinking of a very rare case. Let's say we land a fix which is specific to 4.x and if that doesn't follow this rule, then we will have two slightly different style systems and it wouldn't be consistent, right? |
Yeah, you're right.
|
arrow-spacing: [2, {"before": true, "after": true}] | ||
## Prevent using => in a condition where <= is intended | ||
no-arrow-condition: 2 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no Arrow Functions
category in http://eslint.org/docs/rules/. Can you structure the rules like in that list?
I'm with @bnoordhuis writing As a data point - linters for C# (like ReSharper's rules) raise a warning (by default) if you include the |
@jasnell thoughts on landing this now? The nice thing about disabling or loosening a lint rule in the future is that it doesn't require going back and fixing the code again. |
This commit applies new arrow function linting rules across the codebase. As it turns out, the only offenders were in the test directory. PR-URL: #4813 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
This commit enables the following rules: * arrow-parens - requires parens around arrow function arguments * arrow-spacing - ensures a space on each side of the => * no-arrow-condition - prevents accidental use of => in cases where the user really intends to use <= PR-URL: nodejs#4813 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
This commit applies new arrow function linting rules across the codebase. As it turns out, the only offenders were in the test directory. PR-URL: nodejs#4813 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
This PR enforces the following linting rules:
where the user really intends to use <=
The only code that violated these rules existed in the
test
directory.R= @rvagg