仅删除 TS/TSX 个文件的 CR - VSCode 1.46 上的 Prettier ESLint
Delete CR only for TS/TSX files - Prettier ESLint on VSCode 1.46
我使用 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"
}
}
}
由于此 post 获得了一些流量,我通过将此规则添加到我的 eslint 配置来解决此问题
rules: {
'prettier/prettier': ['off', { singleQuote: true }],
}
此处的关键部分是 'off'
,当您将其默认设置为 'error'
时,会出现此错误。将其关闭会禁用该检查。
您还可以更改行尾的 VS 代码设置:
- 按 F1
- select“更改行尾顺序”
- select“LF”而不是“CRLF”
瞧!
我使用 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"
}
}
}
由于此 post 获得了一些流量,我通过将此规则添加到我的 eslint 配置来解决此问题
rules: {
'prettier/prettier': ['off', { singleQuote: true }],
}
此处的关键部分是 'off'
,当您将其默认设置为 'error'
时,会出现此错误。将其关闭会禁用该检查。
您还可以更改行尾的 VS 代码设置:
- 按 F1
- select“更改行尾顺序”
- select“LF”而不是“CRLF”
瞧!