Skip to content

GCI cannot use custom section ordering, and cannot use multiple prefixes added in gci 0.10.0 #3776

Closed
@deathbots

Description

@deathbots

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

Custom section ordering was not working if specified in the config file.

Additionally, gci mentions a breaking change in version 0.10.0. See PR which means comma-separated sections no longer work.

golangci-lint would need to change how the linter is executed to support the new style.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.51.2 built from 3e8facb4 on 2023-02-19T21:43:54Z

Configuration file

$ cat .golangci.yml
linters-settings:

  gci:
    sections:
      - standard                                                    # stdlib
      - default                                                     # other
      - prefix(github.com/[Redacted],github.com/[Redacted])         # us
    skip-generated: false
    custom-order: true                        # enable sections-based sorting


linters:
  disable-all: true
  enable:
    - gci

Go environment

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/[redacted]/Library/Caches/go-build"
GOENV="/Users/[redacted]/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/[redacted]/.direnv/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/[redacted]/.gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/[redacted]/go.mod"
GOWORK="/Users/[redacted]/go.work"
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/83/vbv2phhx2g11gdnr6vlnlfsm0000gn/T/go-build1961314045=/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/[redacted] /Users/[redacted] /Users /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 1 linters: [gci]          
INFO [loader] Go packages loading at mode 7 (files|compiled_files|name) took 11.794804667s 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 276.208875ms 
INFO [linters_context/goanalysis] analyzers took 2.329851837s with top 10 stages: gci: 2.329851837s 
INFO [runner] Issues before processing: 3, after processing: 0 
INFO [runner] Processors filtering stat (out/in): cgo: 3/3, autogenerated_exclude: 0/3, filename_unadjuster: 3/3, skip_dirs: 3/3, path_prettifier: 3/3, skip_files: 3/3 
INFO [runner] processing took 2.820169ms with stages: autogenerated_exclude: 2.704875ms, path_prettifier: 86.834µs, skip_dirs: 22.918µs, cgo: 1.083µs, max_same_issues: 750ns, nolint: 708ns, filename_unadjuster: 459ns, identifier_marker: 458ns, diff: 292ns, sort_results: 250ns, exclude: 250ns, exclude-rules: 249ns, uniq_by_line: 209ns, source_code: 167ns, path_shortener: 167ns, severity-rules: 167ns, skip_files: 166ns, max_from_linter: 125ns, max_per_file_from_linter: 42ns, path_prefixer: 0s 
INFO [runner] linters took 827.049459ms with stages: gci: 824.16375ms 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 131 samples, avg is 69.9MB, max is 847.9MB 
INFO Execution took 12.908264583s

Runs fine, doesn't produce desired sort

Code example or link to a public repository

// add your code here

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions