Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows: gci gofmt goimports fail due to being unable to parse diff output #3428

Closed
4 tasks done
matjam opened this issue Dec 20, 2022 · 2 comments
Closed
4 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@matjam
Copy link

matjam commented Dec 20, 2022

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc.).
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

Summary

running golangci-lint run ./... gives:

level=warning msg="[runner] Can't run linter goanalysis_metalinter: gci: 4:20: expected ';', found \"fmt\" (and 10 more errors)"
level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: gci: 4:20: expected ';', found \"fmt\" (and 10 more errors)\n\n"

disabling gci gives:

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

disabling gofmt gives:

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: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: goimports: can't extract issues from gofmt diff output \"\": got no diffs from patch parser: []\n\n"

I've tried both the current release of golangci-lint as well as what is in HEAD which contains the fix for macos 58ebedd but this fix does not work for Windows.

This is broken on trivial go projects on Windows, so is easily reproducable.

I have tried installing diffutils via choco (similar to homebrew on Windows)` but it doesn't appear to do anything.

Workaround

disable gci, gofmt and goimports in .golangci.yml.

Environment

Windows 11 22H2 (OS Build 22621.963)

Running linters standalone

gofmt

$ gofmt -d .
diff main.go.orig main.go
--- main.go.orig
+++ main.go
@@ -1,7 +1,7 @@
-package main
-
-import "fmt"
-
-func main() {
-       fmt.Println("wow")
-}
+package main
+
+import "fmt"
+
+func main() {
+       fmt.Println("wow")
+}

gci

Doesn't seem to give any meaningful output, so showing debug output

$ C:\Users\matjam\go\bin\gci.exe diff . -d
2022-12-20T12:31:10.347-0800    DEBUG   gci/gci.go:115  Loaded File: main.go

goimports

same as gci, I guess that means no format needs to be done.

$ goimports -d -v .
2022/12/20 12:33:00.687510 fixImports(filename="main.go"), abs="C:\\Users\\matjam\\src\\gotest\\main.go", srcDir="C:\\Users\\matjam\\src\\gotest" ...
diff -u main.go.orig main.go

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.50.1 built from 8926a95f on 2022-10-22T10:50:47Z

Configuration file

$ cat .golangci.yml
linters:
  enable-all: true
  disable:
    - ifshort
    - scopelint
    - nosnakecase
    - interfacer
    - structcheck
    - deadcode
    - exhaustivestruct
    - maligned
    - varcheck
    - golint
    - rowserrcheck
    - sqlclosecheck
    - structcheck
    - wastedassign

Go environment

$ go version
go version go1.19.4 windows/amd64
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\matjam\AppData\Local\go-build
set GOENV=C:\Users\matjam\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\matjam\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\matjam\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=C:\Users\matjam\src\tmp
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\matjam\src\aaa\go.mod
set GOWORK=
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\matjam\src\tmp\go-build888202901=/tmp/go-build -gno-record-gcc-switches

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ C:\\Users\\matjam\\src\\aaa C:\\Users\\matjam\\src C:\\Users\\matjam C:\\Users C:\\]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 87 linters: [asasalint asciicheck bidichk bodyclose containedctx contextcheck cyclop decorder depguard dogsled dupl dupword durationcheck errcheck errchkjson errname errorlint execinquery exhaustive exhaustruct exportloopref forbidigo forcetypeassert funlen gci gochecknoglobals gochecknoinits gocognit goconst gocritic gocyclo godot godox goerr113 gofmt gofumpt goheader goimports gomnd gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper importas ineffassign interfacebloat ireturn lll loggercheck maintidx makezero misspell nakedret nestif nilerr nilnil nlreturn noctx nolintlint nonamedreturns nosprintfhostport paralleltest prealloc predeclared promlinter reassign revive staticcheck stylecheck tagliatelle tenv testableexamples testpackage thelper tparallel typecheck unconvert unparam unused usestdlibvars varnamelen whitespace wrapcheck wsl]"
level=info msg="[loader] Go packages loading at mode 575 (name|types_sizes|compiled_files|deps|exports_file|files|imports) took 484.3446ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 516.3µs"
level=info msg="[linters_context] importas settings found, but no aliases listed. List aliases under alias: key."
level=info msg="[linters_context/goanalysis] analyzers took 19.8678496s with top 10 stages: buildir: 3.7615609s, buildssa: 2.0476737s, exhaustive: 1.6065353s, nilness: 1.4750624s, fact_purity: 1.4613604s, ctrlflow: 1.4155391s, typedness: 1.4109057s, printf: 1.393384s, SA5012: 1.3238458s, contextcheck: 1.1712991s"
level=warning msg="[runner] Can't run linter goanalysis_metalinter: gci: 4:13: expected ';', found \"fmt\" (and 10 more errors)"
level=info msg="[runner] processing took 0s with stages: path_prefixer: 0s, path_prettifier: 0s, exclude-rules: 0s, diff: 0s, severity-rules: 0s, identifier_marker: 0s, source_code: 0s, cgo: 0s, filename_unadjuster: 0s, path_shortener: 0s, nolint: 0s, uniq_by_line: 0s, max_per_file_from_linter: 0s, max_same_issues: 0s, skip_files: 0s, skip_dirs: 0s, autogenerated_exclude: 0s, exclude: 0s, max_from_linter: 0s, sort_results: 0s"
level=info msg="[runner] linters took 2.5545941s with stages: goanalysis_metalinter: 2.5545941s"
level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: gci: 4:13: expected ';', found \"fmt\" (and 10 more errors)\n\n"
level=info msg="Memory: 32 samples, avg is 167.4MB, max is 336.0MB"
level=info msg="Execution took 3.0809582s"

Same output for current HEAD version.

Code example or link to a public repository

go.mod:

module github.com/matjam/gotest

go 1.19

main.go:

package main

import "fmt"

func main() {
	fmt.Println("wow")
}

.golangci.yml:

linters:
  enable-all: true
  disable:
    - ifshort
    - scopelint
    - nosnakecase
    - interfacer
    - structcheck
    - deadcode
    - exhaustivestruct
    - maligned
    - varcheck
    - golint
    - rowserrcheck
    - sqlclosecheck
    - structcheck
    - wastedassign
@matjam matjam added the bug Something isn't working label Dec 20, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 20, 2022

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez ldez added the platform: windows Issue that is related to Windows label Dec 20, 2022
@ldez
Copy link
Member

ldez commented Dec 20, 2022

duplicate of #3408

@ldez ldez closed this as completed Dec 20, 2022
@ldez ldez added duplicate This issue or pull request already exists and removed bug Something isn't working platform: windows Issue that is related to Windows labels Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants