简体   繁体   English

使用eslint-plugin-compat和Babel一起使用

[英]Use eslint-plugin-compat alongside Babel

I have a webpack project that uses Babel for JavaScript transpilation. 我有一个使用Babel进行JavaScript转换的webpack项目。 To tell Babel which browsers to target when it transpiles my code, I use a .browserslistrc file. 要告诉Babel哪些浏览器在转换代码时要定位,我使用.browserslistrc文件。

I'm also interested in using the ESLint compatibility plugin, eslint-plugin-compat , which will warn you if you're using JS that is not compatible with the browsers you are targeting (the ESLint plugin also refers to the .browserslistrc file). 我也对使用ESLint兼容性插件eslint-plugin-compat感兴趣,如果你使用的JS与你所针对的浏览器不兼容,它会警告你(ESLint插件也指的是.browserslistrc文件) 。

So I went ahead and installed and added the plugin to my .eslintrc.js file, and it seems to be working fine. 所以我继续安装并将插件添加到我的.eslintrc.js文件中,它似乎工作正常。 But when I compile my webpack project, ESLint is pointing out features I'm using in my code, like Object.values() , that are not compatible with my target browsers. 但是当我编译我的webpack项目时,ESLint指出了我在我的代码中使用的功能,比如Object.values() ,这些功能与我的目标浏览器不兼容。 Well yeah, I know that - that's why I'm using Babel, so those features are converted to ones that are compatible for the browsers I'm targeting. 嗯,是的,我知道 - 这就是为什么我使用Babel,所以这些功能转换为与我所针对的浏览器兼容的功能。

So maybe I'm missing a key point here somewhere. 所以也许我在这里错过了一个关键点。 If I'm using Babel already to transpile to compatible code in the browsers I'm targeting, is there still any use for eslint-plugin-compat in my build process? 如果我已经使用Babel转换为我所针对的浏览器中的兼容代码,那么在我的构建过程中是否还有任何eslint-plugin-compat用途?

I think you should rather use babel-eslint , which 我认为你应该选择使用babel-eslint

allows you to lint ALL valid Babel code with the fantastic ESLint. 允许您使用梦幻般的ESLint来提示所有有效的Babel代码。

I am just planning to make this change, so I don't have any experience with it, but should mean that it makes eslint-plugin-compat unnecessary, as no "invalid" code should go to the bundle. 我只是计划进行此更改,因此我没有任何使用它的经验,但应该意味着它使eslint-plugin-compat变得不必要,因为没有“无效”代码应该转到捆绑包。

But on the other hand, still there are useful hints from eslint-plugin-compat , like window.screenLeft() is not supported in Firefox XY . 但在另一方面,仍然来自有用的提示eslint-plugin-compat ,像window.screenLeft() is not supported in Firefox XY Disqualifying eslint-plugin-compat would also skip these hints in my opinion. 在我看来,取消资格eslint-plugin-compat也会跳过这些提示。

Update You can track this on https://github.com/amilajack/eslint-plugin-compat/issues/174 更新您可以在https://github.com/amilajack/eslint-plugin-compat/issues/174上进行跟踪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM