我在带有 React 的 JavaScript 项目中使用 Prettier。我所有的组件道具都在 1 行中格式化:
<Icon icon="arrow-left" width={15} height={18} />
我想要这个:
<Icon
icon="arrow-left"
width={15}
height={18}
/>
我已添加"react/jsx-max-props-per-line": [1, { "when": "multiline" }]
到我的 .prettierrc,但没有结果。
我也有一个 ESLint 配置,具有以下规则:
{
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:prettier/recommended"
],
"plugins": ["react", "prettier", "standard"],
"rules": {
"indent": [2, 2, { "SwitchCase": 1 }],
"quotes": [2, "single"],
"linebreak-style": [2, "unix"],
"semi": [2, "always"],
"no-console": [0],
"no-loop-func": [0],
"new-cap": [0],
"no-trailing-spaces": [0],
"no-param-reassign": [0],
"func-names": [0],
"comma-dangle": [0],
"no-unused-expressions": [0],
"block-scoped-var": [0],
"react/prop-types": [0],
"prettier/prettier": "error"
}
}
我的 .prettier 文件配置:
"bracketSpacing": true,
"jsxBracketSameLine": true,
"printWidth": 80,
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 2,
"useTabs": false,
"react/jsx-max-props-per-line": [1, { "when": "always" }]
也许是冲突?我尝试将react/jsx-max-props-per-line
规则移至 ESLint,但也没有结果。没变。
任何人都可以帮助我吗?