Skip to content

Commit 4e57a27

Browse files
scopmvdan
authored andcommitted
format: treat noinspection as comment directive
Used by some versions of GoLand and friends, https://www.jetbrains.com/help/go/disabling-and-enabling-inspections.html New versions use `//goland:noinspection` instead/additionally, but it doesn't hurt much to support the older (and still the only documented) one.
1 parent 53340e7 commit 4e57a27

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

format/format.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,18 @@ func (f *fumpter) lineEnd(line int) token.Pos {
306306

307307
// rxCommentDirective covers all common Go comment directives:
308308
//
309-
// //go: | standard Go directives, like go:noinline
310-
// //some-words: | similar to the syntax above, like lint:ignore or go-sumtype:decl
311-
// //line | inserted line information for cmd/compile
312-
// //export | to mark cgo funcs for exporting
313-
// //extern | C function declarations for gccgo
314-
// //sys(nb)? | syscall function wrapper prototypes
315-
// //nolint | nolint directive for golangci
309+
// //go: | standard Go directives, like go:noinline
310+
// //some-words: | similar to the syntax above, like lint:ignore or go-sumtype:decl
311+
// //line | inserted line information for cmd/compile
312+
// //export | to mark cgo funcs for exporting
313+
// //extern | C function declarations for gccgo
314+
// //sys(nb)? | syscall function wrapper prototypes
315+
// //nolint | nolint directive for golangci
316+
// //noinspection | noinspection directive for GoLand and friends
316317
//
317318
// Note that the "some-words:" matching expects a letter afterward, such as
318319
// "go:generate", to prevent matching false positives like "https://site".
319-
var rxCommentDirective = regexp.MustCompile(`^([a-z-]+:[a-z]+|line\b|export\b|extern\b|sys(nb)?\b|nolint\b)`)
320+
var rxCommentDirective = regexp.MustCompile(`^([a-z-]+:[a-z]+|line\b|export\b|extern\b|sys(nb)?\b|no(lint|inspection)\b)`)
320321

321322
func (f *fumpter) applyPre(c *astutil.Cursor) {
322323
f.splitLongLine(c)

testdata/scripts/comment-spaced.txt

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

2525
//nolint:somelinter // explanation
2626

27+
//noinspection ALL
28+
29+
//noinspection foo,bar
30+
2731
//not actually: a directive
2832

2933
//https://just.one/url
@@ -83,6 +87,10 @@ package p
8387

8488
//nolint:somelinter // explanation
8589

90+
//noinspection ALL
91+
92+
//noinspection foo,bar
93+
8694
// not actually: a directive
8795

8896
// https://just.one/url

0 commit comments

Comments
 (0)