[eslint config] [base] [breaking] Prevent line breaks before and after =

This commit is contained in:
Sharmila
2018-01-26 10:57:21 -08:00
committed by Jordan Harband
parent 53b2d7d245
commit e9fff7adbf
2 changed files with 23 additions and 1 deletions

View File

@@ -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

View File

@@ -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' }],