Golangci-lint: Can't extract issues from gofmt output on windows

Created on 26 Nov 2018  路  10Comments  路  Source: golangci/golangci-lint

I'm trying to run golangci-lint with the gofmt linter enabled on windows:

golangci-lint run -E gofmt

And get the following error:

level=warning msg="[runner] Can't run linter gofmt: can't extract issues from gofmt diff output \"--- G:/dev/linttest/main.go.or
ig\\t2018-11-26 18:07:15.209770400 +0000\\r\\n+++ G:/dev/linttest/main.go\\t2018-11-26 18:07:15.210770400 +0000\\r\\n@@ -2,8 +2,
8 @@\\r\\n \\r\\n import (\\r\\n \\t// goimports error - wrong order\\r\\n-\\t\\\"time\\\"\\r\\n \\t\\\"fmt\\\"\\r\\n+\\t\\\"tim
e\\\"\\r\\n )\\r\\n \\r\\n func main() {\\r\\n\": can't parse patch: line 3, char 149: bad hunk header: @@ -2,8 +2,8 @@\r"

Verbose output:

level=warning msg="[runner] Can't run linter gofmt: can't extract issues from gofmt diff output \"--- G:/dev/linttest/main.go.or
ig\\t2018-11-26 18:07:15.209770400 +0000\\r\\n+++ G:/dev/linttest/main.go\\t2018-11-26 18:07:15.210770400 +0000\\r\\n@@ -2,8 +2,
8 @@\\r\\n \\r\\n import (\\r\\n \\t// goimports error - wrong order\\r\\n-\\t\\\"time\\\"\\r\\n \\t\\\"fmt\\\"\\r\\n+\\t\\\"tim
e\\\"\\r\\n )\\r\\n \\r\\n func main() {\\r\\n\": can't parse patch: line 3, char 149: bad hunk header: @@ -2,8 +2,8 @@\r"

G:\dev\linttest>golangci-lint run -v -E gofmt
level=info msg="[config_reader] Config search paths: [./ G:\\dev\\linttest G:\\dev G:\\]"
level=info msg="Gocritic enabled checks: [appendAssign assignOp caseOrder dupArg dupBranchBody dupCase flagDeref ifElseChain reg
expMust singleCaseSwitch sloppyLen switchTrue typeSwitchVar underef unlambda unslice defaultCaseOrder]"
level=info msg="[lintersdb] Active 9 linters: [deadcode errcheck gofmt govet ineffassign megacheck structcheck typecheck varchec
k]"
level=info msg="[loader] Go packages loading at mode load deps types and syntax took 1.7967282s"
level=info msg="[loader] SSA repr building timing: packages building 12.5015ms, total 212.5269ms"
level=info msg="[loader] SSA for megacheck repr building timing: packages building 5.5007ms, total 178.5227ms"
level=info msg="[runner] worker.7 took 0s"
level=info msg="[runner] worker.12 took 0s"
level=info msg="[runner] worker.5 took 0s"
level=info msg="[runner] worker.13 took 0s"
level=info msg="[runner] worker.8 took 0s"
level=info msg="[runner] worker.4 took 500.1碌s with stages: typecheck: 0s"
level=info msg="[runner] worker.11 took 0s"
level=info msg="[runner] worker.15 took 1.0002ms with stages: varcheck: 500.1碌s"
level=info msg="[runner] worker.14 took 500.1碌s with stages: structcheck: 500.1碌s"
level=info msg="[runner] worker.9 took 0s"
level=info msg="[runner] worker.16 took 1.0002ms with stages: errcheck: 1.0002ms"
level=info msg="[runner] worker.6 took 1.0002ms with stages: deadcode: 1.0002ms"
level=info msg="[runner] worker.10 took 1.0002ms with stages: ineffassign: 1.0002ms"
level=info msg="[runner] worker.1 took 4.0006ms with stages: govet: 4.0006ms"
level=info msg="[runner] worker.3 took 86.011ms with stages: megacheck: 86.011ms"
level=info msg="[runner] worker.2 took 95.0121ms with stages: gofmt: 95.0121ms"
level=info msg="[runner] Workers idle times: #1: 43.0054ms, #3: 8.5011ms, #4: 84.0106ms, #5: 94.0119ms, #6: 55.007ms, #7: 100.01
27ms, #8: 89.0113ms, #9: 68.0086ms, #10: 48.5061ms, #11: 81.5103ms, #12: 97.0123ms, #13: 91.5116ms, #14: 70.5089ms, #15: 75.5096
ms, #16: 61.5078ms"
level=warning msg="[runner] Can't run linter gofmt: can't extract issues from gofmt diff output \"--- G:/dev/linttest/main.go.or
ig\\t2018-11-26 18:09:06.346770400 +0000\\r\\n+++ G:/dev/linttest/main.go\\t2018-11-26 18:09:06.347770400 +0000\\r\\n@@ -2,8 +2,
8 @@\\r\\n \\r\\n import (\\r\\n \\t// goimports error - wrong order\\r\\n-\\t\\\"time\\\"\\r\\n \\t\\\"fmt\\\"\\r\\n+\\t\\\"tim
e\\\"\\r\\n )\\r\\n \\r\\n func main() {\\r\\n\": can't parse patch: line 3, char 149: bad hunk header: @@ -2,8 +2,8 @@\r"
level=info msg="[runner] processing took 0s with stages: autogenerated_exclude: 0s, diff: 0s, path_prettifier: 0s, cgo: 0s, noli
nt: 0s, uniq_by_line: 0s, skip_files: 0s, skip_dirs: 0s, max_same_issues: 0s, exclude: 0s, max_per_file_from_linter: 0s, max_fro
m_linter: 0s, source_code: 0s, path_shortener: 0s"
level=info msg="Memory: 34 samples, avg is 61.7MB, max is 236.2MB"
level=info msg="Execution took 3.4024321s"

Version

golangci-lint has version 1.12.3 built from 014a924 on 2018-11-24T08:54:08Z

Output from go version && go env:

go version go1.11.1 windows/amd64
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\CDrew\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=G:\dev\GoWork
set GOPROXY=
set GORACE=
set GOROOT=D:\Go
set GOTMPDIR=
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=G:\dev\linttest\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=D:\NOTBAC~1\Temp\go-build767837518=/tmp/go-build -gno-record
-gcc-switches

The file I'm linting has a simple linting error:

package main

import (
    // goimports error - wrong order
    "time"
    "fmt"
)

func main() {
    fmt.Println("The time is", time.Now())
}

Most helpful comment

ok, got it. I've looked into the error text, looks like diff-parsing library doesn't support \r, I will fix it.

All 10 comments

It seems to depend on what kind of shell I use. The above reproduction was using windows command prompt. If I use Git bash I don't get the error. With Powershell Console I get the same error.

I wonder if this issue is related to the issue of enabling linters in Visual Studio Code on windows: #222

More info. I have GnuWin32 diff in my path. If I remove it from my path I get this error instead:

level=warning msg="[runner] Can't run linter gofmt: error computing diff: exec: \"diff\": executable file not found in %PATH%"

hi! thank you for the issue
looks difficult to reproduce because I have only Mac OS and Linux

@jirfag I think the question is, can golangci-lint be made to work without a "diff" executable. Because that will typically not be available on windows.

does gofmt without golangci-lint work for you? it uses diff

@jirfag Interesting... without any diff executable in my path all the functionality of gofmt works, except gofmt -d. You are right, gofmt -d does use diff. If I have a diff tool such as GnuWin32 DiffUtils in my path then I get the output I expect from gofmt -d .

ok, got it. I've looked into the error text, looks like diff-parsing library doesn't support \r, I will fix it.

I have created a pull request on the diff-parsing library: https://github.com/sourcegraph/go-diff/pull/29

l have similar question on windows 10,golangci-lint version is V1.32.2
run command:

golangci-lint run

got the error:

level=warning msg="[runner] Can't run linter goanalysis_metalinter: goimports: can't extract issues from gofmt diff output \"\": got no diffs from patch parser: []"
level=error msg="Running error: goimports: can't extract issues from gofmt diff output \"\": got no diffs from patch parser: []"

Has this problem been fixed锛焧hank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jirfag picture jirfag  路  3Comments

kpeu3i picture kpeu3i  路  3Comments

DarthHater picture DarthHater  路  4Comments

anuaimi picture anuaimi  路  4Comments

jsm picture jsm  路  5Comments