Skip to content

Commit dcae6e2

Browse files
committed
lintcmd: file names are optional in error positions
Closes: gh-1582 (cherry picked from commit 06d3e3e)
1 parent 2cef146 commit dcae6e2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lintcmd/lint.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,10 @@ func filterAnalyzerNames(analyzers []string, checks []string) map[string]bool {
550550
return allowedChecks
551551
}
552552

553-
var posRe = regexp.MustCompile(`^(.+?):(\d+)(?::(\d+)?)?`)
553+
// Note that the file name is optional and can be empty because of //line
554+
// directives of the form "//line :1" (but not "//line :1:1"). See
555+
// https://go.dev/issue/24183 and https://staticcheck.dev/issues/1582.
556+
var posRe = regexp.MustCompile(`^(?:(.+?):)?(\d+)(?::(\d+)?)?`)
554557

555558
func parsePos(pos string) (token.Position, int, error) {
556559
if pos == "-" || pos == "" {

0 commit comments

Comments
 (0)