Skip to content

Commit

Permalink
format: treat noinspection as comment directive
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
scop authored and mvdan committed Dec 16, 2021
1 parent 53340e7 commit 4e57a27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 9 additions & 8 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,18 @@ func (f *fumpter) lineEnd(line int) token.Pos {

// rxCommentDirective covers all common Go comment directives:
//
// //go: | standard Go directives, like go:noinline
// //some-words: | similar to the syntax above, like lint:ignore or go-sumtype:decl
// //line | inserted line information for cmd/compile
// //export | to mark cgo funcs for exporting
// //extern | C function declarations for gccgo
// //sys(nb)? | syscall function wrapper prototypes
// //nolint | nolint directive for golangci
// //go: | standard Go directives, like go:noinline
// //some-words: | similar to the syntax above, like lint:ignore or go-sumtype:decl
// //line | inserted line information for cmd/compile
// //export | to mark cgo funcs for exporting
// //extern | C function declarations for gccgo
// //sys(nb)? | syscall function wrapper prototypes
// //nolint | nolint directive for golangci
// //noinspection | noinspection directive for GoLand and friends
//
// 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|nolint\b)`)
var rxCommentDirective = regexp.MustCompile(`^([a-z-]+:[a-z]+|line\b|export\b|extern\b|sys(nb)?\b|no(lint|inspection)\b)`)

func (f *fumpter) applyPre(c *astutil.Cursor) {
f.splitLongLine(c)
Expand Down
8 changes: 8 additions & 0 deletions testdata/scripts/comment-spaced.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ package p

//nolint:somelinter // explanation

//noinspection ALL

//noinspection foo,bar

//not actually: a directive

//https://just.one/url
Expand Down Expand Up @@ -83,6 +87,10 @@ package p

//nolint:somelinter // explanation

//noinspection ALL

//noinspection foo,bar

// not actually: a directive

// https://just.one/url
Expand Down

0 comments on commit 4e57a27

Please sign in to comment.