typescript - VSC 中的 ESLint 不适用于 .ts 和 .tsx 文件
问题描述
我在 VSC 中安装了 ESLint 扩展,它适用于 .js 文件。现在我已经在我的 React 项目中引入了 Typescript,ESLint 不再在 VSC 中运行。
我的项目根目录中有一个 .eslintrc 文件,如下所示:
{
"parser": "@typescript-eslint/parser",
"extends": [
"airbnb",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true,
"node": true,
"serviceworker": true
},
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"rules": {
"@typescript-eslint/indent": ["error", 2],
"indent": "off",
"jsx-a11y/anchor-is-valid": ["error", {
"aspects": ["invalidHref", "preferButton"]
}],
"no-console": ["error", {
"allow": ["error", "info"]
}],
"react/no-danger": 0
}
}
我有一个如下所示的 npm 脚本:
"scripts": {
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
},
如果我运行npm run eslint
,整个项目都会被正确地整理。我需要做些什么才能让项目在 VSC 中使用红色波浪线即时进行 lint?
解决方案
假设您已eslint
在 Visual Studio Code 上安装了扩展,您应该将以下内容添加到您的设置中。
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
],
这将使 eslint 查看 typescript 文件以及 javascript 文件。
推荐阅读
- html - 使子元素不受父元素旋转的影响
- maven - 使用 settings.xml 中的变量,但使用 Maven 中的环境变量覆盖
- node.js - 从外部库记录到不显示“警告”日志
- c# - 如何在连接子句中使用 OR 条件使用 LINQ 查询
- wordpress - 发布帖子时对元数据执行 do_action 以更改其他帖子的元数据
- javascript - 为什么我需要用括号将属性传递给这个指令?
- bash - 更改每个子目录中每个文件的某些字符
- amazon-web-services - AWS Route53 ConflictingDomainExists:有没有办法将同一个 VPC 与共享同一个父域的多个私有托管区域相关联
- redis - Lettuce 连接的缩放限制
- python - Groupby 在 2 列上并将一列拆分为具有前 2 个非 Na 值的 2 列