Skip to content

[gochecknoglobals] should ignore variables prefixed with //go:embed #1727

Closed
@zbindenren

Description

@zbindenren

Thank you for creating the issue!

  • 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).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.36.0 built from 6c25d06 on 2021-01-26T13:14:05Z
Config file
$ cat .golangci.yml
---
run:
  tests: false
  skip-dirs:
    - .github
    - build
    - web
    - .go
linters-settings:
  dupl:
    threshold: 100
  funlen:
    lines: 100
    statements: 50
  goconst:
    min-len: 2
    min-occurrences: 2
  gocritic:
    enabled-tags:
      - diagnostic
      - experimental
      - opinionated
      - performance
      - style
    disabled-checks:
      - whyNoLint
      - hugeParam
  gocyclo:
    min-complexity: 15
  golint:
    min-confidence: 0.8
  govet:
    check-shadowing: true
  lll:
    line-length: 140
  maligned:
    suggest-new: true
  misspell:
    locale: US
  nolintlint:
    allow-leading-space: false
    require-explanation: true
    allow-no-explanation:
      - gocognit
      - funlen
      - gocyclo

linters:
  disable-all: true
  enable:
    - bodyclose
    - deadcode
    - depguard
    - dogsled
    - dupl
    - errcheck
    - funlen
    - nolintlint
    - gochecknoglobals
    - gochecknoinits
    - gocognit
    - goconst
    - gocritic
    - gocyclo
    # - godox
    - gofmt
    - goimports
    - golint
    - goprintffuncname
    - gosec
    - gosimple
    - govet
    - ineffassign
    - interfacer
    # - lll
    - maligned
    - misspell
    - nakedret
    - prealloc
    - rowserrcheck
    - scopelint
    - staticcheck
    - structcheck
    - stylecheck
    - typecheck
    - unconvert
    - unparam
    - unused
    - varcheck
    - whitespace
    - wsl

issues:
  exclude:
    # Very commonly not checked.
    - 'Error return value of .(l.Sync|.*Close|.*.Write|.*Flush|os\.Remove(All)?|os\.(Un)?Setenv). is not checked'
    - 'G104:.*'
    - 'exported method (.*\.MarshalJSON|.*\.UnmarshalJSON) should have comment or be unexported'
    - 'shadow: declaration of "err" shadows declaration.*'
  max-same-issues: 0
  exclude-use-default: false
Go environment
$ go version && go env
go version go1.16rc1 linux/amd64
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/rz/.cache/go-build"
GOENV="/home/rz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/rz/golang/pkg/mod"
GONOPROXY="*.pnet.ch"
GONOSUMDB="*.pnet.ch"
GOOS="linux"
GOPATH="/home/rz/golang"
GOPRIVATE="*.pnet.ch"
GOPROXY="https://proxy.golang.org"
GOROOT="/home/rz/.gimme/versions/go1.16rc1.linux.amd64"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/rz/.gimme/versions/go1.16rc1.linux.amd64/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16rc1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/rz/repos/git.pnet.ch/golang/create-go-app/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3664690889=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Used config file .golangci.yaml 
INFO [lintersdb] Active 39 linters: [bodyclose deadcode depguard dogsled dupl errcheck funlen gochecknoglobals gochecknoinits gocognit goconst gocritic gocyclo gofmt goimports golint goprintffuncname gosec gosimple govet ineffassign interfacer maligned misspell nakedret nolintlint prealloc rowserrcheck scopelint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace wsl] 
INFO [loader] Go packages loading at mode 575 (deps|types_sizes|compiled_files|exports_file|files|imports|name) took 290.181193ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 1.876901ms 
INFO [linters context/goanalysis] analyzers took 0s with no stages 
INFO [linters context/goanalysis] analyzers took 0s with no stages 
INFO [runner] Issues before processing: 34, after processing: 1 
INFO [runner] Processors filtering stat (out/in): identifier_marker: 21/21, exclude: 15/21, nolint: 1/15, source_code: 1/1, cgo: 34/34, skip_dirs: 34/34, diff: 1/1, max_from_linter: 1/1, severity-rules: 1/1, sort_results: 1/1, path_prettifier: 34/34, skip_files: 34/34, exclude-rules: 15/15, max_per_file_from_linter: 1/1, max_same_issues: 1/1, path_shortener: 1/1, filename_unadjuster: 34/34, uniq_by_line: 1/1, path_prefixer: 1/1, autogenerated_exclude: 21/34 
INFO [runner] processing took 2.075051ms with stages: nolint: 1.126563ms, identifier_marker: 397.833µs, exclude: 161.34µs, path_prettifier: 132.708µs, autogenerated_exclude: 126.487µs, skip_dirs: 72.946µs, cgo: 19.316µs, source_code: 17.573µs, filename_unadjuster: 3.075µs, path_shortener: 2.795µs, uniq_by_line: 2.634µs, max_from_linter: 2.295µs, max_same_issues: 2.074µs, max_per_file_from_linter: 1.343µs, diff: 1.212µs, sort_results: 1.072µs, exclude-rules: 1.042µs, severity-rules: 981ns, skip_files: 961ns, path_prefixer: 801ns 
INFO [runner] linters took 71.703275ms with stages: goanalysis_metalinter: 67.820908ms, unused: 819.335µs 
assets.go:8:2: assets is a global variable (gochecknoglobals)
        assets embed.FS
        ^
INFO File cache stats: 1 entries of total size 216B 
INFO Memory: 5 samples, avg is 71.3MB, max is 71.8MB 
INFO Execution took 371.860433ms                  

I have to add a nolint comment to the following code:

// Package assets contains templates.
package assets

import "embed"

var (
        //go:embed templates
        assets embed.FS //nolint: gochecknoglobals // no other possibility
)

// Get gets the templates in templates folder as embed.FS.
func Get() embed.FS {
        return assets
}

The gochecknoglobals should ignore global variables prefixed with the new go 1.6 feature: //go:embed like it already does for regular expressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesRelates to an upstream dependencyenhancementNew feature or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions