在Visual Studio 2022中能否将整个文件夹排除在Code Cleanup范围外?
配置Code Cleanup排除指定文件夹运行
根据截图显示,需要排除的黄色高亮文件夹为node_modules和dist,以下是几种主流场景下的实现方法:
VS Code 内置/插件配置
- 打开设置面板(快捷键
Ctrl+,或Cmd+,),搜索对应Code Cleanup工具的排除设置; - 直接编辑
settings.json,以ESLint为例添加排除规则(多数代码清理工具逻辑通用):"eslint.exclude": [ "**/node_modules/**", "**/dist/**" ]
命令行工具执行方式
如果通过prettier、eslint等命令行工具执行代码清理,可直接在命令中指定排除目录:
- Prettier示例:
npx prettier --write . --exclude '**/node_modules/**' --exclude '**/dist/**' - ESLint示例:
npx eslint . --ignore-pattern 'node_modules/' --ignore-pattern 'dist/'
配置文件定义排除规则
在项目根目录创建对应工具的忽略配置文件,写入需要排除的文件夹即可:
- 对于Prettier,创建
.prettierignore文件:node_modules/ dist/ - 对于ESLint,创建
.eslintignore文件,内容同上。
内容的提问来源于stack exchange,提问作者papps
相关产品推荐
相关产品推荐

