From ec55db560eea5ccdde7a94a09709262634f85917 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Sat, 16 Jan 2021 02:43:59 +0100 Subject: [PATCH] Don't require relative paths to start with ./ or ../ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Errors reported by Go, even when containing relative paths, do not always begin with ./ or ../ – for example: $ go build ./... # honnef.co/go/tools/lintcmd lintcmd/format.go:28:8: syntax error: cannot use path := filepath.Clean(pos.Filename) as value We could require either ./, ../ or at least one path separator and still match Go's output. However, commonly used linters (such as Staticcheck and golint) never use ./ for relative paths. Their output stopped being matched when we moved from v1 to v2. I believe that being able to match the output of linters is worth relaxing the pattern for. This change slightly relaxes the stricter pattern that was introduced as part of v2 to address #46. However, the pattern is still stricter than it was in v1 and as strict as it can be for most users. --- __tests__/setup-go.test.ts | 10 ++++++++++ matchers.json | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index c90d74b82..c113ccb32 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -497,6 +497,16 @@ describe('setup-go', () => { expect(annotation.message).toBe('undefined: fmt.Printl'); }); + it('matches on unix path down the tree', async () => { + let line = 'foo/main.go:13:2: undefined: fmt.Printl'; + let annotation = testMatch(line); + expect(annotation).toBeDefined(); + expect(annotation.line).toBe(13); + expect(annotation.column).toBe(2); + expect(annotation.file).toBe('foo/main.go'); + expect(annotation.message).toBe('undefined: fmt.Printl'); + }); + it('matches on rooted unix path', async () => { let line = '/assert.go:4:1: missing return at end of function'; let annotation = testMatch(line); diff --git a/matchers.json b/matchers.json index 675fdb765..24be34118 100644 --- a/matchers.json +++ b/matchers.json @@ -4,7 +4,7 @@ "owner": "go", "pattern": [ { - "regexp": "^\\s*(\\.{0,2}[\\/\\\\].+\\.go):(?:(\\d+):(\\d+):)? (.*)", + "regexp": "^\\s*(.+\\.go):(?:(\\d+):(\\d+):)? (.*)", "file": 1, "line": 2, "column": 3, @@ -13,4 +13,4 @@ ] } ] -} \ No newline at end of file +}