Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,28 @@ func (f *fumpter) lineEnd(line int) token.Pos {
//
// //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
// //line | inserted line information for cmd/compile
// //noinspection | noinspection directive for GoLand and friends
// //nolint | nolint directive for golangci
// //#nosec | #nosec directive for gosec
// //NOSONAR | NOSONAR directive for SonarQube
// //sys(nb)? | syscall function wrapper prototypes
//
// 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)|NOSONAR\b`)
var rxCommentDirective = regexp.MustCompile(
`^(?:` +
`[a-z-]+:[a-z]+` +
`|export` +
`|extern` +
`|line` +
`|no(?:inspection|lint)` +
`|#nosec` +
`|NOSONAR` +
`|sys(?:nb)?` +
`)\b`)

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

//noinspection foo,bar

//#nosec

//#nosec G000 G999 -- explanation

//not actually: a directive

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

//noinspection foo,bar

//#nosec

//#nosec G000 G999 -- explanation

// not actually: a directive

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