OpenPeeDeeP / depguard

Go linter that checks if package imports are in a list of acceptable packages.
GNU General Public License v3.0
138 stars 15 forks source link

depguard doesn't seem to respect configuration #93

Open ptokarski opened 4 months ago

ptokarski commented 4 months ago
$ golangci-lint --version
golangci-lint has version v1.57.2 built with go1.22.2 from (unknown, modified: ?, mod sum: "h1:NNhxfZyL5He1WWDrIvl1a4n5bvWZBcgAqBwlJAAgLTw=") on (unknown)

main.go:

package main

import _ "github.com/lib/pq"

func main() {}

go.mod

module main

go 1.22.2

require github.com/lib/pq v1.10.9

go.sum

github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=

.golangci.yml

linters:
  enable:
    - depguard

.depguard.yml

Main:
  files:
    - $all
    - "!$test"
  allow:
    - $gostd
    - github.com/lib/pq
  deny:
    reflect: Please don't use reflect package
Test:
  files:
    - $test
  allow:
    - $gostd
    - github.com/stretchr/testify
  deny:
    reflect: Please don't use reflect package

invocation:

$ golangci-lint run
main.go:3:8: import 'github.com/lib/pq' is not allowed from list 'Main' (depguard)
import _ "github.com/lib/pq"
       ^

I think I did everything as it is describe in the docs. Expected not to see an issue.

dixonwille commented 4 months ago

When using golangci-lint, you should use their configuration file to configure depguard. Here is an example pulled for your specific verison of golangci-lint. https://github.com/golangci/golangci-lint/blob/77a8601aa372eaab3ad2d7fa1dffa71f28005393/.golangci.reference.yml#L210

Please respond back after making these changes whether or not moving the configuration into golangci-lint's configuration works.

https://github.com/OpenPeeDeeP/depguard?tab=readme-ov-file#golangci-lint