linebreak_operator-linebreak (Rules) – Eslint 中文开发手册 - Break易站
Eslint 中文開發手冊
operator-linebreak (Rules) - Eslint 中文開發手冊
在命令行上的--fix選項可以自動修復一些被這條規則反映的問題。
當一條語句太長而不適合單行時,通常會在分隔表達式的運算符旁邊插入換行符。想到的第一種方式是按照英文標點符號將操作員放在行的末尾。
var fullHeight = borderTop +
innerHeight +
borderBottom;
一些開發人員發現,將行號放置在行首會使代碼更具可讀性。
var fullHeight = borderTop
+ innerHeight
+ borderBottom;
規則細節
此規則為運營商實施一致的換行樣式。
選項
此規則有一個選項,可以是字符串選項或對象選項。
字符串選項:
"after" 需要將換行符置于操作員之后"before" 需要將換行符放在操作員面前"none" 不允許在運營商的任何一方進行換行
對象選項:
"overrides" 覆蓋用于指定operatorsThe默認配置的全局設置是 "after", { "overrides": { "?": "before", ":": "before" } }的afterExamples 不正確代碼此規則與默認"after"選項:/*eslint operator-linebreak: ["error", "after"]*/
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" option:/*eslint operator-linebreak: ["error", "after"]*/
foo = 1 + 2;
foo = 1 +
2;
foo =
5;
if (someCondition ||
otherCondition) {
}
answer = everything ?
42 :
foo;beforeExamples of incorrect code for this rule with the "before" option:/*eslint operator-linebreak: ["error", "before"]*/
foo = 1 +
2;
foo =
5;
if (someCondition ||
otherCondition) {
}
answer = everything ?
42 :
foo;之前的這個規則的代碼不正確"before"選項:/*eslint operator-linebreak: ["error", "before"]*/
foo = 1 + 2;
foo = 1
+ 2;
foo
= 5;
if (someCondition
|| otherCondition) {
}
answer = everything
? 42
: foo;none此規則的代碼不正確,代碼如下"none"選項:/*eslint operator-linebreak: ["error", "none"]*/
foo = 1 +
2;
foo = 1
+ 2;
if (someCondition ||
otherCondition) {
}
if (someCondition
|| otherCondition) {
}
answer = everything
? 42
: foo;
answer = everything ?
42 :
foo;此規則的代碼不正確,帶有"none"選項的代碼如下:/*eslint operator-linebreak: ["error", "none"]*/
foo = 1 + 2;
foo = 5;
if (someCondition || otherCondition) {
}
answer = everything ? 42 : foo;overrides此規則附加正確代碼的示例,其中包含以下{ "overrides": { "+=": "before" } }選項:/*eslint operator-linebreak: ["error", "after", { "overrides": { "+=": "before" } }]*/
var thing
+= 'thing';這個規則的附加正確代碼示例包含以下{ "overrides": { "?": "ignore", ":": "ignore" } }選項:/*eslint operator-linebreak: ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" } }]*/
answer = everything ?
42
: foo;
answer = everything
?
42
:
foo;When Not To Use ItIf your project will not be using a common operator line break style, turn this rule off.Related Rulescomma-style
版本
該規則在 ESLint 0.19.0中引入。
資源
規則資源文檔資源
總結
以上是生活随笔為你收集整理的linebreak_operator-linebreak (Rules) – Eslint 中文开发手册 - Break易站的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拓展迅雷快传等
- 下一篇: Linux下应用程序列表