Skip to content

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

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
3 tasks done
zbindenren opened this issue Feb 10, 2021 · 7 comments · Fixed by #2317
Closed
3 tasks done

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

zbindenren opened this issue Feb 10, 2021 · 7 comments · Fixed by #2317
Labels
dependencies Relates to an upstream dependency enhancement New feature or improvement

Comments

@zbindenren
Copy link

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.

@zbindenren zbindenren added the bug Something isn't working label Feb 10, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 10, 2021

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

@bombsimon
Copy link
Member

Please add an upstream issue for this in the gochecknoglobals repository and we can bump the version when it's implemented.

@bombsimon bombsimon added blocked Need's direct action from maintainer dependencies Relates to an upstream dependency labels Feb 10, 2021
@ldez ldez added enhancement New feature or improvement and removed blocked Need's direct action from maintainer bug Something isn't working labels Apr 8, 2021
@victoraugustolls
Copy link

Hi @bombsimon ! A fix was merged in gochecknoglobals! Can we bump the version here?

@bombsimon
Copy link
Member

Sure! @leighmcculloch are you planning on releasing a stable version of gochecknoglobals? If so it will be bumped automatically upon new releases. If not we'll have to update the dependency manually.

@leighmcculloch
Copy link
Contributor

leighmcculloch commented Oct 30, 2021

I think it's almost time to release a v1, but not quite yet. There's an issue, more of an RFC, that I want to pose and for us to make a decision on before tagging a v1. For the moment can we manually bump the version? I'll open the RFC and let's see if we can make v1 happen soon.

@ldez
Copy link
Member

ldez commented Oct 30, 2021

@leighmcculloch instead of creating a v1 you can create a v0.

The tags are useful for us because the dependabot can use them.
Also, the v0 (ex: v0.1.0) follows semver and the Go recommendations.

@leighmcculloch
Copy link
Contributor

Ah, got it. For some reason I thought you folks needed a stable major version. Tagged the latest as v0.1.0. https://github.com/leighmcculloch/gochecknoglobals/releases/tag/v0.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Relates to an upstream dependency enhancement New feature or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants