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

Conflict autofix between goimports and gocritic #3690

Closed
4 tasks done
pawndev opened this issue Mar 14, 2023 · 3 comments
Closed
4 tasks done

Conflict autofix between goimports and gocritic #3690

pawndev opened this issue Mar 14, 2023 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@pawndev
Copy link

pawndev commented Mar 14, 2023

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

Hi, in advance sorry for my bad english,

I started a brand new linter config for some projects, take some time configuring all of these in golangci-lint when I saw this bug.

If i have something like this:

//PrintMeUp will print text to the console
func PrintMeUp(text string) {
	fmt.Println(text)
}

And activate gocritic and goimports in my config. Launch lint with golangci-lint run -v --fix, this will remove the comment instead of adding a whitespace between // and the sentence.
If I deactivate one of the two linters, it works like a charm.
I added a reproducible repository in the Code example or link to a public repository section below.

Thanks in advance !

Version of golangci-lint

$ golangci-lint --version
# golangci-lint has version v1.51.2 built from (unknown, mod sum: "h1:yIcsT1X9ZYHdSpeWXRT1ORC/FPGSqDHbHsu9uk4FK7M=") on (unknown)

Configuration file

$ cat .golangci.yml
run:
  concurrency: 4
  # timeout for analysis, e.g. 30s, 5m, default is 1m
  timeout: 5m


  # exit code when at least one issue was found, default is 1
  issues-exit-code: 1

  # include test files or not, default is true
  tests: false

  skip-dirs:
    - build/...
    - vendor/...

  # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
  # If invoked with -mod=readonly, the go command is disallowed from the implicit
  # automatic updating of go.mod described above. Instead, it fails when any changes
  # to go.mod are needed. This setting is most useful to check that go.mod does
  # not need updates, such as in a continuous integration and testing system.
  # If invoked with -mod=vendor, the go command assumes that the vendor
  # directory holds the correct copies of dependencies and ignores
  # the dependency descriptions in go.mod.
  modules-download-mode: vendor


# all available settings of specific linters
linters-settings:
  gocritic:
    # Settings passed to gocritic.
    # The settings key is the name of a supported gocritic checker.
    # The list of supported checkers can be find in https://go-critic.github.io/overview.
#    disabled-checks:
#      - commentFormatting
    settings:
      captLocal:
        # Whether to restrict checker to params only.
        # Default: true
        paramsOnly: false
      underef:
        # Whether to skip (*x).method() calls where x is a pointer receiver.
        # Default: true
        skipRecvDeref: false


linters:
  enable:
    - gocritic # provides diagnostics that check for bugs, performance and style issues
    - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
  enable-all: false
  disable-all: true
  fast: false


issues:
  # Excluding configuration per-path, per-linter, per-text and per-source
  exclude-rules:
    # Exclude some linters from running on tests files.
    - path: _test\.go
      linters:
        #        - gocyclo
        - errcheck
        - dupl
        - gosec
        - funlen
        - goconst
        - gochecknoglobals
        - gocritic
        - lll
        - noctx
        - wrapcheck
    - path: testsutils/
      linters:
        #        - gocyclo
        - errcheck
        - dupl
        - gosec
        - funlen
        - gochecknoglobals
        - gocritic
        - lll
        - wrapcheck
    - path: internal/version/
      linters:
        - gochecknoglobals
    - source: "//noinspection"
      linters: [ gocritic ]
      # Exclude `lll` issues for long lines with `go:generate`.
    - source: "^//go:generate "
      linters:
        - lll
    - source: "(noinspection|TODO)"
      linters: [ godot, lll ]

  exclude-use-default: false
  new-from-rev: ""

Go environment

$ go version && go env
go version go1.20 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/pawndev/.cache/go-build"
GOENV="/home/pawndev/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/pawndev/workspace/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/pawndev/workspace/go:/usr/lib/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/pawndev/workspace/go/golangci-lint-conflict-goimports-gocritic/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build909477859=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/pawndev/workspace/go/golangci-lint-conflict-goimports-gocritic /home/pawndev/workspace/go /home/pawndev/workspace /home/pawndev /home /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 2 linters: [gocritic goimports] 
INFO [loader] Go packages loading at mode 575 (imports|types_sizes|compiled_files|deps|exports_file|files|name) took 71.200352ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 96.673µs 
INFO [linters_context/goanalysis] analyzers took 4.110431ms with top 10 stages: gocritic: 3.191592ms, goimports: 918.839µs 
INFO [runner] Issues before processing: 2, after processing: 1 
INFO [runner] Processors filtering stat (out/in): diff: 1/1, source_code: 1/1, path_shortener: 1/1, path_prefixer: 1/1, path_prettifier: 2/2, skip_dirs: 2/2, identifier_marker: 2/2, nolint: 2/2, uniq_by_line: 1/2, max_from_linter: 1/1, severity-rules: 1/1, sort_results: 1/1, filename_unadjuster: 2/2, autogenerated_exclude: 2/2, exclude-rules: 2/2, max_same_issues: 1/1, cgo: 2/2, exclude: 2/2, max_per_file_from_linter: 1/1, skip_files: 2/2 
INFO [runner] processing took 83.609µs with stages: identifier_marker: 26.928µs, nolint: 14.526µs, path_prettifier: 12.211µs, autogenerated_exclude: 8.99µs, skip_dirs: 8.235µs, exclude-rules: 6.763µs, max_same_issues: 1.039µs, source_code: 958ns, uniq_by_line: 839ns, cgo: 824ns, max_from_linter: 466ns, filename_unadjuster: 364ns, skip_files: 346ns, path_shortener: 315ns, max_per_file_from_linter: 186ns, exclude: 184ns, severity-rules: 179ns, sort_results: 98ns, diff: 88ns, path_prefixer: 70ns 
INFO [runner] linters took 187.741069ms with stages: goanalysis_metalinter: 187.619692ms 
custom/print.go:5:1: commentFormatting: put a space between `//` and comment text (gocritic)
//PrintMeUp will print text to the console
^
INFO File cache stats: 1 entries of total size 124B 
INFO Memory: 4 samples, avg is 50.0MB, max is 60.7MB 
INFO Execution took 263.381749m

Code example or link to a public repository

Reproducible repository

@pawndev pawndev added the bug Something isn't working label Mar 14, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 14, 2023

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

@ldez ldez added question Further information is requested and removed bug Something isn't working labels Mar 14, 2023
@pawndev
Copy link
Author

pawndev commented Mar 15, 2023

If you need more information, let me know 🙂

@ldez
Copy link
Member

ldez commented Mar 16, 2023

Duplicate of #3230

@ldez ldez marked this as a duplicate of #3230 Mar 16, 2023
@ldez ldez closed this as completed Mar 16, 2023
@ldez ldez added duplicate This issue or pull request already exists and removed question Further information is requested labels Mar 16, 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

2 participants