GithubHelp home page GithubHelp logo

bign8 / bandep Goto Github PK

View Code? Open in Web Editor NEW

This project forked from caarlos0-graveyard/bandep

0.0 2.0 0.0 25 KB

enforce banned dependency imports in Go code

License: MIT License

Makefile 4.54% Go 95.46%

bandep's Introduction

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 --ban 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.

bandep's People

Contributors

caarlos0 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.