我使用Create React应用程序的Typescript模板创建了一个React项目,为ESLint 6.8.0添加了必要的插件,并配置了ESLint和prettier,但每当我编辑.ts或.tsx文件时,我都会收到ESLint Error 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设置中的所有内容,以便在"files.eol": "\r\n",中使用CRLF (我在Windows上
即使我尝试使用不同的行尾,也会得到类似的错误。
如果我这样做了
"prettier/prettier": [
"error",
{
"endOfLine": "lf"
},
{ "usePrettierrc": true }
],

如果我设置endOfLine : crlf,它和auto的错误是一样的!
这里有价值的是我的整个.eslintrc.json
{
"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"
}
}
}发布于 2021-02-18 02:30:15
由于这篇文章获得了一些流量,我通过将这个规则添加到我的eslint配置中解决了这个问题
rules: {
'prettier/prettier': ['off', { singleQuote: true }],
}这里的关键部分是'off',当您将其设置为'error'时,默认情况下会显示此错误。将其设置为off将禁用该检查。
https://stackoverflow.com/questions/63190725
复制相似问题