Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure the rule set of SonarLint in Visual Studio Code?

I have installed sonar lint extension on my visual studio code editor and I was wondering if there is a way to enable or disable the rules which are used by the analyzer? There is a way to do it in Visual Studio and Eclipse but I couldn't find a way to enable or disable the rules on Visual Studio Code.

I do have SonarQube running on my local server where I can disable and enable the rules from the Admin UI page. If there is a way to configure the SonarLint with the server, that would be cool. But I am not sure how to do it. If anyone does, please point me in a right direction.

like image 607
ShellZero Avatar asked Apr 03 '18 22:04

ShellZero


People also ask

How do I activate SonarLint rule in VSCode?

In SonarLint v3. 6 and above for VSCode, to set up SonarQube/SonarCloud connections, open a SONARLINT CONNECTED MODE view in VSCode. Select either Add SonarQube Connection or Add SonarCloud Connection, and complete the fields. For SonarQube connections, provide your SonarQube Server URL and User Token.

How do I activate rules in SonarLint?

Open the “SonarLint Bindings” view in Eclipse, right click on your connection, and click “Update all projects bindings”. I know the root cause. It is because these rules are default not activated. I shoud copy the built-in profile and activate them, then Update All Project Bindings from SonarLint.

How do I add a custom rule in SonarLint?

SonarLint maintains a long list of rules that are executed on source code to generate issues. You can select exactly which rules you want to include in analyses via the Rules Configuration dialog. To access it: Bring up the Preferences dialog via Window -> Preferences from the main menu.

How does Visual Studio code integrate with SonarLint?

Installing the SonarLint VS Code extension: Go to VS Code Side Bar › Extensions or Press Ctrl + Shift + X in Windows. Search SonarLint Extensions in Marketplace. Click on the extension SonarLint. Click on Install.


2 Answers

Goto settings and search for sonarlint enter image description here

Click on Edit in settings.json

Add to "sonarlint.rules": the rule you wand to disable as follow:

    "javascript:S1488": {
        "level": "off"
    }

the rule code is displayed in the floating box enter image description here

like image 192
Elia Weiss Avatar answered Oct 28 '22 06:10

Elia Weiss


Currently there is no way to use the connected mode which allows the user to configure (enable/disable) the rules on the SonarLint.

According to the discussion on the SonarLint Google Group.

It's very likely that this feature will be added soon (within the year), as we already started developing it for other flavors of SonarLint (Eclipse).

This feature is currently in work in progress and can be tracked here

like image 3
ShellZero Avatar answered Oct 28 '22 07:10

ShellZero