Skip to content

depguard linter emits alert #3116

Closed
@jerome-laforge

Description

@jerome-laforge

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. (https://golangci-lint.run/usage/linters/)

Description of the problem

With golangci/golangci-lint:v1.48 docker image (works fine with golangci/golangci-lint:v1.47 docker image), depguard linter emits those alerts:

xxxx: `github.com/gin-gonic/gin` is in the denylist (depguard)
        "github.com/gin-gonic/gin"

xxxx `github.com/davecgh/go-spew/spew` is in the denylist (depguard)
        "github.com/davecgh/go-spew/spew"
...
...

I don't have those errors, when I run golangci-lint with binary of course with the same version of docker image (i.e. v1.38) (fetched by arch package https://aur.archlinux.org/packages/golangci-lint-bin).

Of course, I don't put this package into my .golangci.yml, plz find the extract for depguard:

  depguard:
    list-type: blacklist
    include-go-root: true
    packages:
      - io/ioutil
      - math/rand
      - golang.org/x/net/context
      - github.com/satori/go.uuid
      - gopkg.in/go-playground/assert.v1
      - github.com/magiconair/properties/assert
      - github.com/globalsign/mgo
      - github.com/globalsign/mgo/bson

I run golangci/golangci-lint:v1.48 docker image within makefile:

linter:
	mkdir -p /tmp/.cache_golint
	docker run -it --rm -e GOLANGCI_LINT_CACHE=/tmp/.cache -v ${HOME}/go:/go -v /tmp/.cache_golint:/tmp/.cache -v  $(CURDIR):/app -w /app golangci/golangci-lint:${LINTERVERSION} sh -c "/usr/bin/golangci-lint run"

Version of golangci-lint

v1.48

Configuration file

$ cat .golangci.yml


# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
  # default concurrency is a available CPU number
  #  concurrency: 4

  # timeout for analysis, e.g. 30s, 5m, default is 1m
  deadline: 20m

  # 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: true

  # list of build tags, all linters use it. Default is empty list.
  build-tags:
  #    - mytag


  # which files to skip: they will be analyzed, but issues from them
  # won't be reported. Default value is empty list, but there is
  # no need to include all autogenerated files, we confidently recognize
  # autogenerated files. If it's not please let us know.
  skip-files:
    - .*_pie.go$

  # 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: readonly|release|vendor


# output configuration options
output:
  # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
  format: colored-line-number

  # print lines of code with issue, default is true
  print-issued-lines: true

  # print linter name in the end of issue text, default is true
  print-linter-name: true


# all available settings of specific linters
linters-settings:
  errcheck:
    # report about not checking of errors in type assetions: `a := b.(MyStruct)`;
    # default is false: such cases aren't reported by default.
    check-type-assertions: false

    # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
    # default is false: such cases aren't reported by default.
    check-blank: false

    # [deprecated] comma-separated list of pairs of the form pkg:regex
    # the regex is used to ignore names within pkg. (default "fmt:.*").
    # see https://github.com/kisielk/errcheck#the-deprecated-method for details
    #    ignore: fmt:.*,io/ioutil:^Read.*

    # path to a file containing a list of functions to exclude from checking
    # see https://github.com/kisielk/errcheck#excluding-functions for details
  #    exclude: /path/to/file.txt
  govet:
    # settings per analyzer
    settings:
      printf: # analyzer name, run `go tool vet help` to see all analyzers
        funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf

    # enable or disable analyzers by name
    # run `go tool vet help` to see all analyzers
    enable-all: true
    disable:
      - composites
      - fieldalignment
      - shadow

  golint:
    # minimal confidence for issues, default is 0.8
    min-confidence: 0.8
  gofmt:
    # simplify code: gofmt with `-s` option, true by default
    simplify: true
  goimports:
  # put imports beginning with prefix after 3rd-party packages;
  # it's a comma-separated list of prefixes
  #    local-prefixes: github.com/org/project
  gocyclo:
    # minimal code complexity to report, 30 by default (but we recommend 10-20)
    min-complexity: 10
  dupl:
    # tokens count to trigger issue, 150 by default
    threshold: 100
  goconst:
    # minimal length of string constant, 3 by default
    min-len: 3
    # minimal occurrences count to trigger, 3 by default
    min-occurrences: 3
  depguard:
    list-type: blacklist
    include-go-root: true
    packages:
      - io/ioutil
      - math/rand
      - golang.org/x/net/context
      - github.com/satori/go.uuid
      - gopkg.in/go-playground/assert.v1
      - github.com/magiconair/properties/assert
      - github.com/globalsign/mgo
      - github.com/globalsign/mgo/bson

  misspell:
    # Correct spellings using locale preferences for US or UK.
    # Default is to use a neutral variety of English.
    # Setting locale to US will correct the British spelling of 'colour' to 'color'.
    locale: US
    #    ignore-words:
    #      - someword
    #  lll:
    # max line length, lines longer will be reported. Default is 120.
    # '\t' is counted as 1 character by default, and can be changed with the tab-width option
    #    line-length: 120
    # tab width in spaces. Default to 1.
  #    tab-width: 1
  unused:
    # treat code as a program (not a library) and report unused exported identifiers; default is false.
    # XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
    # if it's called for subdir of a project it can't find funcs usages. All text editor integrations
    # with golangci-lint call it on a directory with the changed file.
    check-exported: false
  unparam:
    # Inspect exported functions, default is false. Set to true if no external program/library imports your code.
    # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
    # if it's called for subdir of a project it can't find external interfaces. All text editor integrations
    # with golangci-lint call it on a directory with the changed file.
    check-exported: false
  nakedret:
    # make an issue if func has more lines of code than this setting and it has naked returns; default is 30
    max-func-lines: 30
  prealloc:
    # XXX: we don't recommend using this linter before doing performance profiling.
    # For most programs usage of prealloc will be a premature optimization.

    # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
    # True by default.
    simple: true
    range-loops: true # Report preallocation suggestions on range loops, true by default
    for-loops: true # Report preallocation suggestions on for loops, false by default
  gocritic:
    # Which checks should be enabled; can't be combined with 'disabled-checks';
    # See https://go-critic.github.io/overview#checks-overview
    # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
    # By default list of stable checks is used.
    enabled-checks:
    #      - rangeValCopy

    # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
    disabled-checks:
      - regexpMust

    # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks.
    # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
    enabled-tags:
      - performance

    settings: # settings passed to gocritic
      captLocal: # must be valid enabled check name
        paramsOnly: true
      rangeValCopy:
        sizeThreshold: 32

  forbidigo:
    # Forbid the following identifiers
    forbid:
      - ^fmt\.Print(|f|ln)$
      - ^spew\.Dump$
      - ^spew\.Print(|f|ln)$

linters:
  enable-all: true
  disable:
    - asciicheck
    - containedctx
    - contextcheck
    - cyclop
    - dupl
    - durationcheck
    - exhaustive
    - exhaustivestruct
    - exhaustruct
    - forcetypeassert
    - funlen
    - gci
    - gochecknoglobals
    - gochecknoinits
    - gocognit
    - goconst
    - gocritic
    - gocyclo
    - godot
    - godox
    - goerr113
    - gofumpt
    - golint
    - gomnd
    - interfacer
    - ireturn
    - lll
    - maintidx
    - maligned
    - misspell
    - nakedret
    - nestif
    - nlreturn
    - noctx
    - nonamedreturns
    - nosnakecase
    - paralleltest
    - revive
    - scopelint
    - staticcheck
    - stylecheck
    - tagliatelle
    - testpackage
    - thelper
    - varnamelen
    - wrapcheck
    - wsl
  disable-all: false
  fast: false


issues:

  # Independently from option `exclude` we use default exclude patterns,
  # it can be disabled by this option. To list all
  # excluded by default patterns execute `golangci-lint run --help`.
  # Default value for this option is true.
  exclude-use-default: false

  # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
  max-per-linter: 0

  # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
  max-same-issues: 0

  # Show only new issues: if there are unstaged changes or untracked files,
  # only those changes are analyzed, else only changes in HEAD~ are analyzed.
  # It's a super-useful option for integration of golangci-lint into existing
  # large codebase. It's not practical to fix all existing issues at the moment
  # of integration: much better don't allow issues in new code.
  # Default is false.
  new: false

  # Show only new issues created after git revision `REV`
  #  new-from-rev: REV

  # Show only new issues created in git patch with set file path.
#  new-from-patch: path/to/patch/file

Go environment

$ go version && go env
go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/user/dev/OM/MYPROJECT/bin"
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org"
GOROOT="/home/user/sdk/go1.19"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/user/sdk/go1.19/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/user/dev/OM/MYPROJECT/src/myproject/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build684505404=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

xxxx: `github.com/gin-gonic/gin` is in the denylist (depguard)
        "github.com/gin-gonic/gin"

xxxx `github.com/davecgh/go-spew/spew` is in the denylist (depguard)
        "github.com/davecgh/go-spew/spew"

Code example or link to a public repository

It is just an import

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdependenciesRelates to an upstream dependency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions