Skip to content

Conflict gofumpt and wsl for empty lines before if statement #1510

Closed
@velp

Description

@velp

Thank you for creating the issue!

  • 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).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version v1.30.0 built from (unknown, mod sum: "h1:UhdK5WbO0GBd7W+k2lOD7BEJH4Wsa7zKfw8m3/aEJGQ=") on (unknown)
Config file
$ cat .golangci.yml
cat: .golangci.yml: No such file or directory
Go environment
$ go version && go env
go version go1.15 darwin/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/user/Work/go/pkg/mod"
GONOPROXY="github.com/user"
GONOSUMDB="github.com/user"
GOOS="darwin"
GOPATH="/Users/user/Work/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sb/v5w11ncx5vscty2qslyqvx700000gn/T/go-build126064246=/tmp/go-build -gno-record-gcc-switches -fno-common"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /Users/velp/Work/go/src/github.com/velp/test2 /Users/velp/Work/go/src/github.com/velp /Users/velp/Work/go/src/github.com /Users/velp/Work/go/src /Users/velp/Work/go /Users/velp/Work /Users/velp /Users /]
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]
INFO [loader] Go packages loading at mode 575 (exports_file|types_sizes|compiled_files|deps|files|imports|name) took 242.792256ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 293.194µs
INFO [linters context/goanalysis] analyzers took 18.81894ms with top 10 stages: buildir: 1.103903ms, S1020: 1.063927ms, ineffassign: 940.727µs, fact_deprecated: 847.572µs, S1024: 804.642µs, SA4019: 726.57µs, SA1019: 675.849µs, SA1012: 628.761µs, varcheck: 610.249µs, SA4003: 601.734µs
INFO [linters context/goanalysis] analyzers took 1.180983ms with top 10 stages: U1000: 656.494µs, buildir: 524.489µs
INFO [runner] processing took 3.378µs with stages: max_same_issues: 565ns, skip_dirs: 469ns, autogenerated_exclude: 294ns, cgo: 251ns, nolint: 235ns, filename_unadjuster: 221ns, max_from_linter: 208ns, uniq_by_line: 152ns, path_prettifier: 144ns, diff: 142ns, skip_files: 134ns, identifier_marker: 128ns, sort_results: 59ns, max_per_file_from_linter: 57ns, path_shortener: 55ns, source_code: 54ns, exclude: 54ns, exclude-rules: 53ns, severity-rules: 52ns, path_prefixer: 51ns
INFO [runner] linters took 107.323844ms with stages: goanalysis_metalinter: 70.414496ms, unused: 36.866632ms
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 5 samples, avg is 72.0MB, max is 72.6MB
INFO Execution took 398.634797ms

Description of problem

The problem: gofumpt conflicts with wsl lister for empty lines before if statement with several assignments.

Example of code

package main

import (
	"encoding/base64"
	"log"
)

func main() {
	str := "just example of code for test"
	encodedStr := base64.StdEncoding.EncodeToString([]byte(str))
	_, err := base64.StdEncoding.DecodeString(encodedStr)
	if err != nil {
		log.Fatalf("Decodding error: %s", err)
	}
}

How to reproduce:

  1. run linting
$ golangci-lint run --enable wsl,gofumpt
main.go:12:2: only one cuddle assignment allowed before if statement (wsl)
	if err != nil {
	^
  1. add new line before if statement to fix wsl error:
package main

import (
	"encoding/base64"
	"log"
)

func main() {
	str := "just example of code for test"
	encodedStr := base64.StdEncoding.EncodeToString([]byte(str))
	_, err := base64.StdEncoding.DecodeString(encodedStr)

	if err != nil {
		log.Fatalf("Decodding error: %s", err)
	}
}
  1. run linting again:
$ golangci-lint run --enable wsl,gofumpt
main.go:12: File is not `gofumpt`-ed (gofumpt)
  1. run gofumpt -w main.go to fix this problem:
$ gofumpt -w main.go
$
  1. run linting again:
$ golangci-lint run --enable wsl,gofumpt
main.go:12:2: only one cuddle assignment allowed before if statement (wsl)
	if err != nil {
	^

Ooops! WSL returns the error, again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions