Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. But every article fails to explain 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?

like image 715
Jatin Mehrotra Avatar asked Aug 10 '21 04:08

Jatin Mehrotra


People also ask

What is ESLint extension in VS Code?

Using ESLint to validate TypeScript files Especially make sure that you can validate TypeScript files successfully in a terminal using the eslint command. This project itself uses ESLint to validate its TypeScript files. So it can be used as a blueprint to get started.

How do you use ESLint extension in VS Code?

Configure VSCode Settings to use ESLint for Formatting Click that tiny icon in the top-right that looks like a piece of paper with a little arrow. The first one turns on ESLint for formatting, and the next 3 make it do the formatting when you hit save. That should do it! Save the settings file and close it, we're done.

How do I know if ESLint is working?

Open the command palette ( Ctrl / Cmd + Shift + P ) and select ESLint: Manage Library Execution to open the dialog for your project and confirm with 'Accept'.


Video Answer


2 Answers

why do we need to separately install eslint as npm package and vscode extension?

Short answer: you don't.

Long answer:

Installing ESLint/Prettier as extension, allows you to format/check your code inside the VSCode.

However, installing them also as dependencies brings extra benefits:

  • VSCode will use exact same package as installed. So you will not spot the situation when VSCode says OK, but your CI server says: 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
  • You will be able to pair them with Husky or NPM hooks to automatically verify/format the code

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). This will make your life a bit predictable.

like image 172
Drag13 Avatar answered Dec 16 '22 21:12

Drag13


These programs can format your code (ESLint and Prettier) and detect specific syntax (ESLint).

When installed as an extension in your IDE (vscode for example), you can get:

  • 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.

When installed as npm packages (and included somewhere in the pipeline, either in the npm start, or in your continuous deployment, or...)

  • 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
like image 43
Sheraff Avatar answered Dec 16 '22 22:12

Sheraff