Skip to content

How to configure upperCaseConst for the var-naming rule within golangci-lint for revive? #4091

@takanuva15

Description

@takanuva15

Welcome

Description of the problem

I'm confused how to configure upperCaseConst for the var-naming rule within golangci-lint for revive. The linter-setting documentation in golangci-lint only shows 2 arguments for the var-naming rule. How would I specify the upperCaseConst option?

The revive documentation on the upperCaseConst option is listed here.

I tried this in my .golangci.yml but it doesn't seem to work with the golangci-lint GitHub action. It still tells me to remove ALL_CAPS constants:

linters-settings:
  revive:
    rules:
      - name: var-naming
        arguments:
          - []
          - []
          - [{upperCaseConst=true}]

If I run revive -config revive.toml in my MVE repo, it works fine so I know the revive linter is working correctly.

Version of golangci-lint

Details
$ golangci-lint --version
golangci-lint has version 1.54.2 built with go1.21.0 from 411e0bbb on 2023-08-21T12:04:32Z

Configuration

Details

.golangci.yml

linters-settings:
  revive:
    rules:
      - name: unexported-return
        disabled: true
      - name: var-naming
        arguments:
          - []
          - []
          - [{upperCaseConst=true}]

linters:
  enable:
    - revive

revive.toml

[rule.package-comments]

[rule.var-naming]
  arguments = [[], [], [{upperCaseConst=true}]]

Go environment

Details
$ go version && go env
go version go1.20.3 darwin/arm64
GO111MODULE=""
GOARCH="arm64"
GOBIN="/Users/me/go/bin"
GOCACHE="/Users/me/Library/Caches/go-build"
GOENV="/Users/me/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/me/go/pkg/mod"
GONOPROXY="github.com/mycompany/*"
GONOSUMDB="github.com/mycompany/*"
GOOS="darwin"
GOPATH="/Users/me/go"
GOPRIVATE="github.com/mycompany/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.3/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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/v4/3h3xcz0n74x0_c7fwr00cln40000gq/T/go-build2106927852=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

Details
$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /Users/me/Documents/Repositories_external/golangci-lint-revive-upperCaseConst-demo /Users/me/Documents/Repositories_external /Users/me/Documents /Users/me /Users /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 7 linters: [errcheck gosimple govet ineffassign revive staticcheck unused]
INFO [loader] Go packages loading at mode 575 (deps|exports_file|imports|compiled_files|files|name|types_sizes) took 237.375416ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 984.583µs
INFO [linters_context/goanalysis] analyzers took 719.635916ms with top 10 stages: buildir: 505.977996ms, inspect: 32.040998ms, printf: 31.530294ms, ctrlflow: 30.485089ms, fact_deprecated: 27.137495ms, nilness: 22.585125ms, SA5012: 22.257791ms, fact_purity: 21.420751ms, typedness: 16.309542ms, the_only_name: 2.912458ms
INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 1/1, fixer: 1/1, severity-rules: 1/1, path_prettifier: 1/1, autogenerated_exclude: 1/1, uniq_by_line: 1/1, diff: 1/1, max_same_issues: 1/1, path_shortener: 1/1, cgo: 1/1, identifier_marker: 1/1, exclude-rules: 1/1, max_per_file_from_linter: 1/1, source_code: 1/1, path_prefixer: 1/1, sort_results: 1/1, skip_files: 1/1, skip_dirs: 1/1, exclude: 1/1, nolint: 1/1, max_from_linter: 1/1
INFO [runner] processing took 238.501µs with stages: path_prettifier: 85.376µs, nolint: 34.375µs, identifier_marker: 28.959µs, autogenerated_exclude: 28.875µs, exclude-rules: 26.75µs, source_code: 19.541µs, skip_dirs: 8.917µs, uniq_by_line: 1.208µs, max_same_issues: 792ns, cgo: 667ns, max_from_linter: 583ns, path_shortener: 375ns, filename_unadjuster: 334ns, exclude: 292ns, severity-rules: 291ns, max_per_file_from_linter: 250ns, skip_files: 209ns, sort_results: 208ns, fixer: 208ns, diff: 208ns, path_prefixer: 83ns
INFO [runner] linters took 537.616959ms with stages: goanalysis_metalinter: 537.327875ms
main.go:5:7: var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive)
const NOUN_SUBJECT = "World"
      ^
INFO File cache stats: 1 entries of total size 116B
INFO Memory: 9 samples, avg is 112.5MB, max is 210.9MB
INFO Execution took 787.058167ms

A minimal reproducible example or link to a public repository

Details

I've made an MVE repository here.

You can view the output of the golangci-lint GitHub action on the main branch here.

Validation

  • Yes, I've included all information above (version, config, etc.).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions