SonarLint VSCode Extension with NVM | CG4 Dev

SonarLint VSCode Extension with NVM

published: July 4, 2024

Better Code

You and I, like many before us, decide that we should use a tool to help with code quality and alert you when you’ve achieved a certain complexity. For many, eslint does most of what you want. I use eslint, prettier, typescript; and finally I added SonarLint as another tool to help me achieve that *chef’s kiss code aesthetic.

Add the Extension

To add the extension first bring up the command palette cmd + shift + p and then type Extensions: Install Extensions this will bring open the extensions search panel. Search for SonarLint and install the one that is from SonarSource.

Users with one version of Node installed this is all you have to do. You’re set!

Node Version Manager (NVM)

For users with nvm installed switching between multiple projects with multiple versions of legacy node, there is one more step that you have to complete and it’s slightly tricky. Or at least it was tricky for me because I assumed I would have to map to the node directory.

With nvm installed you need to point sonarlint to nvm instead of node. To do this bring open settings cmd + , and honestly click the little paper file icon in the upper right corner to edit the JSON file.

Append the following line:

{@html `"sonarlint.pathToNodeExecutable": "/Users/<your-user>/.nvm/versions/node/v20.13.1/bin/node"`}

And now you are all done, SonarLint extension is ready to use! I would advise checking out CodeMetrics to pair with SonarLint, I have found it to be a great combination to work together!