From e915fffb6089a23ff1cae926cc607f9b87dc1819 Mon Sep 17 00:00:00 2001 From: Yuping Zuo Date: Sat, 14 Sep 2019 09:20:44 +0800 Subject: [PATCH] Docs: Improve examples and clarify default option (#12067) * 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 --- docs/rules/operator-linebreak.md | 60 ++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/docs/rules/operator-linebreak.md b/docs/rules/operator-linebreak.md index e2a69a1fdc6..3b1986e0fff 100644 --- a/docs/rules/operator-linebreak.md +++ b/docs/rules/operator-linebreak.md @@ -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"]*/ @@ -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"]*/ @@ -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 @@ -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.