gpt4 book ai didi

javascript - 用于垂直点对齐的样式化 ESlint

转载 作者:行者123 更新时间:2023-11-29 22:47:32 24 4
gpt4 key购买 nike

前奏

我更喜欢让点垂直对齐:

const my_long_name = louis.what()
.a()
.wonderful()
.world();

但是 ESlint 提示

`Expected indentation of 4 spaces but found 26. [indent]`.

我的 ~/.eslintrc.js

module.exports = {
extends: [
'airbnb-base',
],
...
}

问题

我如何使用 airbnb-base 让点垂直对齐(并让 ESlint 检查它)?

(另一种风格是否开箱即用?写作

    extends: [
'crockford',
],

没用。)


更新1

如果我write~/.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" }]
}
...
};

这比继续收到警告或破坏点的垂直对齐要好。

如果点垂直未对齐,是否可以继续收到警告,或者 { "MemberExpression": "off"} 是 2019 年底使用 ESlint 可以做的最好的事情?


更新2

我对以下两个代码示例运行了 eslint --init(没有额外的代码)。

~/.eslintrc-strictly-four.js

let hello = louis.what()
.a()
.wonderful()
.world();

~/.eslintrc-dots-vertically-aligned.js

let hello = louis.what()
.a()
.wonderful()
.world();

得到以下区别:

> diff ~/.eslintrc-strictly-four.js ~/.eslintrc-dots-vertically-aligned.js 
61c61
< "indent": "error",
---
> "indent": "off",

因此,在有人用权威答案阐明这一点之前,这就是这样做的方法。

最佳答案

看起来像设置 MemberExpression optionindent 规则设置 off 可能会解决您的问题。

"MemberExpression" (default: 1) enforces indentation level for multi-line property chains. This can also be set to "off" to disable checking for MemberExpression indentation.

例如,在您的 .eslintrc 中:

"rules": {
"indent": ["error", 4, { "MemberExpression": 0 }]
}

关于javascript - 用于垂直点对齐的样式化 ESlint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58071981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com