[英]How to fix prettier and tslint error with brackets with single props?
I use prettier and tslint, with https://github.com/alexjoverm/tslint-config-prettier and https://github.com/ikatyang/tslint-plugin-prettier . 我使用更漂亮的tslint和https://github.com/alexjoverm/tslint-config-prettier和https://github.com/ikatyang/tslint-plugin-prettier 。
My tslint.json
is like 我的
tslint.json
就像
{
"defaultSeverity": "error",
"extends": [
"tslint-config-airbnb",
"tslint-react",
"tslint-config-prettier"
],
"jsRules": {},
"rules": {
"max-line-length": [true, 80],
"import-name": false,
"variable-name": false,
"jsx-boolean-value": false,
"jsx-no-multiline-js": false,
"no-else-after-return": false,
"object-shorthand-properties-first": false,
"ter-arrow-parens": false,
"ter-indent": false,
"prettier": true
},
"rulesDirectory": ["tslint-plugin-prettier"]
}
And my .prettierrc
is like 我的
.prettierrc
就像
{
"trailingComma": "all",
"singleQuote": true
}
After tslint --fix "src/**/*.ts"
, codes like below appears: 在
tslint --fix "src/**/*.ts"
之后,出现如下代码:
import { getChildrenProceduresSelector } from '@src/entities/procedures/selectors';
And the error says [tslint] Exceeds maximum line length of 80 (max-line-length)
. 并且错误显示
[tslint] Exceeds maximum line length of 80 (max-line-length)
。
But when I fix it manually to 但是当我手动修复它
import {
getChildrenProceduresSelector,
} from '@src/entities/procedures/selectors';
It says 它说
[tslint] Replace `⏎··getChildrenProceduresSelector,⏎` with `·getChildrenProceduresSelector·` (prettier)
I use VSCode with tslint and prettier extensions. 我将VSCode与tslint和更漂亮的扩展一起使用。 My tslint command says the same error.
我的tslint命令说同样的错误。 How to fix this conflicts?
如何解决此冲突?
Error in your config comes from "max-line-length": [true, 80]
. 您配置中的错误来自
"max-line-length": [true, 80]
。 It conflicts with prettier rules. 它与更漂亮的规则相冲突。 If you want to set
max-line
you should do it in .prettierc
file -> "printWidth": 80
. 如果要设置
max-line
,则应在.prettierc
文件-> "printWidth": 80
。
tslint-config-prettier - this config disables all the rules from tslint
that conflicts with prettier
(So in your case, this plugin disabled max-line
from tslint
, but then you set it manually in rules
section) tslint-config-prettier-此配置禁用
tslint
中与prettier
冲突的所有规则(因此,在您的情况下,此插件禁用了tslint
max-line
,但是您可以在rules
部分中手动设置它)
tslint-plugin-prettier - this plugin runs prettier rules as tslint
rules. tslint-plugin-prettier-此插件
tslint
漂亮的规则作为tslint
规则运行。 In addition you need to enable this in rule
section of your tslint.json
. 另外,您需要在
tslint.json
rule
部分中启用此tslint.json
。
Taking all of that into consideration your configuration should look more or less like this: 考虑到所有这些,您的配置应大致如下所示:
// With tslint@5.0.0+
{
"extends": [
"tslint-config-airbnb",
"tslint-config-prettier",
"tslint-plugin-prettier"
],
"rules": {
"prettier": true
}
}
// With tslint@5.2.0+
{
"extends": [
"tslint-config-airbnb",
"tslint-config-prettier",
"tslint-plugin-prettier"
],
"rules": {
"prettier": true
},
"rulesDirectory": [
"tslint-plugin-prettier"
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.