From 06d3e3e4b67b699e4e97993c51529b20097e537b Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Tue, 6 Aug 2024 13:04:52 +0200 Subject: [PATCH] lintcmd: file names are optional in error positions Closes: gh-1582 --- lintcmd/lint.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lintcmd/lint.go b/lintcmd/lint.go index 0a58e514..548d74d4 100644 --- a/lintcmd/lint.go +++ b/lintcmd/lint.go @@ -550,7 +550,10 @@ func filterAnalyzerNames(analyzers []string, checks []string) map[string]bool { return allowedChecks } -var posRe = regexp.MustCompile(`^(.+?):(\d+)(?::(\d+)?)?`) +// Note that the file name is optional and can be empty because of //line +// directives of the form "//line :1" (but not "//line :1:1"). See +// https://go.dev/issue/24183 and https://staticcheck.dev/issues/1582. +var posRe = regexp.MustCompile(`^(?:(.+?):)?(\d+)(?::(\d+)?)?`) func parsePos(pos string) (token.Position, int, error) { if pos == "-" || pos == "" {