Skip to content

Commit

Permalink
Docs: Improve examples and clarify default option (#12067)
Browse files Browse the repository at this point in the history
* Docs: Improve examples and clarify default option

The "default" option is now set to `overrides` instead of `after` because examples in after may be misleading.
A new incorrect example is added to `overrides` to clarify whether the overridden style can still be used.

* Docs: Reformat operator-linebreak
  • Loading branch information
zypA13510 authored and ilyavolodin committed Sep 14, 2019
1 parent 540296f commit e915fff
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions docs/rules/operator-linebreak.md
Expand Up @@ -38,7 +38,7 @@ The default configuration is `"after", { "overrides": { "?": "before", ":": "bef

### after

Examples of **incorrect** code for this rule with the default `"after"` option:
Examples of **incorrect** code for this rule with the `"after"` option:

```js
/*eslint operator-linebreak: ["error", "after"]*/
Expand All @@ -62,7 +62,7 @@ answer = everything
: foo;
```

Examples of **correct** code for this rule with the default `"after"` option:
Examples of **correct** code for this rule with the `"after"` option:

```js
/*eslint operator-linebreak: ["error", "after"]*/
Expand Down Expand Up @@ -175,6 +175,16 @@ answer = everything ? 42 : foo;

### overrides

Examples of additional **incorrect** code for this rule with the `{ "overrides": { "+=": "before" } }` option:

```js
/*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/

var thing = 'thing';
thing +=
's';
```

Examples of additional **correct** code for this rule with the `{ "overrides": { "+=": "before" } }` option:

```js
Expand All @@ -201,6 +211,52 @@ answer = everything
foo;
```

Examples of **incorrect** code for this rule with the default `"after", { "overrides": { "?": "before", ":": "before" } }` option:

```js
/*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/

foo = 1
+
2;

foo = 1
+ 2;

foo
= 5;

if (someCondition
|| otherCondition) {
}

answer = everything ?
42 :
foo;
```

Examples of **correct** code for this rule with the default `"after", { "overrides": { "?": "before", ":": "before" } }` option:

```js
/*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/

foo = 1 + 2;

foo = 1 +
2;

foo =
5;

if (someCondition ||
otherCondition) {
}

answer = everything
? 42
: foo;
```

## When Not To Use It

If your project will not be using a common operator line break style, turn this rule off.
Expand Down

0 comments on commit e915fff

Please sign in to comment.