我将Prettier 1.14.0和Prettier Formatter用于Visual Studio Code。我遇到了函数参数格式不固定的问题。
例如要求我保持字符串compose(field('tags'), orEmpty, commaList, usertag())()(user),
内联,而第二个则强制它像这样
compose(
field('tags'),
orEmpty,
commaList,
usertag(),
)()(user),
我希望两者都像第二种情况。看来parser
不适用于package.json ...
以下是一些配置:
package.json
"prettier": {
"parser": "flow",
"printWidth": 80
},
"eslintConfig": {
"parser": "babel-eslint",
"extends": [
"standard",
"prettier",
"plugin:import/recommended"
],
"plugins": [
"prettier",
"simple-complexity",
"import",
"import-order-autofix",
"filenames"
],
"settings": {
"import/resolver": "webpack",
"import/ignore": [
"node_modules"
]
},
"rules": {
"filenames/match-exported": [
"error"
],
"import-order-autofix/order": [
"error",
{
"newlines-between": "always"
}
],
"prettier/prettier": [
"error",
{
"parser": "flow",
"printWidth": 80,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false,
"semi": false,
"requirePragma": true,
"insertPragma": true
}
],
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline"
}
],
"complexity": [
"error",
{
"max": 15
}
],
"max-nested-callbacks": [
"error",
{
"max": 3
}
],
"max-statements": [
"error",
{
"max": 10
}
],
"max-params": [
"error",
{
"max": 4
}
],
"max-lines": [
"error",
{
"max": 350,
"skipBlankLines": true,
"skipComments": true
}
],
"max-depth": [
"error",
{
"max": 3
}
],
"simple-complexity/max-indent": [
"error",
{
"max": 20
}
]
}
},
.eslintrc
{
"extends": "react-app",
"plugins": [
"prettier",
"simple-complexity",
"import",
"import-order-autofix",
"filenames"
],
"rules": {
"filenames/match-exported": ["error"],
"import-order-autofix/order": [
"error",
{
"newlines-between": "always"
}
],
"prettier/prettier": [
"error",
{
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false,
"semi": false,
"requirePragma": true,
"insertPragma": true
}
],
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline"
}
],
"complexity": [
"error",
{
"max": 15
}
],
"max-nested-callbacks": [
"error",
{
"max": 3
}
],
"max-statements": [
"error",
{
"max": 10
}
],
"max-params": [
"error",
{
"max": 4
}
],
"max-lines": [
"error",
{
"max": 350,
"skipBlankLines": true,
"skipComments": true
}
],
"max-depth": [
"error",
{
"max": 3
}
],
"simple-complexity/max-indent": [
"error",
{
"max": 20
}
]
}
}
.vscode /设置
{
"[javascript]": {
"editor.formatOnSave": true,
},
"prettier.eslintIntegration": true,
"editor.tabSize": 2,
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/*/**": true
},
}