简体   繁体   English

将eslint安装为扩展和安装为npm package有什么区别?

[英]What is the difference between installing eslint as extension and installing as npm package?

I have been following various blogs and videos on setting up and configuring eslint and prettier for vscode and development .我一直在关注有关为 vscode 和开发设置和配置 eslint 和 prettier 的各种博客和视频。 But every article fails to explain why do we need to separately install eslint as an npm package and vs code extension?但是每篇文章都没有解释why do we need to separately install eslint as an npm package and vs code extension?

what difference it will make if I install either of the ones?如果我安装其中任何一个,会有什么不同?

why do we need to separately install eslint as npm package and vscode extension?为什么我们需要单独安装eslint as npm package 和vscode扩展?

Short answer: you don't.简短的回答:你没有。

Long answer:长答案:

Installing ESLint/Prettier as extension, allows you to format/check your code inside the VSCode.安装 ESLint/Prettier 作为扩展,允许您在 VSCode 中格式化/检查您的代码。

However, installing them also as dependencies brings extra benefits:但是,将它们也作为依赖项安装会带来额外的好处:

  • VSCode will use exact same package as installed. VSCode 将使用与安装时完全相同的 package。 So you will not spot the situation when VSCode says OK, but your CI server says: NOT OK所以当 VSCode 说 OK 时你不会发现这种情况,但是你的 CI 服务器说:NOT OK
  • You will get control over the versions, and can update whenever you want您将控制版本,并可以随时更新
  • You will be able to use different versions for different projects.您将能够为不同的项目使用不同的版本。 This is especially important, when you can't migrate old project, but want to use the latest possibilities for the new one当您无法迁移旧项目,但想为新项目使用最新的可能性时,这一点尤其重要
  • You will be able to access Prettier/ESlint through the script block of the package.json , and be able to write custom commands with parameters exactly as you need您将能够通过 package.json 的script块访问 Prettier/ package.json ,并能够根据需要编写带有参数的自定义命令
  • You will be able to pair them with Husky or NPM hooks to automatically verify/format the code您将能够将它们与 Husky 或 NPM 挂钩配对以自动验证/格式化代码

From my experience, if you can install something locally - install it as package dependency (except CLI like create-react-app or angular-cli that helps you start the app).根据我的经验,如果你可以在本地安装一些东西——将它安装为 package 依赖项(除了像 create-react-app 或 angular-cli 这样的 CLI 可以帮助你启动应用程序)。 This will make your life a bit predictable.这会让你的生活有点可预测。

These programs can format your code (ESLint and Prettier) and detect specific syntax (ESLint).这些程序可以格式化您的代码(ESLint 和 Prettier)并检测特定语法(ESLint)。

When installed as an extension in your IDE (vscode for example), you can get:当作为扩展安装在你的 IDE(例如 vscode)中时,你可以获得:

  • squiggly lines in real time;实时波浪线;
  • and format-on-save.和格式保存。

But someone who starts up your project on their own environment might not have these extensions installed (might not even have the same IDE) and thus might not get these.但是在他们自己的环境中启动您的项目的人可能没有安装这些扩展(甚至可能没有相同的 IDE),因此可能无法获得这些扩展。

When installed as npm packages (and included somewhere in the pipeline, either in the npm start, or in your continuous deployment, or...)当作为 npm 包安装时(并包含在管道中的某处,或者在 npm 开始,或者在你的持续部署中,或者......)

  • you won't get real time squiggly lines,你不会得到实时的波浪线,
  • but you can still get auto-formatting (though not necessarily on save, depending on the configuration),但你仍然可以获得自动格式化(虽然不一定在保存时,取决于配置),
  • you can get blocking rules (meaning instead of just seeing errors / warnings, you can actually block the pipelines until the dev fixes said errors / warnings)您可以获得阻止规则(这意味着您不仅可以看到错误/警告,还可以实际阻止管道,直到开发人员修复所述错误/警告)
  • you can insure anyone who starts the project, from any IDE, gets the packages included您可以确保从任何 IDE 开始该项目的任何人都能获得包含的软件包

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

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