【问题标题】:eslint indent rule not being disabledeslint 缩进规则没有被禁用
【发布时间】:2019-04-06 15:30:06
【问题描述】:

我试图让更漂亮和 eslint 一起工作,我遵循了这个article,但我遇到了缩进规则的问题.. 基本上我有这个jsx 格式

const ResponseModule = ({ response }) => (
    <div>
        {response.code === 401 ? (
            <div className="response">
                <div className="response-content">
                    <h1> {response.message} </h1>
                    <button onClick={() => initLogout()}> Login to continue </button>
                </div>
            </div>
        ) : null}
    </div>
);

我收到这样的缩进错误

[eslint] Delete `..` [prettier/prettier]

现在当我应用自动修复时,它变成了这个

const ResponseModule = ({ response }) => (
  <div>
    {response.code === 401 ? (
      <div className="response">
        <div className="response-content">
          <h1> {response.message} </h1>
          <button onClick={() => initLogout()}> Login to continue </button>
        </div>
      </div>
    ) : null}
  </div>
);

当我在 vs 代码中点击保存 (CTRL+S) 时,它只是回到第一种格式,因此再次给我同样的错误.. 我无法继续工作..

这是我的 eslint 配置

{
  "env": {
    "browser": true
  },
  "extends": [
    "airbnb",
    "plugin:prettier/recommended"
  ],
  "parser": "babel-eslint",
  "rules": {
    "no-tabs": 0,
    "indent": 0,
    "no-underscore-dangle": 0,
    "react/prop-types": 0,
    "linebreak-style": [
      "error",
      "windows"
    ],
    "jsx-closing-tag-location": 0,
    "class-methods-use-this": 0,
    "import/no-named-as-default": 0,
    "react/jsx-filename-extension": [
      "error",
      {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    ]
  },
  "plugins": [
    "prettier"
  ]
}

这些是我拥有的 eslint/prettier 包相关

"eslint": "^5.3.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.0",
"prettier": "1.14.3",

【问题讨论】:

  • 我不知道 VSCode,但看起来您已将其设置为在保存时自动格式化代码。因此,您应该禁用自动格式化或将其配置为正确的缩进。

标签: reactjs visual-studio-code eslint prettier eslintrc


【解决方案1】:

您还需要禁用react/jsx-indent,该规则由eslint-config-airbnb 启用。

【讨论】:

  • 先生,但是如何。请告知我需要禁用它们。谢谢。
猜你喜欢
  • 1970-01-01
  • 2021-10-16
  • 2015-10-07
  • 2021-12-10
  • 2020-08-15
  • 1970-01-01
  • 1970-01-01
  • 2017-07-04
  • 1970-01-01
相关资源
最近更新 更多