Skip to content

Commit

Permalink
[eslint config][major][guide] Always require parens for arrow functio…
Browse files Browse the repository at this point in the history
…n args
  • Loading branch information
sharmilajesupaul committed Jul 10, 2018
1 parent 96317f8 commit 0ca14dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -962,9 +962,12 @@ Other Style Guides
`A string containing the ${nextNumber}.`;
});

// good
// bad
[1, 2, 3].map(number => `A string containing the ${number}.`);

// good
[1, 2, 3].map((number) => `A string containing the ${number}.`);

// good
[1, 2, 3].map((number) => {
const nextNumber = number + 1;
Expand Down Expand Up @@ -1018,22 +1021,27 @@ Other Style Guides
```

<a name="arrows--one-arg-parens"></a><a name="8.4"></a>
- [8.4](#arrows--one-arg-parens) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments for clarity and consistency. Note: it is also acceptable to always use parentheses, in which case use the [“always” option](https://eslint.org/docs/rules/arrow-parens#always) for eslint. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens.html)
- [8.4](#arrows--one-arg-parens) Always include parentheses around arguments for clarity and consistency. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens.html)

> Why? Less visual clutter.
> Why? Minimizes diff churn when adding or removing arguments.
```javascript
// bad
[1, 2, 3].map((x) => x * x);

// good
[1, 2, 3].map(x => x * x);

// good
[1, 2, 3].map((x) => x * x);

// bad
[1, 2, 3].map(number => (
`A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`
));

// good
[1, 2, 3].map((number) => (
`A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`
));

// bad
[1, 2, 3].map(x => {
const y = x + 1;
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-config-airbnb-base/rules/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ module.exports = {

// require parens in arrow function arguments
// https://eslint.org/docs/rules/arrow-parens
'arrow-parens': ['error', 'as-needed', {
requireForBlockBody: true,
}],
'arrow-parens': ['error', 'always'],

// require space before/after arrow function's arrow
// https://eslint.org/docs/rules/arrow-spacing
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-airbnb-base/test/test-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Object.keys(files).forEach((

// scan rules for react/ and fail if any exist
const reactRuleIds = Object.keys(config.rules)
.filter(ruleId => ruleId.indexOf('react/') === 0);
.filter((ruleId) => ruleId.indexOf('react/') === 0);
t.deepEquals(reactRuleIds, [], 'there are no react/ rules');
});
});
2 changes: 1 addition & 1 deletion packages/eslint-config-airbnb/test/test-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Object.keys(files).forEach((name) => {

// scan rules for react/ and fail if any exist
const reactRuleIds = Object.keys(config.rules)
.filter(ruleId => ruleId.indexOf('react/') === 0);
.filter((ruleId) => ruleId.indexOf('react/') === 0);
t.deepEquals(reactRuleIds, [], 'there are no react/ rules');
});
});

0 comments on commit 0ca14dc

Please sign in to comment.