我使用Create React Apps的Typescript模板创建了一个React项目,为ESLint 6.8.0
添加了必要的插件,并一起配置了ESLint和漂亮,但是每当我编辑.ts
或.tsx
文件时,得到ESLint错误Delete
␍⏎␍⏎``
我在VSCode中同时安装了ESLint和Prettier扩展
我检查了SO上的其他各种帖子,并尝试了提到的大多数设置,
我将此添加到了.eslintrc.json
文件中
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
},
{ "usePrettierrc": true }
],
这是我的.prettierrc
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": true,
"semi": true,
"singleQuote": true,
"jsxBracketSameLine": false,
"printWidth": 80,
"endOfLine": "auto"
}
但是,每当在.ts / .tsx文件中创建新行时,仍然出现lint错误
我更改了VSCode设置中的所有内容,以将CRLF
与"files.eol": "\r\n",
一起使用"prettier/prettier": [
"error",
{
"endOfLine": "lf"
},
{ "usePrettierrc": true }
],
(在Windows上)
即使我尝试使用不同的行尾,也会出现类似的错误。
如果我愿意
endOfLine : crlf
如果我将.eslintrc.json
设置为与auto相同的错误!
这是我整个{
"env": {
"browser": true,
"es6": true,
"jest": true
},
"extends": [
"standard",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended",
"plugin:jsx-a11y/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"__DEV__": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"project": "tsconfig.json",
"tsconfigRootDir": "."
},
"plugins": ["react", "react-hooks", "@typescript-eslint", "prettier"],
"rules": {
"camelcase": "off",
"no-unused-expressions": "off",
"react/prop-types": "off",
"react/jsx-one-expression-per-line": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/jsx-filename-extension": [
1,
{
"extensions": [".tsx"]
}
],
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "_"
}
],
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
// Remove after
"@typescript-eslint/no-empty-interface": "off",
"jsx-a11y/no-static-element-interactions": "off",
"jsx-a11y/click-events-have-key-events": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "crlf"
},
{ "usePrettierrc": true }
],
// Remove After
"jsx-quotes": "warn",
"import/prefer-default-export": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never",
"tsx": "never"
}
]
},
"settings": {
"import/resolver": {
"typescript": {}
},
"react": {
"version": "detect"
}
}
}
// Enables or disables the HTTP/2 support in secure connections
// http://nginx.org/en/docs/http/ngx_http_v2_module.html
// Default: true
UseHTTP2 bool `json:"use-http2,omitempty"`
答案 0 :(得分:9)
由于这篇文章获得了一些流量,我通过将此规则添加到我的 eslint 配置中来解决此问题
rules: {
'prettier/prettier': ['off', { singleQuote: true }],
}
此处的关键部分是 'off'
,默认情况下将其设置为 'error'
时会出现此错误。将其关闭将禁用该检查。