Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install ESlint globally?

Tags:

I'm trying to install ESlint to use it with Sublime Text 2 for all my local projects. Configuration documentation is very unclear about global installation:

Note: eslint --init is intended for setting up and configuring ESLint on a per-project basis and will perform a local installation of ESLint and its plugins in the directory in which it is run. If you prefer using a global installation of ESLint, any plugins used in your configuration must also be installed globally.

I don't understand what they mean. I used eslint --init and it installed ESlint locally in node_modules, along with all plugins. There's nothing explained about installing plugins globally. How do I do that? Also, how do I use the global ESlint installation if eslint --init installs local one anyway? This is so confusing.

like image 264
Robo Robok Avatar asked Mar 12 '18 02:03

Robo Robok


People also ask

How do I install ESLint globally with Yarn?

Make sure your plugins (and ESLint) are both in your project's package. json as devDependencies (or dependencies, if your project uses ESLint at runtime). Make sure you have run npm install and all your dependencies are installed. Make sure your plugins' peerDependencies have been installed as well.

How do I enable global ESLint in VSCode?

ESLint inside VSCode Simply open up VSCode and open the Extensions from the sidebar. Search for ESLint and install the extension. That's it! You should now be able to use ESLint inside Visual Studio Code!

What is npm install ESLint?

ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions: ESLint uses Espree for JavaScript parsing. ESLint uses an AST to evaluate patterns in code.


1 Answers

You can install Node modules within the project (locally) or globally. To switch to globally, you may use the -g flag, like so:

npm install -g eslint

Then see if it's working without Sublime Text (-v flag to see the version of eslint):

eslint -v

To see where it was installed (assuming MacOS/Linux):

which eslint

Then see if it's working in Sublime Text (you may need to restart Sublime first). If it's not working, make sure in the eslint package settings that the path is correct.

like image 66
Winfried Avatar answered Sep 19 '22 19:09

Winfried