Skip to content

Commit e9fff7a

Browse files
sharmilajesupaulljharb
authored andcommitted
[eslint config] [base] [breaking] Prevent line breaks before and after =
1 parent 53b2d7d commit e9fff7a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,28 @@ Other Style Guides
16991699
const truthyCount = array.filter(Boolean).length;
17001700
```
17011701
1702+
- [13.7](#variables--linebreak) Avoid linebreaks before or after `=` in an assignment. If your assignment violates [`max-len`](https://eslint.org/docs/rules/max-len.html), surround the value in parens. eslint [`operator-linebreak`](https://eslint.org/docs/rules/operator-linebreak.html).
1703+
1704+
> Why? Linebreaks surrounding `=` can obfuscate the value of an assignment.
1705+
1706+
```javascript
1707+
// bad
1708+
const foo =
1709+
superLongLongLongLongLongLongLongLongFunctionName();
1710+
1711+
// bad
1712+
const foo
1713+
= 'superLongLongLongLongLongLongLongLongString';
1714+
1715+
// good
1716+
const foo = (
1717+
superLongLongLongLongLongLongLongLongFunctionName()
1718+
);
1719+
1720+
// good
1721+
const foo = 'superLongLongLongLongLongLongLongLongString';
1722+
```
1723+
17021724
**[⬆ back to top](#table-of-contents)**
17031725
17041726
## Hoisting

packages/eslint-config-airbnb-base/rules/style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ module.exports = {
405405

406406
// Requires operator at the beginning of the line in multiline statements
407407
// https://eslint.org/docs/rules/operator-linebreak
408-
'operator-linebreak': ['error', 'before'],
408+
'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }],
409409

410410
// disallow padding within blocks
411411
'padded-blocks': ['error', { blocks: 'never', classes: 'never', switches: 'never' }],

0 commit comments

Comments
 (0)