VS Code的ESLint扩展是否会使用项目中的.eslintrc.json配置文件?
VS Code安装ESLint扩展后是否会自动识别已配置的TypeScript ESLint文件?
已完成的配置步骤
你已经为TypeScript项目完成了以下ESLint配置:
- 安装依赖包:
npm install eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser --save-dev - 在
package.json中添加lint脚本:"scripts": { "lint": "eslint src/**/*.ts" } - 创建了
.eslintrc.json配置文件:{ "parser": "@typescript-eslint/parser", "parserOptions": { "project": "./tsconfig.json" }, "plugins": ["@typescript-eslint"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], "rules": { // Add your custom rules here } }
回答
VS Code的ESLint扩展会自动识别并使用你已创建的.eslintrc.json配置文件,无需在VS Code中重新配置。不过有几个细节需要留意:
- 确保VS Code打开的工作区根目录就是项目根目录(即
.eslintrc.json和package.json所在的目录),如果打开的是子文件夹,扩展可能无法定位到配置文件。 - 如果扩展未自动生效,可以重启VS Code,或者通过快捷键
Ctrl+Shift+P打开命令面板,执行ESLint: Restart ESLint Server命令重新加载配置。 - 检查VS Code的ESLint扩展设置,确认没有手动指定其他配置文件路径——默认情况下,扩展会自动扫描项目根目录下的各类ESLint配置文件(包括
.eslintrc.json、.eslintrc.js等)。
内容的提问来源于stack exchange,提问作者Ahmed Ghrib
相关产品推荐
相关产品推荐

