1 # enforce consistent linebreak style for operators (operator-linebreak)
3 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.
6 var fullHeight = borderTop +
11 Some developers find that placing operators at the beginning of the line makes the code more readable.
14 var fullHeight = borderTop
21 This rule enforces a consistent linebreak style for operators.
25 This rule has two options, a string option and an object option.
29 * `"after"` requires linebreaks to be placed after the operator
30 * `"before"` requires linebreaks to be placed before the operator
31 * `"none"` disallows linebreaks on either side of the operator
35 * `"overrides"` overrides the global setting for specified operators
37 The default configuration is `"after", { "overrides": { "?": "before", ":": "before" } }`
41 Examples of **incorrect** code for this rule with the `"after"` option:
44 /*eslint operator-linebreak: ["error", "after"]*/
75 Examples of **correct** code for this rule with the `"after"` option:
78 /*eslint operator-linebreak: ["error", "after"]*/
110 Examples of **incorrect** code for this rule with the `"before"` option:
113 /*eslint operator-linebreak: ["error", "before"]*/
125 answer = everything ?
140 Examples of **correct** code for this rule with the `"before"` option:
143 /*eslint operator-linebreak: ["error", "before"]*/
175 Examples of **incorrect** code for this rule with the `"none"` option:
178 /*eslint operator-linebreak: ["error", "none"]*/
198 answer = everything ?
220 Examples of **correct** code for this rule with the `"none"` option:
223 /*eslint operator-linebreak: ["error", "none"]*/
229 if (someCondition || otherCondition) {
232 answer = everything ? 42 : foo;
248 Examples of additional **incorrect** code for this rule with the `{ "overrides": { "+=": "before" } }` option:
251 /*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/
258 Examples of additional **correct** code for this rule with the `{ "overrides": { "+=": "before" } }` option:
261 /*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/
268 Examples of additional **correct** code for this rule with the `{ "overrides": { "?": "ignore", ":": "ignore" } }` option:
271 /*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" } }]*/
273 answer = everything ?
284 Examples of **incorrect** code for this rule with the default `"after", { "overrides": { "?": "before", ":": "before" } }` option:
287 /*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/
303 answer = everything ?
308 Examples of **correct** code for this rule with the default `"after", { "overrides": { "?": "before", ":": "before" } }` option:
311 /*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "before", ":": "before" } }]*/
330 ## When Not To Use It
332 If your project will not be using a common operator line break style, turn this rule off.
336 * [comma-style](comma-style.md)