ESLint: Typescript + React + TSX 集成
2020-02-08
最新的版本对 TS 的支持非常完善, 绝大多数的问题都是由于安装了旧版本或者版本不兼容.
当前版本: ESLint 6.8.0
2020.02.09 更新
- 首先更新 Eslint 到最新版本, 为了省去后续的一切不必要的麻烦
- VSC 会默认调用 global 的 EsLint, 所以建议将全局的 EsLint 更新到最新版本
- 为了防止后续版本冲突本地的 package.json 最好也保留一个相同版本
- 跑到项目根目录执行
./node_modules/.bin/eslint --init
- 如果你希望使用现成的规则, 那么对于第一个选项 How would you like to use ESLint?
- 必须选择 To check syntax, find problems, and enforce code style
- 然后选择使用了 Typescript
- 然后 eslint 会引导你使用 npm 下载对应的包。或者你也可以不让他下载而手动使用 yarn 安装
yarn add [email protected]^7.14.3 @typescript-eslint/[email protected] [email protected] [email protected]^5.16.0 || ^6.1.0 [email protected]^2.18.2 [email protected]^6.2.3 [email protected]^1.7.0 @typescript-eslint/[email protected] --dev
本地安装这些包, ** 不要安装到 global**
- [email protected]^7.14.3
- @typescript-eslint/[email protected]
- [email protected]
- eslint
- [email protected]^2.18.2
- [email protected]^6.2.3
- [email protected]^1.7.0
以及一些可能需要的其他 Package
- @typescript-eslint/parser
- eslint-plugin-import
- eslint-plugin-jsx-a11y
这些包安装完之后到 CLI 执行
./node_modules/.bin/eslint index.tsx
试一试
依然遇到问题? 参考这篇文章: ESLint Troubleshooting
关于本文
- 文章标题: ESLint: Typescript + React + TSX 集成
- 发布日期: 2020-02-08
- 文章分类: Tech
- 相关标签: ReactESlintTypeScriptTSTSX
留言板
正在加载 评论框