Eslint + Prettier + React。道具缩进

Eslint + Prettier + React. Props indents

我想使用这种格式,其中第一个 prop 位于带有标签的行中

<strong className={`list__item_price${props.price ? '' : ' empty'}`}
        itemProp="offers"
        itemScope
        itemType="http://schema.org/Offer">

我想使用 prettier 和 eslint。但它们相互冲突。 Prettier 说 first prop 应该在下一行,而 Eslint 说它应该在第一行。以下是选项:

.prettierrc.json:

{
  "printWidth": 120,
  "tabWidth": 4,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "all",
  "bracketSpacing": false,
  "jsxBracketSameLine": true,
  "arrowParens": "avoid",
  "endOfLine": "lf"
}

.eslintrc.json:

{
    "env": {
        "browser": true,
        "es2020": true
    },
    "ecmaFeatures": {
        "modules":true,
        "arrowFunctions":true,
        "classes":true
    },
    "extends": [
        "plugin:react/recommended",
        "airbnb",
        "prettier",
        "prettier/react"
    ],
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 11,
        "sourceType": "module"
    },
    "settings": {
        "import/resolver": "webpack"
    },
    "plugins": [
        "react",
        "prettier"
    ],
    "rules": {
        "no-plusplus": "off",
        "prettier/prettier": "error",
        "prettier/tabWidth": "off",
        "react/jsx-indent": ["error", 4],
        "react/jsx-indent-props": ["error", "first"],
        "react/jsx-props-no-spreading": ["error", {
            "html": "ignore"
        }],
        "react/jsx-closing-bracket-location": ["error", "after-props"],
        "react/jsx-first-prop-new-line": ["error", "never"],
        "jsx-a11y/no-static-element-interactions": "off",
        "jsx-a11y/click-events-have-key-events": "off"
    }
}

如您所见,我试图关闭一些更漂亮的选项,但没有帮助。可以解释一下,我该怎么做?

Prettier 不支持该样式。您有多种选择:

  1. 运行 在 ESLint 之前更漂亮,因此 ESLint 会覆盖您想要的格式
  2. 不用这种风格使用 Prettier
  3. 在没有 Prettier 的情况下使用此样式