2 title: operator-linebreak
11 When a statement is too long to fit on a single line, line breaks are generally inserted next to the operators separating expressions. The first style coming to mind would be to place the operator at the end of the line, following the English punctuation rules.
14 var fullHeight = borderTop +
19 Some developers find that placing operators at the beginning of the line makes the code more readable.
22 var fullHeight = borderTop
29 This rule enforces a consistent linebreak style for operators.
33 This rule has two options, a string option and an object option.
37 * `"after"` requires linebreaks to be placed after the operator
38 * `"before"` requires linebreaks to be placed before the operator
39 * `"none"` disallows linebreaks on either side of the operator
43 * `"overrides"` overrides the global setting for specified operators
45 The default configuration is `"after", { "overrides": { "?": "before", ":": "before" } }`
49 Examples of **incorrect** code for this rule with the `"after"` option:
54 /*eslint operator-linebreak: ["error", "after"]*/
87 Examples of **correct** code for this rule with the `"after"` option:
92 /*eslint operator-linebreak: ["error", "after"]*/
106 answer = everything ?
126 Examples of **incorrect** code for this rule with the `"before"` option:
131 /*eslint operator-linebreak: ["error", "before"]*/
143 answer = everything ?
160 Examples of **correct** code for this rule with the `"before"` option:
165 /*eslint operator-linebreak: ["error", "before"]*/
199 Examples of **incorrect** code for this rule with the `"none"` option:
204 /*eslint operator-linebreak: ["error", "none"]*/
224 answer = everything ?
248 Examples of **correct** code for this rule with the `"none"` option:
253 /*eslint operator-linebreak: ["error", "none"]*/
259 if (someCondition || otherCondition) {
262 answer = everything ? 42 : foo;
280 Examples of additional **incorrect** code for this rule with the `{ "overrides": { "+=": "before" } }` option:
285 /*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/
294 Examples of additional **correct** code for this rule with the `{ "overrides": { "+=": "before" } }` option:
299 /*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/
308 Examples of additional **correct** code for this rule with the `{ "overrides": { "?": "ignore", ":": "ignore" } }` option:
313 /*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" } }]*/
315 answer = everything ?
328 Examples of **incorrect** code for this rule with the default `"after", { "overrides": { "?": "before", ":": "before" } }` option:
333 /*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/
349 answer = everything ?
356 Examples of **correct** code for this rule with the default `"after", { "overrides": { "?": "before", ":": "before" } }` option:
361 /*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/
382 ## When Not To Use It
384 If your project will not be using a common operator line break style, turn this rule off.