bandep

command module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2019 License: MIT Imports: 12 Imported by: 0

README

bandep

Bandep is a tool meant to be used in the CI and/or git commit hooks to prevent users from adding banned deps.

Use Cases

  • you have multiple packages with the same name in GOPATH (maybe even the same methods) and your editor sometimes import the wrong import in some files (example)
  • you have explicit rules in your codebase regarding which packages can import which packages

Usage

A basic usage would be to ban some deps in the current project, recursively:

bandep --pkg ./... --ban foo/bar,github.com/foo/bar

Or, for example, on DigitalOcean, they forbid the exp package to be imported from anywhere but the exp package itself:

go list -f '{{ .Dir }}' -e ./... | grep -v do/exp | while read -r pkg; do
  bandep --pkg $pkg --ban do/exp/foo
done

Composing it with shell (and go list), you can do basically anything you need.

You can, of course, add it to your git pre-commit hook. Check out this example.

Install

go get github.com/caarlos0/bandep

or

brew install caarlos0/tap/bandep

Or download one from the releases tab and install manually.

How it works

It is quite simple, really: we scan the dirs into an AST, and use that AST to check if a banned import is being used.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL