我要求 运行 autofix 对这些导入进行排序!不久前,我在 TypeScript 中的 eslint simple-import-sort/imports 插件上使用过,但现在我已经一切正常了。如果我运行 eslint --ext .tsx,.ts . --fix
它会修复文件,但是当我手动保存这个特定文件时,它会恢复,然后显示错误。 (请注意,当我按 CMD+S 时,图像中它是如何闪烁的)。
运行 autofix 对这些进行排序
imports!eslintsimple-import-sort/imports
。
.eslintrc.json
:
{
"env": {
"browser": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": ["./tsconfig.json"]
},
"overrides": [
{
"files": ["*.yaml", "*.yml"],
"parser": "yaml-eslint-parser"
}
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"import",
"simple-import-sort",
"sort-exports",
"typescript-sort-keys",
"sort-keys",
"prettier",
"unused-imports"
],
"extends": [
"prettier",
"next",
"plugin:import/recommended",
"plugin:import/typescript"
],
"rules": {
"curly": 2,
"@typescript-eslint/quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"@typescript-eslint/no-unnecessary-condition": 0,
"@typescript-eslint/array-type": [
2,
{
"default": "generic"
}
],
"react/display-name": "off",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/consistent-type-definitions": 0,
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/method-signature-style": "error",
"@typescript-eslint/naming-convention": 0,
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-useless-empty-export": "error",
"@typescript-eslint/prefer-function-type": "error",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error",
"no-throw-literal": "off",
"@typescript-eslint/no-throw-literal": "error",
"lines-between-class-members": "off",
"@typescript-eslint/lines-between-class-members": "error",
"object-curly-spacing": "off",
"@typescript-eslint/object-curly-spacing": [2, "always"],
"padding-line-between-statements": "off",
"@typescript-eslint/padding-line-between-statements": [
"error",
{
"blankLine": "always",
"prev": "*",
"next": ["type"]
}
],
"space-before-blocks": "off",
"@typescript-eslint/space-before-blocks": ["error", "always"],
"@typescript-eslint/type-annotation-spacing": [
"error",
{ "after": true }
],
"import/no-duplicates": "error",
"sort-exports/sort-exports": "off",
"typescript-sort-keys/interface": "off",
"typescript-sort-keys/string-enum": "off",
"sort-keys": "off",
"sort-keys/sort-keys-fix": "off",
"prettier/prettier": 2,
"@typescript-eslint/no-unused-vars": "off",
"default-case": "off",
"default-case-last": "off",
"unused-imports/no-unused-imports": "error",
"simple-import-sort/imports": [
"error",
{
"groups": [
["^react$", "^next", "^[a-z]"],
["^@"],
["^~"],
["^\\.\\.(?!/?$)", "^\\.\\./?$"]
]
}
]
}
}
这是我的.vscode/settings.json
:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always",
"source.sortMembers": "always"
},
"css.lint.unknownAtRules": "ignore",
"eslint.validate": ["javascript", "typescript"],
"eslint.nodePath": "./node_modules/eslint",
"emmet.showExpandedAbbreviation": "never",
"editor.quickSuggestions": {
"other": "on",
"comments": "off",
"strings": "on"
},
"eslint.workingDirectories": [{ "mode": "auto" }]
}
我必须有冲突的规则或某些东西,但我已经尝试了很多事情(删除这个和那个eslint规则),但除了将排序导入规则设置为off
(我不这样做)之外,没有任何效果不想要,我想要自动修复导入)。
你可以尝试一下