golangci-lint
golangci-lint copied to clipboard
Using `--fix` with both `gofumpt` and `gocritic` linters deletes comment lines
Welcome
- [X] Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
- [X] Yes, I've searched similar issues on GitHub and didn't find any.
- [X] Yes, I've included all information below (version, config, etc).
- [X] Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)
Description of the problem
Using golangci-lint with --fix flag and both gofumpt and gocritic linters enabled deletes comment lines.
This is the case with at least comment lines missing a space after //.
In minimal example running with golangci-lint run --fix --disable-all --enable gocritic,gofumpt with no .golangci.yml config file.
Using either gofumpt or gocritic alone has the expected behavior (e.g. adding whitespace after //)
Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.49.0 built from cc2d97f3 on 2022-08-24T10:24:37Z
Configuration file
$ cat .golangci.yml
cat: .golangci.yml: No such file or directory
Go environment
$ go version && go env
go version go1.19 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/psaikko/.cache/go-build"
GOENV="/home/psaikko/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/psaikko/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/psaikko/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4702641=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v --fix --disable-all --enable gocritic,gofumpt main.go
INFO [config_reader] Config search paths: [./ /home/psaikko/lintbug /home/psaikko /home /]
INFO [lintersdb] Active 2 linters: [gocritic gofumpt]
INFO [loader] Go packages loading at mode 575 (types_sizes|compiled_files|deps|exports_file|imports|files|name) took 132.829788ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 172.936µs
INFO [linters context/goanalysis] analyzers took 5.195754ms with top 10 stages: gocritic: 4.979514ms, gofumpt: 216.24µs
INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 2/2, exclude: 2/2, max_from_linter: 2/2, source_code: 2/2, cgo: 2/2, skip_dirs: 2/2, autogenerated_exclude: 2/2, max_per_file_from_linter: 2/2, path_prefixer: 2/2, path_prettifier: 2/2, skip_files: 2/2, identifier_marker: 2/2, diff: 2/2, sort_results: 2/2, exclude-rules: 2/2, nolint: 2/2, uniq_by_line: 2/2, max_same_issues: 2/2, path_shortener: 2/2, severity-rules: 2/2
INFO [runner] processing took 230.733µs with stages: exclude-rules: 68.396µs, identifier_marker: 59.956µs, nolint: 32.522µs, autogenerated_exclude: 21.874µs, path_prettifier: 17.159µs, source_code: 12.761µs, skip_dirs: 9.658µs, path_shortener: 1.352µs, cgo: 1.236µs, max_same_issues: 1.06µs, filename_unadjuster: 904ns, uniq_by_line: 647ns, max_per_file_from_linter: 632ns, skip_files: 631ns, max_from_linter: 569ns, severity-rules: 341ns, exclude: 312ns, diff: 310ns, sort_results: 232ns, path_prefixer: 181ns
INFO [runner] linters took 540.551663ms with stages: goanalysis_metalinter: 540.238954ms
INFO Line 6 has multiple issues but at least one of them isn't inline: []result.Issue{result.Issue{FromLinter:"gocritic", Text:"commentFormatting: put a space between `//` and comment text", Severity:"", SourceLines:[]string{"\t//standard greeting"}, Replacement:(*result.Replacement)(0xc0010f4030), Pkg:(*packages.Package)(0xc000b1ec00), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"main.go", Offset:43, Line:6, Column:2}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}, result.Issue{FromLinter:"gofumpt", Text:"File is not `gofumpt`-ed", Severity:"", SourceLines:[]string{"\t//standard greeting"}, Replacement:(*result.Replacement)(0xc000f96610), Pkg:(*packages.Package)(0xc000b1ec00), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"main.go", Offset:0, Line:6, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}}
INFO Fix issue &result.Issue{FromLinter:"gocritic", Text:"commentFormatting: put a space between `//` and comment text", Severity:"", SourceLines:[]string{"\t//standard greeting"}, Replacement:(*result.Replacement)(0xc0010f4030), Pkg:(*packages.Package)(0xc000b1ec00), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"main.go", Offset:43, Line:6, Column:2}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""} with range {6 6}
INFO fixer took 206.198µs with stages: all: 206.198µs
INFO File cache stats: 1 entries of total size 93B
INFO Memory: 8 samples, avg is 45.1MB, max is 64.8MB
INFO Execution took 681.67783ms
Code example or link to a public repository
package main
import "fmt"
func main() {
//standard greeting
fmt.Println("hello world")
}
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.
I ran into this as well. It was fairly hard to add a comment to the code with this
I wonder if the issue might be triggered in general by two or more fixers being applied to the same line?
so per the closed dup issue, not just comments but also code
Fixed by #3230
@ldez above you attached link to this issue itself 🙂
Should be #3316