Skip to content

gofumpt collides with gocritic and comments are deleted #3894

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

Closed
4 tasks done
YishaiBerg opened this issue Jun 7, 2023 · 2 comments
Closed
4 tasks done

gofumpt collides with gocritic and comments are deleted #3894

YishaiBerg opened this issue Jun 7, 2023 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@YishaiBerg
Copy link

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

When using gocritic together with gofumpt they collide when taking care of comments with multiple lines.
In case of multiple line comments, when the first line does not have a whitespace, it will be deleted. If there are more than 2 lines, the first line will be deleted and the rest of the lines will remain unfixed.
For example:

//foo
// foobar

expected:

// foo
// foobar

actual:

// foobar

and in case of 3 lines:

//bar
//foo
// foobar

expected:

// bar
// foo
// foobar

actual:

//foo
// foobar

It is possible to solve it by silencing the commentFormatting check in gocritic, I'm just afraid this bug will come back to bite me in some other scenario.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.52.2 built with go1.20.2 from da04413 on 2023-03-23T16:18:48Z

Configuration file

linters:
  enable:
    - funlen
    - gocognit
    - gocritic
    - godot
    - gofumpt
    - loggercheck
    - misspell
    - whitespace
linters-settings:
  gocognit:
    min-complexity: 10
issues:
  fix: true

Go environment

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/.../Caches/go-build"
GOENV="/.../Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/.../go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/.../go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.4/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/.../go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5m/jf5mvvt955jc3_fmn2sccvfc0000gn/T/go-build567769021=/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: [...] 
INFO [config_reader] Used config file .golangci.yaml 
INFO [lintersdb] Active 15 linters: [errcheck funlen gocognit gocritic godot gofumpt gosimple govet ineffassign loggercheck misspell staticcheck typecheck unused whitespace] 
INFO [loader] Go packages loading at mode 575 (imports|name|deps|exports_file|files|types_sizes|compiled_files) took 184.800916ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 1.964416ms 
INFO [linters_context/goanalysis] analyzers took 5.610243706s with top 10 stages: buildir: 3.999506707s, fact_deprecated: 272.253707ms, inspect: 206.637835ms, printf: 200.667166ms, ctrlflow: 174.752632ms, nilness: 138.261496ms, fact_purity: 137.41108ms, SA5012: 131.85204ms, typedness: 106.718828ms, gocritic: 33.799375ms 
INFO [runner] Line 12 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{"//foo"}, Replacement:(*result.Replacement)(0x1400b309a10), Pkg:(*packages.Package)(0x14001194000), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"...", Offset:154, Line:12, Column:1}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}, result.Issue{FromLinter:"gofumpt", Text:"File is not `gofumpt`-ed", Severity:"", SourceLines:[]string{"//foo"}, Replacement:(*result.Replacement)(0x140033ced90), Pkg:(*packages.Package)(0x14001194000), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"...", Offset:0, Line:12, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""}} 
INFO [runner] Fix issue &result.Issue{FromLinter:"gocritic", Text:"commentFormatting: put a space between `//` and comment text", Severity:"", SourceLines:[]string{"//foo"}, Replacement:(*result.Replacement)(0x1400b309a10), Pkg:(*packages.Package)(0x14001194000), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"...", Offset:154, Line:12, Column:1}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""} with range {12 12} 
INFO [runner] Fix issue &result.Issue{FromLinter:"gofumpt", Text:"File is not `gofumpt`-ed", Severity:"", SourceLines:[]string{""}, Replacement:(*result.Replacement)(0x1400d533510), Pkg:(*packages.Package)(0x1400119f380), LineRange:(*result.Range)(nil), Pos:token.Position{Filename:"...", Offset:0, Line:166, Column:0}, HunkPos:0, ExpectNoLint:false, ExpectedNoLintLinter:""} with range {166 166} 
INFO [runner] fixer took 1.336209ms with stages: all: 1.336209ms 
INFO [runner] Issues before processing: 6, after processing: 0 
INFO [runner] Processors filtering stat (out/in): skip_files: 6/6, autogenerated_exclude: 3/6, exclude: 3/3, max_same_issues: 3/3, source_code: 3/3, path_prettifier: 6/6, uniq_by_line: 3/3, path_shortener: 3/3, filename_unadjuster: 6/6, skip_dirs: 6/6, identifier_marker: 3/3, diff: 3/3, max_per_file_from_linter: 3/3, max_from_linter: 3/3, cgo: 6/6, exclude-rules: 3/3, nolint: 3/3, severity-rules: 3/3, fixer: 0/3 
INFO [runner] processing took 1.965625ms with stages: fixer: 1.354417ms, nolint: 212.041µs, path_prettifier: 128.458µs, autogenerated_exclude: 111.459µs, source_code: 57.375µs, exclude-rules: 37µs, identifier_marker: 33.542µs, skip_dirs: 26.166µs, cgo: 1.25µs, max_same_issues: 708ns, filename_unadjuster: 584ns, uniq_by_line: 501ns, path_shortener: 500ns, severity-rules: 333ns, skip_files: 292ns, max_from_linter: 250ns, max_per_file_from_linter: 208ns, exclude: 207ns, diff: 167ns, sort_results: 126ns, path_prefixer: 41ns 
INFO [runner] linters took 1.911119209s with stages: goanalysis_metalinter: 1.909111s 
INFO File cache stats: 17 entries of total size 36.3KiB 
INFO Memory: 23 samples, avg is 253

Code example or link to a public repository

//foo
//bar
// foobar
@YishaiBerg YishaiBerg added the bug Something isn't working label Jun 7, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 7, 2023

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

@bombsimon
Copy link
Member

Duplicate of #3230

@bombsimon bombsimon marked this as a duplicate of #3230 Jun 7, 2023
@ldez ldez added duplicate This issue or pull request already exists and removed bug Something isn't working labels Jun 7, 2023
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

3 participants