Javascript 用于垂直点对齐的ESlint样式 序曲
我更喜欢保持点垂直对齐:Javascript 用于垂直点对齐的ESlint样式 序曲,javascript,ecmascript-6,eslint,Javascript,Ecmascript 6,Eslint,我更喜欢保持点垂直对齐: const my_long_name = louis.what() .a() .wonderful() .world(); 但埃斯林特抱怨道 `Expected indentation of 4 spaces but found 26. [indent]`. 我的~/.eslintrc.js已经 module.e
const my_long_name = louis.what()
.a()
.wonderful()
.world();
但埃斯林特抱怨道
`Expected indentation of 4 spaces but found 26. [indent]`.
我的~/.eslintrc.js
已经
module.exports = {
extends: [
'airbnb-base',
],
...
}
问题: 如何使用
airbnb base
使点垂直对齐(并进行ESlint检查)
(另一种风格是开箱即用的吗?写作
extends: [
'crockford',
],
没用。)
更新1 如果我在
~/.eslint.js
中:
module.exports = {
rules: {
"indent": ["error", 4, { "MemberExpression": 0 }]
}
...
};
信息变成
Expected indentation of 0 spaces but found 26. [indent]
然后,ESlint需要以下格式:
const my_long_name = louis.what()
.a()
.wonderful()
.world();
Elethan的回答给出了一个关闭链调用缩进的提示,使用:
module.exports = {
rules: {
"indent": ["error", 4, { "MemberExpression": "off" }]
}
...
};
这比继续收到警告或打破点的垂直排列要好
如果点垂直对齐错误,或者是2019年末ESlint的最佳解决方案是{“MemberExpression”:“off”}
,是否可以继续收到警告
更新2 我在以下两个代码示例上运行了
eslint--init
(没有其他代码)
~/.eslintrc.js
let hello = louis.what()
.a()
.wonderful()
.world();
let hello = louis.what()
.a()
.wonderful()
.world();
~/.eslintrc点垂直对齐.js
let hello = louis.what()
.a()
.wonderful()
.world();
let hello = louis.what()
.a()
.wonderful()
.world();
得到了以下区别:
> diff ~/.eslintrc-strictly-four.js ~/.eslintrc-dots-vertically-aligned.js
61c61
< "indent": "error",
---
> "indent": "off",
>diff~/.eslintrc-stricted-four.js~/.eslintrc-dots-vertical-aligned.js
61c61
<“缩进”:“错误”,
---
>“缩进”:“关闭”,
因此,除非有人给出权威性的答案,否则这就是解决问题的方法。似乎将缩进规则的设置为关闭可以解决问题
“MemberExpression”
(默认值:1)为多行属性链强制执行缩进级别。这也可以设置为“off”
,以禁用对成员表达式
缩进的检查
例如,在您的.eslintrc
中:
"rules": {
"indent": ["error", 4, { "MemberExpression": 0 }]
}
试着用louis¨.what()¨.a()¨.wonderful()¨.world()
代替它?@Bergi我不确定JS代码的正文中的皮尔克罗(,或段落符号)的含义,而不是字符串。要添加引用吗?pilcrow表示一个换行符,不能在注释中显示。@Bergi我明白你的意思了:在对象名称后添加换行符,以同时缓和ESlint中的缩进规则和我自己看到点垂直对齐的需要。这不是很正统,但它似乎是ESlint v6.4.0所能做到的最好的。