Grayscale profile picture

Patrique Ouimet

Senior Product Engineer

Sublime Text with SublimeLinter and ESLint through NVM

Tue, Aug 27, 2019 6:32 PM

Intro

This article will explain how to setup SublimeLinter with ESLint while using NVM (Node Version Manager) within Sublime as I had some issues setting this up, so I thought I would share.

Caveats

This article assumes you've already installed Sublime Text, Package Control, and NVM (Node Version Manager).

Installing SublimeLinter

Open the command palette (CMD + SHIFT + P on MacOS) type "Package Control: Install Package" press enter/return, then type in "SublimeLinter" and select it. It will open a readme should it install successfully.

NOTE: official documentation can be found here SublimeLinter

Installing ESLint

Open your terminal and run the following command

npm install -g eslint

NOTE: official documentation can be found here ESLint

Installing SublimeLinter-eslint

Open the command palette (CMD + SHIFT + P on MacOS) type "Package Control: Install Package" press enter/return, then type in "SublimeLinter-eslint" and select it (do not install the eslint_d version). It will open a readme should it install successfully.

NOTE: official documentation can be found here SublimeLinter

Configuring SublimeLinter with NVM

For this step you'll need to know the executable path for node and eslint. On Unix/Linux based systems you can run this in terminal:

which node
/Users/{your_user_name}/.nvm/versions/node/v11.13.0/bin/node

which eslint
/Users/{your_user_name}/.nvm/versions/node/v11.13.0/bin/eslint

NOTE: if you don't set it to a specific installed version you might get errors like:

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib

Now that you have the paths to the executables, open the command palette (CMD + SHIFT + P on MacOS) type "SublimeLinter Settings" press enter/return, it will open a file named SublimeLinter.sublime-settings - User. Then paste in your paths into the configuration file. It might look something like:

{
    "linters": {
        "eslint": {
            "disable": false,
            "args": [],
            "executable": [
                "/Users/{your_user_name}/.nvm/versions/node/v11.13.0/bin/node",
                "/Users/{your_user_name}/.nvm/versions/node/v11.13.0/bin/eslint"
            ],
            "excludes": [],
            "lint_mode": "background"
        }
    },
}

Once you've saved the file, close Sublime Text and reopen it.

Conclusion/Testing

Everything is setup, try opening a file and typing gibberish to see if ESLint shows you errors!

I hope you enjoyed the article and that it was helpful, if you'd like to cover another topic leave a comment or shoot me a tweet/dm on twitter @patoui2!

Happy coding :)