Getting Started Installation - kevin-hinz/sonarlint-docs-migration-render GitHub Wiki

Page Item: Installation

SLUG: getting-started-installation

Installing SonarLint is most easily accomplished from your IDE's marketplace. Select the tab below corresponding to your IDE:

tabbed

Eclipse

PLACE ECLIPSE CONTENT HERE TO ENTERED INTO THE KONTENT.AI-SPECIFIC ASSET

You can find the SonarLint for Eclipse IDE extension directly on the Eclipse Marketplace.

CONSIDER PLACEMENT: SonarLint can optionally be connected to SonarQube or SonarCloud to provide additional features.

Quick Installation

SonarLint for Eclipse is a plugin that can be installed in most Eclipse based IDEs (including Spring Tool Suite, PyDev, ...)

  1. In your Eclipse based IDE, open the Marketplace client

Open Marketplace Client

  1. Search for SonarLint, and click Install

Install from Marketplace

  1. Restart your IDE

For more installation methods, look for the advanced installation documentation.

INFOBOX By using this method, you will be automatically notified of new updates of SonarLint (assuming you have allowed Eclipse to check for updates).

Online installation using the Eclipse Install New Software wizard

NOTE: THIS HEADER SHOULD BE RENAMED TO REFLECT THE NATURE OF THE "ADVANCED" INSTALLATION METHOD.

Official Eclipse documentation

If you can't use the Eclipse Marketplace client, you can still use directly the SonarLint update site.

  1. Open Install New Software

Install new software

  1. Click on the Add... button to add a new repository pointing to https://eclipse-uc.sonarlint.org. Give the repository a meaningful name.Don't worry if you can't open this URL in your web browser, Eclipse will automatically look for files compositeContent.xml and compositeArtifacts.xml

Add Update Site Add Update Site Online

  1. Select the just added SonarLint repository, and tick the SonarLint for Eclipse feature

Select feature online

  1. Review the features about to be installed, and click Finish

Confirm feature

  1. When requested, restart you IDE

:information_source: By using this method, you will be automatically notified of new updates of SonarLint (assuming you have allowed Eclipse to check for updates).

First taste of SonarLint

Now that you have SonarLint installed, open or create a new project containing source files in a programming language SonarLint can analyze out of the box: Java, PHP, Python, JavaScript or HTML.

For example in Java, you can copy paste this code snippet, with a typical bug when copy/pasting for loops:

package org.mycompany;

import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {

  private static final Logger LOGGER = Logger.getLogger(Main.class.getName());

  public static void main(String[] args) {
    for (int left = 0; left < 10; left++) {
      for (int right = 0; right < 10; left++) {
        LOGGER.log(Level.INFO, "Pair: ({0},{1})", new Object[] {left, right});
      }
    }
  }

}

If you open this Java file within the Eclipse Java editor, you should see SonarLint reporting the issue:

First time analysis

To get more details about the issue, you can simply hover on the issue location, and a popup will display the issue message:

Hover

There is also the possibility to use the SonarLint On-The-Fly view to display the list of issues found by SonarLint. Simply open the view from the menu Windows -> Show View -> Other...

Open On-The-Fly view On-The-Fly view

tabbed

IntelliJ

PLACE INTELLIJ CONTENT HERE TO ENTERED INTO THE KONTENT.AI-SPECIFIC ASSET

You can install SonarLint from the JetBrains Plugin Repository, directly available in the IDE preferences.

SEE THE REQUIREMENTS PAGE FOR UP TO DATE DETAILS.

Search the marketplace from the IntelliJ IDE.

Go to File > Settings:

File Settings

Then select the Plugins > Marketplace tab:

Install SonarLint

Then click OK and restart the IDE to finalize the installation.

You can now enjoy SonarLint!

First taste of SonarLint

Let's analyze a first source file and see what SonarLint can bring.

Copy paste this Java code snippet in a project. It contains a code smell because of duplicated methods:

package org.mycompany;

class MyClass {
  private static final String CODE = "XXX";

  public String calculateCode() {
    doTheThing();
    return CODE;
  }

  public String getName() {
    doTheThing();
    return CODE;
  }

  private void doTheThing() {
    // do it
  }
}

If you open this Java file within the editor, you should see SonarLint reporting the issue by highlighting the text range.

You can hover on the highlight to get a short description of the issue.

If you want to read a more detailed explanation of the issue, we provide context actions. One of them will open the detailed rule description.

tabbed

Visual Studio

PLACE VISUAL STUDIO CONTENT HERE TO ENTERED INTO THE KONTENT.AI-SPECIFIC ASSET

You can get it directly from the VS Marketplace and it will then detect new bugs and quality issues as you code (for C#, VB.NET, JavaScript, TypeScript, C and C++).

tabbed

Visual Studio Code

PLACE VISUAL STUDIO CONTENT HERE TO ENTERED INTO THE KONTENT.AI-SPECIFIC ASSET

The easiest way to install the SonarLint extension is to search the Visual Studio Code Marketplace, directly from the IDE.

Select the Extensions icon in the Activity Bar and search for SonarLint:

Extensions Tab

Next, select Install. SonarLint should start right away after the installation is complete.

You can now enjoy SonarLint!

How it works

Simply open any source file, start coding, and you will start seeing issues reported by SonarLint. Issues are highlighted in your code, and also listed in the 'Problems' panel.

sonarlint on-the-fly

You can access the detailed rule description directly from your editor, using the provided contextual menu.

rule description