我使用 Create React Apps 的 Typescript 模板创建了一个 React 项目,为 ESLint 添加了必要的插件并将6.8.0
ESLint 和 prettier 配置在一起,但是每当我编辑.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
(我在 Windows 上)"files.eol": "\r\n",
即使我尝试使用不同的行尾,我也会遇到类似的错误。
如果我做
"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"
}
}
}