Lan*_*ard 14 typescript eslint visual-studio-code
到目前为止,Eslint 正在自动修复和清理我的代码。但现在我添加了这两个 eslint 插件:
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
我在.eslintrc.json以下rules部分中使用了它们:
"simple-import-sort/imports": [
  "error",
  {
    "groups": [
      [
        "^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)"
      ],
      ["^\\w"],
      ["^@"],
      ["^\\u0000"],
      ["^\\.\\.(?!/?$)", "^\\.\\./?$"],
      ["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"]
    ]
  }
],
"simple-import-sort/exports": [
  "error",
  {
    "groups": [
      [
        "^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)"
      ],
      ["^\\w"],
      ["^@"],
      ["^\\u0000"],
      ["^\\.\\.(?!/?$)", "^\\.\\./?$"],
      ["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"]
    ]
  }
],
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error"
我也有:
"plugins": [
  "@typescript-eslint",
  "import",
  "simple-import-sort"
],
为什么它不在保存时自动修复导入?
我的.vscode/settings.json是这样的,它允许修复保存:
{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "eslint.format.enable": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.validate": ["javascript", "typescript"],
  "eslint.nodePath": "./node_modules/eslint",
  "eslint.packageManager": "npm"
}