Skip to content

Commit 38f55de

Browse files
committed
format: make #nosec explicitly a comment directive
https://github.com/securego/gosec#annotating-code Incidentally, #nosec was already mostly treated as a comment directive due to another check done after the regex match. This just makes it explicit and adds related test cases. Some versions of gosec also support the //gosec:disable directive, but that's quite well hidden in docs compared to //#nosec.
1 parent e522cc8 commit 38f55de

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

format/format.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ func (f *fumpter) lineEnd(line int) token.Pos {
318318
// //line | inserted line information for cmd/compile
319319
// //noinspection | noinspection directive for GoLand and friends
320320
// //nolint | nolint directive for golangci
321+
// //#nosec | #nosec directive for gosec
321322
// //NOSONAR | NOSONAR directive for SonarQube
322323
// //sys(nb)? | syscall function wrapper prototypes
323324
//
@@ -330,6 +331,7 @@ var rxCommentDirective = regexp.MustCompile(
330331
`|extern` +
331332
`|line` +
332333
`|no(?:inspection|lint)` +
334+
`|#nosec` +
333335
`|NOSONAR` +
334336
`|sys(?:nb)?` +
335337
`)\b`)

testdata/script/comment-spaced.txtar

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ package p
3232

3333
//noinspection foo,bar
3434

35+
//#nosec
36+
37+
//#nosec G000 G999 -- explanation
38+
3539
//not actually: a directive
3640

3741
//https://just.one/url
@@ -99,6 +103,10 @@ package p
99103

100104
//noinspection foo,bar
101105

106+
//#nosec
107+
108+
//#nosec G000 G999 -- explanation
109+
102110
// not actually: a directive
103111

104112
// https://just.one/url

0 commit comments

Comments
 (0)