[英]tslint and prettier conflict use tslint rules
I have prettier
and tslint
configured.我配置了
prettier
和tslint
。 However it seems prettier overrides the tslint rules.然而,它似乎更漂亮地覆盖了 tslint 规则。 I can disable some of the rules using
.prettierrc
.我可以使用
.prettierrc
禁用一些规则。 However I'm still having issues.但是我仍然有问题。 I want the
tslint.json
/exceptions to take precedence over .prettierrc
我希望
tslint.json
/exceptions 优先于.prettierrc
For instance prettier inserts semicolon at the end of class methods.例如 prettier 在 class 方法的末尾插入分号。 I have exception in
tslint.json
.我在
tslint.json
有异常。 but that doesn't seem to work.但这似乎不起作用。 I could disable with
semi: false
in .prettierrc
if I do that then it would disable semi every where.如果我这样做,我可以在
.prettierrc
中使用semi: false
禁用,然后它会在任何地方禁用 semi。
// appbar.tsx
const makeStyles((theme) => ({});
export class AppBar {
private handleOpen = (event: Event): void => {
event.preventDefault();
this.props.onOpen();
}; // prettier inserts semicolon.
}
{
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-plugin-prettier",
"tslint-config-prettier"
],
"rulesDirectory": [],
"rules": {
"prettier": true,
"interface-name": false,
"quotemark": [true, "single"],
"semicolon": [true, "always", "ignore-bound-class-methods"] // Doesn't work
}
}
{
"jsxSingleQuote": true,
"singleQuote": true,
"semi": false // Disable everything
}
// appbar.tsx
const makeStyles((theme) => ({}) // Prettier removes semicolon here. Which is not OK. need to keep semicolon
export class AppBar {
private handleOpen = (event: Event): void => {
event.preventDefault();
this.props.onOpen();
}
}
import React from 'react' // Disabling in .prettierrc removes semicolon in everywhere.
your tslint.json file seems to be okay, I have to ask though are you sure you installed tslint-config-prettier?你的 tslint.json 文件似乎没问题,我不得不问你确定你安装了 tslint-config-prettier 吗? and I also don't think you need to add in your rules "prettier": true
而且我也不认为您需要在规则中添加“更漂亮”:true
here's a link to the official documentation这是官方文档的链接
https://developer.aliyun.com/mirror/npm/package/tslint-config-prettier . https://developer.aliyun.com/mirror/npm/package/tslint-config-prettier 。
hope this helps though希望这会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.