Skip to content
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

How to blacklist import in non-test files, but allow them in test files? #17

Closed
marten-seemann opened this issue Aug 4, 2020 · 3 comments

Comments

@marten-seemann
Copy link

I'm using the Ginkgo test framework for unit tests in one of my projects. I want to allow importing of github.com/onsi/ginkgo in all _test.go files, but disallow it in non-test files, so that a build of my production code doesn't pull in a test framework.

I can't figure out how to configure depguard to perform that check. Is it possible?

@dixonwille
Copy link
Member

dixonwille commented Aug 27, 2020

You will need to setup a whitelist and only put th ginkgo package in the InTest configuration portion of the tool. Unfortunatly the configuration doesn't allow for split list types. So you will need to whitelist all non test packages too.

@m000
Copy link

m000 commented Apr 7, 2021

I believe that if inTests is empty, then whatever is in packages also applies to tests. So, listing anything in inTests makes it work. Something like this. It's ugly, but seems to work.

{
  "type": "blacklist",
  "packages": [
    "github.com/onsi/ginkgo"
  ],                                                                                                                
  "inTests": [
    "this isn't even a proper package name"
  ],  
  "includeGoStdLib": true
}

@timkral
Copy link
Contributor

timkral commented Dec 24, 2021

I realize that this thread is a bit old, but I was having a similar problem and I submitted a Pull Request to allow for partial list types - #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants