首页 > 解决方案 > 偶尔在保存导入时添加MissingImports 再次反应

问题描述

我正在使用 typescript 和 *.tsx 文件,尤其是当我复制代码时,它通常会添加一个额外的

import React from "react";
    // ? On Save
    "editor.codeActionsOnSave": {
        "source.addMissingImports": true,
        "source.fixAll.eslint": true
        // "source.organizeImports": true
    }

标签: javascriptreactjstypescriptvisual-studio-code

解决方案


我正在使用此配置并且工作正常。

扩展名.json

{
  "recommendations": [
    "amatiasq.sort-imports",
    "dbaeumer.vscode-eslint",
    "eamodio.gitlens",
    "eg2.vscode-npm-script",
    "esbenp.prettier-vscode",
    "github.copilot",
    "github.vscode-pull-request-github",
    "ibm.output-colorizer",
    "mhutchie.git-graph",
    "ms-azuretools.vscode-docker",
    "ms-kubernetes-tools.vscode-kubernetes-tools",
    "ms-playwright.playwright",
    "ms-vscode-remote.vscode-remote-extensionpack",
    "pkief.material-icon-theme",
    "quicktype.quicktype",
    "redhat.vscode-yaml",
    "ryanluker.vscode-coverage-gutters",
    "streetsidesoftware.code-spell-checker",
    "stylelint.vscode-stylelint",
    "tyriar.sort-lines"
  ]
}

设置.json

{
  "[javascript]": {
    "editor.formatOnSave": false
  },
  "[javascriptreact]": {
    "editor.formatOnSave": false
  },
  "[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "[typescript]": {
    "editor.formatOnSave": false
  },
  "[typescriptreact]": {
    "editor.formatOnSave": false
  },
  "diffEditor.ignoreTrimWhitespace": false,
  "editor.bracketPairColorization.enabled": true,
  "editor.codeActionsOnSave": {
    "source.addMissingImports": true,
    "source.fixAll": false,
    "source.fixAll.eslint": true,
    "source.organizeImports": false
  },
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnPaste": false,
  "editor.formatOnSave": true,
  "editor.guides.bracketPairs": "active",
  "editor.inlineSuggest.enabled": true,
  "editor.suggestSelection": "first",
  "editor.tabSize": 2,
  "eslint.alwaysShowStatus": true,
  "eslint.format.enable": true,
  "eslint.probe": [
    "html",
    "javascript",
    "javascriptreact",
    "markdown",
    "typescript",
    "typescriptreact"
  ],
  "files.watcherExclude": {
    "**/*.pem": true,
    "**/*.tsbuildinfo": true,
    "**/.DS_Store": true,
    "**/.env.development.local": true,
    "**/.env.local": true,
    "**/.env.production.local": true,
    "**/.env.test.local": true,
    "**/.next/**": true,
    "**/.pnp.js": true,
    "**/.pnp/**": true,
    "**/.vercel": true,
    "**/build/**": true,
    "**/coverage/**": true,
    "**/node_modules/**": true,
    "**/npm-debug.log*": true,
    "**/out/**": true,
    "**/yarn-debug.log*": true,
    "**/yarn-error.log*": true
  },
  "github.copilot.enable": {
    "*": true,
    "markdown": false,
    "plaintext": true,
    "yaml": true
  },
  "redhat.telemetry.enabled": true,
  "sort-imports.ignore-type-defs": false,
  "stylelint.validate": [
    "css",
    "scss"
  ],
  "terminal.integrated.sendKeybindingsToShell": true,
  "window.zoomLevel": 1,
  "workbench.iconTheme": "material-icon-theme"
}

推荐阅读