Eslint +漂亮+ React。道具缩进

时间:2020-07-12 12:05:31

标签: javascript reactjs phpstorm eslint prettier

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

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

我想使用更漂亮和更漂亮。但是他们彼此冲突。 Prettier说第一个道具应该在下一行,而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"
    }
}

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

1 个答案:

答案 0 :(得分:1)

漂亮的不支持该样式。您有几种选择:

  1. 在ESLint之前运行Prettier,以便ESLint覆盖所需的格式
  2. 使用没有这种样式的更漂亮的
  3. 使用这种样式而不需要漂亮