mirror of
https://github.com/airbnb/javascript.git
synced 2026-04-25 03:00:19 -04:00
[eslint config] [base] [breaking] Prevent line breaks before and after =
This commit is contained in:
22
README.md
22
README.md
@@ -1699,6 +1699,28 @@ Other Style Guides
|
||||
const truthyCount = array.filter(Boolean).length;
|
||||
```
|
||||
|
||||
- [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).
|
||||
|
||||
> Why? Linebreaks surrounding `=` can obfuscate the value of an assignment.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
const foo =
|
||||
superLongLongLongLongLongLongLongLongFunctionName();
|
||||
|
||||
// bad
|
||||
const foo
|
||||
= 'superLongLongLongLongLongLongLongLongString';
|
||||
|
||||
// good
|
||||
const foo = (
|
||||
superLongLongLongLongLongLongLongLongFunctionName()
|
||||
);
|
||||
|
||||
// good
|
||||
const foo = 'superLongLongLongLongLongLongLongLongString';
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
## Hoisting
|
||||
|
||||
@@ -405,7 +405,7 @@ module.exports = {
|
||||
|
||||
// Requires operator at the beginning of the line in multiline statements
|
||||
// https://eslint.org/docs/rules/operator-linebreak
|
||||
'operator-linebreak': ['error', 'before'],
|
||||
'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }],
|
||||
|
||||
// disallow padding within blocks
|
||||
'padded-blocks': ['error', { blocks: 'never', classes: 'never', switches: 'never' }],
|
||||
|
||||
Reference in New Issue
Block a user