emacs-lsp / lsp-sonarlint

lsp-mode :heart: sonarlint
GNU General Public License v3.0
76 stars 13 forks source link
emacs emacs-lsp java javascript lsp-client python sonarlint

SonarLint for Emacs

License: GPLv3 MELPA MELPA Stable

SonarLint™ is a free IDE extension that lets you fix coding issues before they exist!

Like a spell checker,it highlights Bugs and Security Vulnerabilities as you write code, with clear remediation guidance so you can fix them before the code is even committed.

In Emacs supports analysis of JavaScript, TypeScript, Python, Java, HTML, PHP, C/C++, Go, and XML out of the box!

:warning: This is not an official SonarSource extension

Flycheck gif

How it works

lsp-sonarlint relies on the official vscode extension, which is downloaded and unzipped.

The official VSCode extension typically contains :

lsp-sonarlint is emacs's equivalent of the VSCode front-end, but only implements the base feature set, i.e linting and rules viewing.

Requirements

To analyze JavaScript and TypeScript, SonarLint will also need Node.js.

To analyse C/C++ projects, SonarLint's CFamily analyzer will need both a working compiler and a compile_commands.json which is typically generated by cmake or bear.

Installation

Source

Download and include the main file lsp-sonarlint.el.

Melpa

You can then run the following commands to install lsp-sonarlint:

M-x package-refresh-contents RET      (to refresh your package database)
M-x package-install RET lsp-sonarlint RET   (to install and compile `lsp-sonarlint` and its dependencies)

Usage

The language server relies on java plugins to properly analyze the selected language source code.

By default all are enabled, but you can specify the ones you want.

(use-package lsp-sonarlint
  :custom
  ;; Allow sonarlint to download and unzip the official VSCode extension
  ;; If nil, you'll have to do that yourself. See also `lsp-sonarlint-download'
  ;; `lsp-sonarlint-download-url' and `lsp-sonarlint-download-dir'
  (lsp-sonarlint-auto-download t)

  ;; Choose which analyzers you want enabled. By default all are enabled
  ;; See command `lsp-sonarlint-available-analyzers' for the full list.
  (lsp-sonarlint-enabled-analyzers '("java" "cfamily" "python" "text")))

[!WARNING] On windows, lsp-sonarlint may encounter this issue while unzipping the VSCode extension. If you do, try the following :

(setq lsp-unzip-script lsp-ext-pwsh-script)

Static Analysis Rules

Out of the box, SonarLint automatically checks your code against the following rules:

Supported settings

Available commands

Plugins additional info

For most analyzers, lsp-sonarlint provides variables describing additional info.

Plugins not tested yet

Currently, sonarlint's vscode extension also provides omnisharp and Infrastructure As Code (IAC) analyzers. They have not been tested yet, you may expect some additional configuration to make them work. You'll at least need to add the major-modes to `lsp-sonarlint-modes-enabled'.

Feel free to try them out and provide feedback.

Data and telemetry

This extension collects anonymous usage data and sends it to SonarSource.

Collection of telemetry is controlled via the setting: lsp-sonarlint-disable-telemetry, it is disable by default.

Click here to see a sample of the data that are collected.

Additional packages

Contributions

Contributions are very much welcome.

Copyright

SONARLINT and SONARSOURCE are trademarks of SonarSource SA. All other trademarks and copyrights are the property of their respective owners.