前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ESLint: Typescript + React + TSX 集成

ESLint: Typescript + React + TSX 集成

作者头像
szhshp
发布2022-09-21 10:26:17
8580
发布2022-09-21 10:26:17
举报
文章被收录于专栏:szhshp 的第四边境中转站

ESLint: Typescript + React 集成

最新的版本对 TS 的支持非常完善, 绝大多数的问题都是由于安装了旧版本或者版本不兼容. 当前版本: ESLint 6.8.0 2020.02.09 更新

  1. 首先更新 Eslint 到最新版本, 为了省去后续的一切不必要的麻烦
    • VSC 会默认调用 global 的 EsLint, 所以建议将全局的 EsLint 更新到最新版本
    • 为了防止后续版本冲突本地的 package.json 最好也保留一个相同版本
  2. 跑到项目根目录执行 ./node_modules/.bin/eslint --init
    • 如果你希望使用现成的规则, 那么对于第一个选项 How would you like to use ESLint?
    • 必须选择 To check syntax, find problems, and enforce code style
  3. 然后选择使用了 Typescript
  4. 然后 eslint 会引导你使用 npm 下载对应的包。或者你也可以不让他下载而手动使用 yarn 安装
    • yarn add eslint-plugin-react@^7.14.3 @typescript-eslint/eslint-plugin@latest eslint-config-airbnb@latest eslint@^5.16.0 || ^6.1.0 eslint-plugin-import@^2.18.2 eslint-plugin-jsx-a11y@^6.2.3 eslint-plugin-react-hooks@^1.7.0 @typescript-eslint/parser@latest --dev

需要安装的 packages

本地安装这些包, ** 不要安装到 global**

  • eslint-plugin-react@^7.14.3
  • @typescript-eslint/eslint-plugin@latest
  • eslint-config-airbnb@latest
  • eslint
  • eslint-plugin-import@^2.18.2
  • eslint-plugin-jsx-a11y@^6.2.3
  • eslint-plugin-react-hooks@^1.7.0

以及一些可能需要的其他 Package

  • @typescript-eslint/parser
  • eslint-plugin-import
  • eslint-plugin-jsx-a11y

这些包安装完之后到 CLI 执行 ./node_modules/.bin/eslint index.tsx 试一试

TroubleShooting

依然遇到问题? 参考这篇文章: ESLint Troubleshooting

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-02-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ESLint: Typescript + React 集成
  • 需要安装的 packages
  • TroubleShooting
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档