Skip to content

Commit

Permalink
don't add whitespace to //NOSONAR comments
Browse files Browse the repository at this point in the history
When using sonarqube, `//NOSONAR` can be used to disable
SONAR parsing for this line on false-positives.

See: https://docs.sonarcloud.io/appendices/frequently-asked-questions/

This only works if there is no space between the slashes and `NOSONAR`.

Co-authored-by: Kimi Loeffel <kimi.loeffel@bit.admin.ch>
  • Loading branch information
MrSpoony and Kimi Loeffel committed Apr 14, 2023
1 parent 36b4fbb commit ea3d413
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion format/format.go
Expand Up @@ -305,10 +305,11 @@ func (f *fumpter) lineEnd(line int) token.Pos {
// //sys(nb)? | syscall function wrapper prototypes
// //nolint | nolint directive for golangci
// //noinspection | noinspection directive for GoLand and friends
// //NOSONAR | NOSONAR directive for SonarQube
//
// Note that the "some-words:" matching expects a letter afterward, such as
// "go:generate", to prevent matching false positives like "https://site".
var rxCommentDirective = regexp.MustCompile(`^([a-z-]+:[a-z]+|line\b|export\b|extern\b|sys(nb)?\b|no(lint|inspection)\b)`)
var rxCommentDirective = regexp.MustCompile(`^([a-z-]+:[a-z]+|line\b|export\b|extern\b|sys(nb)?\b|no(lint|inspection)\b)|NOSONAR\b`)

func (f *fumpter) applyPre(c *astutil.Cursor) {
f.splitLongLine(c)
Expand Down
8 changes: 8 additions & 0 deletions testdata/script/comment-spaced.txtar
Expand Up @@ -24,6 +24,10 @@ package p

//nolint:somelinter // explanation

//NOSONAR

//NOSONAR // explanation

//noinspection ALL

//noinspection foo,bar
Expand Down Expand Up @@ -87,6 +91,10 @@ package p

//nolint:somelinter // explanation

//NOSONAR

//NOSONAR // explanation

//noinspection ALL

//noinspection foo,bar
Expand Down

0 comments on commit ea3d413

Please sign in to comment.