我正在配置eslint并使用AirBNB样式指南.
我想把缩进(假设是2个空格)覆盖为4个空格.但无论我在.eslintrc中做什么,我都无法得到这个错误,因此我可以使用4个空格的缩进.
我的代码库中到处都有消息"预期缩进2个空格的聊天,但发现了4.(react/jsx-indent)".
我正在使用eslint 4.9.0.我该如何解决这个问题?谢谢.
Not*_*ous 46
好的,这样做相对容易,可以通过在eslint配置中添加以下内容来实现:
// Indent with 4 spaces
"indent": ["error", 4],
// Indent JSX with 4 spaces
"react/jsx-indent": ["error", 4],
// Indent props with 4 spaces
"react/jsx-indent-props": ["error", 4],
Run Code Online (Sandbox Code Playgroud)
Ale*_*Sil 14
上面的代码应该添加到ESlint 配置中的规则字段中。
module.exports = {
"extends": "eslint:recommended",
"rules": {
// enable additional rules
"indent": ["error", 4],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
// override default options for rules from base configurations
"comma-dangle": ["error", "always"],
"no-cond-assign": ["error", "always"],
// disable rules from base configurations
"no-console": "off",
}
Run Code Online (Sandbox Code Playgroud)
[来源- 请参阅使用“eslint:推荐” ]
Leo*_*ele 10
由于接受的答案不完整并且该答案的编辑队列已满,因此我添加了以下补充:
要简单地禁用2 空格 ident 规则,请将以下行添加到rulesesling 配置文件的属性中:
"indent": "off",
Run Code Online (Sandbox Code Playgroud)
要覆盖规则(可能是您想要的)以检查 4 个空格而不是 2 个空格,请添加以下行:
"indent": ["error", 4],
Run Code Online (Sandbox Code Playgroud)
它应该看起来像这样:
// eslintrc.js
module.exports = {
"extends": [
"eslint:recommended",
"airbnb",
],
"rules": {
"indent": ["error", 4],
},
};
Run Code Online (Sandbox Code Playgroud)
您的 eslint 配置可能位于以下任意文件中:
.eslintrc.js.eslintrc.cjs.eslintrc.yaml.eslintrc.yml.eslintrc.json.eslintrcpackage.json某个"eslintConfig"属性中。有关 eslint 配置的更多信息:https://eslint.org/docs/user-guide/configuring(在“配置文件格式”标题下)
| 归档时间: |
|
| 查看次数: |
14176 次 |
| 最近记录: |