Skip to content

Commit 52dc406

Browse files
committed
Add Go analyzer and generic secrets and Bidi detection
1 parent f8da49e commit 52dc406

File tree

8 files changed

+156
-3
lines changed

8 files changed

+156
-3
lines changed

Eask

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"Emacs SonarLint lsp client")
44

55
(website-url "https://github.com/emacs-lsp/lsp-sonarlint")
6-
(keywords "languages" "tools" "php" "javascript" "xml" "html" "java" "python")
6+
(keywords "languages" "tools" "php" "javascript" "typescript" "go" "xml" "html" "java" "python")
77

88
(package-file "lsp-sonarlint.el")
99

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SonarLint™ is a free IDE extension that lets you fix coding issues before they
88

99
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.
1010

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

1313
:warning: This is not an official [SonarSource](https://www.sonarsource.com/) extension
1414

@@ -97,6 +97,8 @@ Out of the box, SonarLint automatically checks your code against the following r
9797
- [HTML rules](https://rules.sonarsource.com/html)
9898
- [PHP rules](https://rules.sonarsource.com/php)
9999
- [XML rules](https://rules.sonarsource.com/xml)
100+
- [Go rules](https://rules.sonarsource.com/go)
101+
- [Bidi (bidirectional unicode characters)](https://rules.sonarsource.com/text/) + [Secrets](https://rules.sonarsource.com/secrets/)
100102

101103
## Supported settings
102104

fixtures/sample.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
// TODO: to be done, really
5+
func main() {
6+
fmt.Println("Hello, World!")
7+
}

fixtures/secrets.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class S6290 {
2+
public static final String KEY = "AKIAIGKECZXA7AEIJLMQ";
3+
public static final String AWS_SESSION_TOKEN = "IQoJb3JpZ2luX2VjEKL//////////wEaDGV1LWNlbnRyYWwtMSJHMEUCIQDFlDUEvUa6slxlkKKn8zbLkN/j1f7lKJdXJ03PQ5T5ZwIgDYlshciO8nyfnmjUfFy4I2+rEuPHBexsvfBo3MlCdgQqugMISxAAGgw4NTk4OTY2NzUzMDYiDFKPV7D/QmnqFWRYpiqXAypJf6TksPZXImVpIUU0Yj0uJhNN0o/HcO8hfQ4BXuCvpm1DOiVsH6VXMxgNdpGTWr8CjNpEt/eYwSk6MAVPOtjg5+lY2qoGJrUuxwhiKe+BquVM17h0giZ18h1B4ozDGkfxA/vGSJa/qBznF0yEpLE+fJoesGe4ZpATs8oUN94/XkrL/eYzXsW3ZD1ZX66QzmSFHhgTJc24d9bezGjR32fEJD/dBm9La+7wpc4+jrXCmt6yxHox0gCuGrSagcJfPh9pVYneM81fnD/S7Kicb1Pw8MiChfqW0hao1twr4wMgp9N3JlYQNK3fZKbMU/qlvoKTz8D0Joa4elSp4rU4reVUsujCXVE95PDyj4LD3IDXHF5SAd/23/M/IucMRyeWlRE4pCtry68ENpojXr0tdyyVs8XSkgCGgup/BqDTkBnEBD+V5hOIrHJv5rJ6KpaxEZG0ozUJdaUpCseSSKK4Jn7liqVqF5EzOOXelqTAACcJmILKQHqke8n3imNs72oi8tu1N+oqbFp60K9whtLDm0JZSavpmRDkMODb8/4FOusBHFYZCuxMUmotN9Dkzp4InT7kJdKZ/kr61SMhU4hj7vTdjhcRHItO2P+jR7+38kQLDR4O1HR1XkHzLMwDvDwZULeOl6afS1ZpbO8XpePHaaLnEqJeZ8BpnfwBEiylK3HGzGAP7WcAgFlMO9AEqoGnnbUBFcL+IYnZ3JFPy0sGsrH4cOC8Gxy2icQKrGpdIyMqGjb2hZsSc1S4njGpK0AlCEKrAjzpr6SzPSwLnFtAJpztHbgb9Z7D2jdsjugQYdFwi6/9GKOI/slKqt5/vb7dLnSyeAY+jTaoveUZf6D5yM8PCKrvw5/k+A1XJw==";
4+
public static final String AWS_SECRET_ACCESS_KEY = "kHeUAwnSUizTWpSbyGAz4f+As5LshPIjvtpswqGb";
5+
}

languages/go/lsp-sonarlint-go.el

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
;;; lsp-sonarlint-go.el --- lsp-sonarlint Go module -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2020 Fermin Munoz
4+
;; URL: https://gitlab.com/sasanidas/lsp-sonarlint
5+
;; Keywords: languages
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
;; Specific configuration for the SonarLint Go plugin.
22+
23+
;; This is NOT and official SonarLint extension.
24+
25+
26+
;;; Code:
27+
28+
(defgroup lsp-sonarlint-go nil
29+
"lsp-sonarlint Go analyzer group"
30+
:group 'lsp-sonarlint
31+
:version '(lsp-sonarlint-go . "1.12.0"))
32+
33+
(defcustom lsp-sonarlint-go-enabled nil
34+
"Enable lsp-sonarlint-go plugin."
35+
:group 'lsp-sonarlint-go
36+
:type 'boolean)
37+
38+
(defcustom lsp-sonarlint-go-download-url
39+
"https://repo.maven.apache.org/maven2/org/sonarsource/slang/sonar-go-plugin/1.12.0.4259/sonar-go-plugin-1.12.0.4259.jar"
40+
"Go plugin download URL."
41+
:group 'lsp-sonarlint-go
42+
:type 'string)
43+
44+
(defcustom lsp-sonarlint-go-analyzer-path
45+
(concat
46+
(file-name-directory load-file-name)
47+
"sonar-go.jar")
48+
"Lsp-sonarlint Go analyzer location."
49+
:group 'lsp-sonarlint-go
50+
:type 'file)
51+
52+
(defvar lsp-sonarlint-go-doc-url "https://www.sonarsource.com/go/"
53+
"Documentation sonarsource URL.")
54+
55+
(defvar lsp-sonarlint-go-repository-url "https://github.com/SonarSource/slang/"
56+
"Official sonarlint code extension repository.")
57+
58+
59+
(provide 'lsp-sonarlint-go)
60+
;;; lsp-sonarlint-go.el ends here
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
;;; lsp-sonarlint-text.el --- lsp-sonarlint text module -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2020 Fermin Munoz
4+
;; URL: https://gitlab.com/sasanidas/lsp-sonarlint
5+
;; Keywords: languages
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
;; Specific configuration for the SonarLint text plugin.
22+
23+
;; This is NOT and official SonarLint extension.
24+
25+
26+
;;; Code:
27+
28+
(defgroup lsp-sonarlint-text nil
29+
"lsp-sonarlint text analyzer group"
30+
:group 'lsp-sonarlint
31+
:version '(lsp-sonarlint-text . "2.0.1"))
32+
33+
(defcustom lsp-sonarlint-text-enabled nil
34+
"Enable lsp-sonarlint-text plugin."
35+
:group 'lsp-sonarlint-text
36+
:type 'boolean)
37+
38+
(defcustom lsp-sonarlint-text-download-url
39+
"https://repo.maven.apache.org/maven2/org/sonarsource/text/sonar-text-plugin/2.0.1.611/sonar-text-plugin-2.0.1.611.jar"
40+
"Text plugin download URL."
41+
:group 'lsp-sonarlint-text
42+
:type 'string)
43+
44+
(defcustom lsp-sonarlint-text-analyzer-path
45+
(concat
46+
(file-name-directory load-file-name)
47+
"sonar-text.jar")
48+
"Lsp-sonarlint text analyzer location."
49+
:group 'lsp-sonarlint-text
50+
:type 'file)
51+
52+
(defvar lsp-sonarlint-text-doc-url "https://www.sonarsource.com/"
53+
"Documentation sonarsource URL.")
54+
55+
(defvar lsp-sonarlint-text-repository-url "https://github.com/SonarSource/sonar-text"
56+
"Official sonarlint code extension repository.")
57+
58+
59+
60+
61+
62+
(provide 'lsp-sonarlint-text)
63+
;;; lsp-sonarlint-text.el ends here

lsp-sonarlint.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
;; Author: Fermin MF <[email protected]>
66
;; Created: 13 Jun 2020
77
;; Version: 0.0.1
8-
;; Keywords: languages, tools, php, javascript, xml, html, java, python
8+
;; Keywords: languages, tools, php, javascript, typescript, go, xml, html, java, python
99
;; URL: https://github.com/emacs-lsp/lsp-sonarlint
1010
;; Package-Requires: ((emacs "25") (dash "2.12.0") (lsp-mode "6.3") (ht "2.3"))
1111
;; License: GPL-3.0-or-later
@@ -53,6 +53,7 @@
5353
:type 'file)
5454

5555
(defcustom lsp-sonarlint-modes-enabled '(php-mode
56+
go-mode
5657
html-mode
5758
web-mode
5859
js-mode

test/lsp-sonarlint-integration-test.el

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ It can perform further interaction with LSP, e.g., execute code actions."
6868
(dir (file-name-directory file))
6969
(lsp-enable-snippet nil)
7070
;; Disable all plugins to focus only on the issues from the knob-symbol
71+
(lsp-sonarlint-go-enabled nil)
7172
(lsp-sonarlint-html-enabled nil)
7273
(lsp-sonarlint-java-enabled nil)
7374
(lsp-sonarlint-javascript-enabled nil)
7475
(lsp-sonarlint-typescript-enabled nil)
7576
(lsp-sonarlint-php-enabled nil)
77+
(lsp-sonarlint-text-enabled nil)
7678
(lsp-sonarlint-typescript-enabled nil)
7779
(lsp-sonarlint-xml-enabled nil)
7880
received-warnings)
@@ -171,6 +173,19 @@ and get the issues from the server."
171173
(should (equal (lsp-sonarlint--get-all-issue-codes "sample.xml" 'lsp-sonarlint-xml-enabled)
172174
'("xml:S1135"))))
173175

176+
;; "text" plugin detects secrets and bidirectional unicode characters
177+
(ert-deftest lsp-sonarlint-text-reports-issues ()
178+
"Check that LSP can detect Secrets with SonarLint."
179+
(require 'lsp-sonarlint-text)
180+
(should (equal (lsp-sonarlint--get-all-issue-codes "secrets.java" 'lsp-sonarlint-text-enabled)
181+
'("secrets:S6290" "secrets:S6290" "secrets:S6290"))))
182+
183+
(ert-deftest lsp-sonarlint-go-reports-issues ()
184+
"Check that LSP can get go SonarLint issues for a go file."
185+
(require 'lsp-sonarlint-go)
186+
(should (equal (lsp-sonarlint--get-all-issue-codes "sample.go" 'lsp-sonarlint-go-enabled)
187+
'("go:S1135"))))
188+
174189
(defun lsp-sonarlint--find-descr-action-at-point ()
175190
"Find the 'get rule description' code action for the issue at point."
176191
(seq-find (lambda (action) (string-match-p "description" (gethash "title" action)))

0 commit comments

Comments
 (0)