Skip to content

Connected Mode

kevin.hinz edited this page Aug 9, 2022 · 25 revisions

You can connect SonarLint to SonarQube 7.9+/SonarCloud by binding your VSCode workspace folder to your SonarQube/SonarCloud project(s), and benefit from the same rules and settings that are used to inspect your project on the server. SonarLint in VSCode then hides Won’t Fix and False Positive issues in any file from a bound folder.

While in Connected Mode, SonarLint receives notifications from SonarQube/SonarCloud about your Quality Gate changes and new issues. Notifications can be enabled or disabled from the UI while creating or editing the connection settings. Note, Connected Mode notifications are not available in SonarQube Community Edition 8.6 and earlier.

When running in Connected Mode with SonarQube 8.6 and above, and browsing a security hotspot, a button will be available offering to open the hotspot in SonarLint (with SonarLint already running in VSCode). Limitation: this feature relies on local communication between your web browser and SonarLint, and consequently is not available in some remote environments such as GitPod, or GitHub CodeSpaces.

Connected Mode will also allow unlocking of your analysis for these languages:

When configuring Connected Mode, follow the Connection Setup instructions below.

Project Binding

SonarLint keeps server-side data in a local storage. If you change something on the server such as the Quality Profile, SonarLint will automatically attempt to synchronize with configured servers at startup and once every hour, and will do its best to synchronize with the most appropriate branch from the server. Additionally, you can trigger an update of the local storage using the "SonarLint: Update all project bindings to SonarQube/SonarCloud" command on the command palette (search for "sonarlint").

Connection Setup

SonarLint v3.8 and above

In v3.8 and above of SonarLint for VSCode, to set up SonarQube/SonarCloud connections, open up a SONARLINT CONNECTED MODE view in VSCode.

Empty Connected Mode View

Click on the relevant button to choose the SonarQube/SonarCloud connection you use, and complete the fields.

Create Connection View

For SonarQube connections, provide your SonarQube Server URL and Token. For SonarCloud connections, provide your Organization Key and Token. User Tokens should be generated on the SonarQube/SonarCloud side and pasted in the User Token field.

User Token can be generated using these pages:

  • SonarQube - https://<your-sonarqube-url>/account/security/
  • SonarCloud - https://sonarcloud.io/account/security/

Connection Name is a friendly name for your connections. In case of multiple connections, it also acts as a connectionId.

In SonarLint for VSCode v3.6 and above, notifications can be enabled or disabled here, or from the UI while creating or editing the connection setting (see next image below). Action buttons in the UI used to edit/delete existing, or create additional connections will be revealed when hovering over each connection.

Click Save Connection and verify that the new connection was set up successfully in the Connected Mode view.

Project Binding v3.8 and above

To configure a project binding, navigate to the SONARLINT CONNECTED MODE view in the VSCode Explorer and click the Add Project Binding button for the desired connection.

Add Project Binding

If your open workspace contains multiple folders, you will be prompted to select the Folder you would like to bind.

Select Folder

After selecting the folder, you will be prompted to select the remote SonarQube/SonarCloud project you would like to bind.

Select Project

Click on the desired project and enjoy Connected Mode! You can also edit/delete bindings from the SONARLINT CONNECTED MODE view

Edit Binding

Action buttons in the UI used to edit/delete existing, or create additional connections will be revealed when hovering over each connection.


SonarLint v3.6-v3.7

Starting from v3.6 of SonarLint for VSCode, to set up SonarQube/SonarCloud connections, open up a SONARLINT CONNECTED MODE view in VSCode.

Empty Connected Mode View

Click on the relevant button to choose the SonarQube/SonarCloud connection you use, and complete the fields.

Create Connection View

For SonarQube connections, provide your SonarQube Server URL and Token. For SonarCloud connections, provide your Organization Key and Token. A User Token should be generated on the SonarQube/SonarCloud side and pasted in the User Token field.

User Tokens can be generated using these pages:

  • SonarQube - https://<your-sonarqube-url>/account/security/
  • SonarCloud - https://sonarcloud.io/account/security/

Connection Name is a friendly name for your connections. In the case of multiple connections, it also acts as a connectionId.

In SonarLint for VSCode v3.6 and above, notifications can be enabled or disabled here (see image above), or from the UI while creating or editing the connection setting (see next image below). Action buttons in the UI used to edit/delete existing, or create additional connections will be revealed when hovering over each connection.

Click Save Connection and verify that the new connection was set up successfully in the Connected Mode view.

Connection Success

Action buttons to edit/delete existing, or create additional connections will be revealed when hovering over each connection.

Project Binding v3.6-3.7

Establish your SONARLINT CONNECTED MODE as described above.

Project Bindings can be configured either at workspace level or in every workspace folder by modifying the settings.json file. Example:

{
    "sonarlint.connectedMode.project": {
        "projectKey": "the-project-key"
    }
}

If you plan to use multiple connections to different SonarQube servers and/or SonarCloud organizations, simply give a unique connectionId to each entry and use them as reference in the binding. Example:

// In project1/.vscode/settings.json
{
    "sonarlint.connectedMode.project": {
        "connectionId": "mySonar",
        "projectKey": "the-project-key-on-sq"
    }
}

// In project2/.vscode/settings.json
{
    "sonarlint.connectedMode.project": {
        "connectionId": "myOrgOnSonarCloud",
        "projectKey": "the-project-key-on-sc"
    }
}

SonarLint Versions 3.5.4 and Lower

Connection details should be configured in the VSCode user settings (user token, SonarQube server URL or SonarCloud organization). For security reasons, the token should not be stored in SCM with workspace settings (why we suggest to configure in VSCode user settings).

Example for SonarQube:

{
    "sonarlint.connectedMode.connections.sonarqube": [
        { "serverUrl": "https://sonarqube.mycompany.com", "token": "<generated from SonarQube account/security page>" }
    ]
}

Example for SonarCloud:

{
    "sonarlint.connectedMode.connections.sonarcloud": [
        { "organizationKey": "myOrg", "token": "<generated from https://sonarcloud.io/account/security/>" }
    ]
}

Notifications from your project's Quality Gate can be toggled using the disableNotifications field in a server connection definition.

Project Binding v3.5.4 and earlier

SonarLint v3.5.4 and earlier allows bindings either at the workspace level, or at each workspace folder. Example:

{
    "sonarlint.connectedMode.project": {
        "projectKey": "the-project-key"
    }
}

If you plan to use multiple connections, to different SonarQube servers and/or SonarCloud organizations, simply give a unique connectionId to each entry, and use them as reference in the binding. Example:

// In user settings
{
    "sonarlint.connectedMode.connections.sonarqube": [
        { "connectionId": "mySonar", "serverUrl": "https://sonarqube.mycompany.com", "token": "xxx" }
    ]
    "sonarlint.connectedMode.connections.sonarcloud": [
        { "connectionId": "myOrgOnSonarCloud", "organizationKey": "myOrg", "token": "yyy" }
    ]
}

// In project1/.vscode/settings.json
{
    "sonarlint.connectedMode.project": {
        "connectionId": "mySonar",
        "projectKey": "the-project-key-on-sq"
    }
}

// In project2/.vscode/settings.json
{
    "sonarlint.connectedMode.project": {
        "connectionId": "myOrgOnSonarCloud",
        "projectKey": "the-project-key-on-sc"
    }
}