babel-eslint 的状态
babel-eslint 被移动到 @babel/eslint-parser 了!
过去
🌐 The Past
作为 Babel 和 ESLint 之间的兼容层——这两个项目由两个不同的团队维护——babel-eslint 从一开始就是一个难以维护的包。团队在维护 babel-eslint 时面临的一些挑战包括:
🌐 Existing as a compatibility layer between Babel and ESLint – two projects maintained by two separate teams – babel-eslint has been a difficult package to maintain since the beginning. Some of the challenges the team has faced while maintaining babel-eslint:
babel-eslint历来由 Babel 团队维护,确保 ESLint 的核心规则(每两周发布一次)能够与实验性语法兼容是一项巨大的任务。- Babel 的内部 AST 表示与 ESLint 使用的 AST 规范 ESTree 不同。因此,要兼容 ESLint,Babel 的解析器需要有一个插件,能够输出与 ESTree 兼容的 AST。
- 虽然 Babel 允许使用实验性语法,但 ESLint 核心只有在语法达到 Stage 4 并在规范中最终确定后才支持。这意味着 ESLint 的核心规则并不是为 Stage 3 及以下的语法设计的。此外,由于 ESTree 规范的最终确定,ESLint 也受到了限制,这导致两个项目支持的语法差异更大。
babel-eslint依赖的 Babel 解析器版本是其package.json的直接依赖,而且它启用的插件是硬编码的,这可能导致编译和 lint 时在版本和启用的语言特性上不匹配。这过去常常引起很多混乱和难以调试的问题,我们认为解决这个问题对维护者和终端用户来说都是一大好处。babel-eslint必须更新以应对上游两个项目的变动,而且它常常与其中某一个项目不同步。
上述挑战累计达到了babel-eslint,需要的资源超过了团队现有的能力,导致babel-eslint没有得到一款广泛使用的项目(在撰写本文时每周有600万次下载)所需的关注,以保持更新。
🌐 The challenges above have added up to babel-eslint requiring more resources than the team has at its disposal, resulting in babel-eslint not getting the attention a widely used project (6M downloads a week at the time of this writing) requires to stay up-to-date.
现在
🌐 The Present
在下一版的 babel-eslint 中,我们决定以新的名字 @babel/eslint-parser 发布这个包。为了减轻上面讨论的一些问题,我们正在做以下几件事:
🌐 With the next iteration of babel-eslint, we have decided to publish the package under a new name: @babel/eslint-parser. To alleviate some of the challenges discussed above, we are doing the following:
@babel/eslint-parser将需要@babel/core作为同级依赖,并且现在会使用 Babel core 的 API 来读取和应用你的 Babel 配置。这意味着在编译和代码检查时会使用相同版本的 Babel 和相同的设置。这与我们在 Babel 生态系统中对其他包的推荐和做法是一致的。@babel/eslint-parser将会和其他 Babel 包一起存放在主babel/babelmonorepo 中。我们希望这能帮忙缓解babel-eslint过去遇到的一些同步问题,并且让我们能够用 GitHub 上的最新源码来检查这个仓库,从而缩短 Babel 的改动对代码检查影响的反馈周期。- ESTree——ESLint 遵循的 AST 规范——最近重新活跃起来了,而且 Babel 团队现在也在积极参与这个项目。希望这能让我们分享关于实验语法的 AST 表示的学习成果,并帮助工具之间的集成变得更容易。
- Kai Cataldo 多年来一直在帮忙处理
babel-eslint的相关工作,由于他同时是 Babel 和 ESLint 的维护者,因此在关注这两个工具的互操作性方面有独特的优势。在过去几个月里,他一直在进行上文提到的代码更改,并将在新包发布后继续提供支持。
未来
🌐 The Future
我们认为这些包已经可以发布了。因为涉及到的集成和项目很多(Babel、ESLint、Prettier、各类框架、各种插件、文本编辑器集成、命令行工具等等),我们确定会有一些需要修复的地方,所以我们计划快速迭代。
🌐 We believe that these packages are ready to be released. Because of all the integrations and projects involved (Babel, ESLint, Prettier, frameworks, various plugins, text editor integrations, command-line tools, etc.), we're sure there will be things that need to be fixed, and we plan to iterate quickly.
请注意,@babel/eslint-parser 将依赖 @babel/core 作为同级依赖,并且这个包必须在你项目的 node_modules 中。
🌐 Please note that @babel/eslint-parser will rely on @babel/core as a peer dependency and this package must be in your project's node_modules.
一旦你确认 @babel/core 已经安装好,你就可以运行以下命令,将 babel-eslint 和 babel-eslint-plugin 升级到新的软件包:
🌐 Once you have ensured that @babel/core has been installed, you can run the following commands to upgrade from babel-eslint and babel-eslint-plugin to the new packages:
- npm
- Yarn
- pnpm
- Bun
npm uninstall babel-eslint babel-eslint-plugin
npm install --save-dev @babel/eslint-parser @babel/eslint-plugin
yarn remove babel-eslint babel-eslint-plugin
yarn add --dev @babel/eslint-parser @babel/eslint-plugin
pnpm remove babel-eslint babel-eslint-plugin
pnpm add --save-dev @babel/eslint-parser @babel/eslint-plugin
bun remove babel-eslint babel-eslint-plugin
bun add --dev @babel/eslint-parser @babel/eslint-plugin
module.exports = {
--- parser: "babel-eslint",
+++ parser: "@babel/eslint-parser"
plugins: [
--- "babel"
+++ "@babel
]
};
@babel/eslint-parser 期望一个标准的 Babel 配置文件(.babelrc 或 babel.config.js)。对于那些可能不想使用 Babel 配置文件,或者通过其他工具(例如带有 babel-loader 的 Webpack)运行 Babel 的情况,@babel/eslint-parser 也支持通过你的 ESLint 配置来应用 Babel 配置。更多细节请查看 babelOptions 配置选项。
一起向前走
🌐 Moving Forward Together
我们制定上述更改的短期目标是让 @babel/eslint-parser 更易于维护,并且让使用 ESLint 对 Babel 编译的代码进行 lint 检查更简单、更可靠。我们非常希望你能参与这项工作!在 GitHub 上的贡献以及 经济捐助 都能极大地帮助我们让这次集成为社区做到最好。
🌐 Our short-term goal in making the changes outlined above is to make it easier for @babel/eslint-parser to maintain and to make linting Babel-compiled code with ESLint easier and more reliable. We would love your help in this endeavor! Contributions on GitHub and financial donations go a long way in helping us make this integration the best it can be for the community.