From 90b621b32fc1a88cc750fe430458e33c8df64ae1 Mon Sep 17 00:00:00 2001 From: Yuping Zuo Date: Tue, 6 Aug 2019 15:39:37 +0800 Subject: [PATCH 1/2] 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/rules/operator-linebreak.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/rules/operator-linebreak.md b/docs/rules/operator-linebreak.md index e2a69a1fdc6..0bf88875a06 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,14 +175,24 @@ answer = everything ? 42 : foo; ### overrides -Examples of additional **correct** code for this rule with the `{ "overrides": { "+=": "before" } }` option: +Examples of additional **incorrect** code for this rule with the default `{ "overrides": { "?": "before", ":": "before" } }` option: ```js -/*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/ +/*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/ -var thing = 'thing'; -thing - += 's'; +answer = everything ? + 42 : + foo; +``` + +Examples of additional **correct** code for this rule with the default `{ "overrides": { "?": "before", ":": "before" } }` option: + +```js +/*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/ + +answer = everything + ? 42 + : foo; ``` Examples of additional **correct** code for this rule with the `{ "overrides": { "?": "ignore", ":": "ignore" } }` option: From 1c1a1b8a9e019677479bb573fc37e03c82c99ae2 Mon Sep 17 00:00:00 2001 From: Yuping Zuo Date: Tue, 20 Aug 2019 16:34:45 +0800 Subject: [PATCH 2/2] Docs: Reformat operator-linebreak --- docs/rules/operator-linebreak.md | 66 +++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/docs/rules/operator-linebreak.md b/docs/rules/operator-linebreak.md index 0bf88875a06..3b1986e0fff 100644 --- a/docs/rules/operator-linebreak.md +++ b/docs/rules/operator-linebreak.md @@ -175,24 +175,24 @@ answer = everything ? 42 : foo; ### overrides -Examples of additional **incorrect** code for this rule with the default `{ "overrides": { "?": "before", ":": "before" } }` option: +Examples of additional **incorrect** code for this rule with the `{ "overrides": { "+=": "before" } }` option: ```js -/*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/ +/*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/ -answer = everything ? - 42 : - foo; +var thing = 'thing'; +thing += + 's'; ``` -Examples of additional **correct** code for this rule with the default `{ "overrides": { "?": "before", ":": "before" } }` option: +Examples of additional **correct** code for this rule with the `{ "overrides": { "+=": "before" } }` option: ```js -/*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/ +/*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/ -answer = everything - ? 42 - : foo; +var thing = 'thing'; +thing + += 's'; ``` Examples of additional **correct** code for this rule with the `{ "overrides": { "?": "ignore", ":": "ignore" } }` option: @@ -211,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.