eslint-unused-imports 移除用不到的 imports

eslint 自动移除用不到的 import

01 安装 eslint/eslint plugin

安装包

yarn add --dev plugin-unused-imports

02 核心配置如下

eslint.config.js,文件名可能不是这个

import unusedImports from "eslint-plugin-unused-imports";

export default [{
    plugins: {
        "unused-imports": unusedImports,
    },
    rules: {
        "no-unused-vars": "off", // or "@typescript-eslint/no-unused-vars": "off",
        "unused-imports/no-unused-imports": "error",
        "unused-imports/no-unused-vars": [
            "warn",
            {
                "vars": "all",
                "varsIgnorePattern": "^_",
                "args": "after-used",
                "argsIgnorePattern": "^_",
            },
        ]
    }
}];

03 应用效果

提交前
提交之后的效果
eslint unused imports