Skip to content
Report unwanted import path usages
Branch: master
Clone or download


Faillint is a simple Go linter that fails when a specific set of import paths are used. It's meant to be used in CI/CD environments to catch rules you want to enforce in your projects.

As an example, you could enforce the usage of instead of the errors package. To prevent the usage of the errors package, you can configure faillint to fail whenever someone imports the errors package in this case.



go get


faillint works on a file, directory or a Go package:

$ faillint -paths "errors" foo.go # pass a file
$ faillint -paths "errors" ./...  # recursively analyze all files
$ faillint -paths "errors" # or pass a package

By default, faillint will not check any import paths. You need to explicitly define it with the -paths flag, which is comma-separated list. Some examples are:

# fail if the errors package is used
-paths "errors"

# fail if the old context package is imported
-paths ""

# fail both on stdlib log and errors package to enforce other internal libraries
-paths "log,errors"

If you have a preferred import path to suggest, append the suggestion after a = character:

# fail if the errors package is used and suggest to use
-paths ""

# fail for the old context import path and suggest to use the stdlib context
-paths ""

# fail both on stdlib log and errors package to enforce other libraries
-paths ","


Assume we have the following file:

package a

import (

func foo() error {
        return errors.New("bar!")

Let's run faillint to check if errors import is used and report it:

$ faillint -paths "" a.go
a.go:4:2: package "errors" shouldn't be imported, suggested: ""

The need for this tool?

Most of these checks should be probably detected during the review cycle. But it's totally normal to accidentally import them (we're all humans in the end).

Second, tools like goimports favors certain packages. As an example going forward if you decided to use in you project, and write errors.New() in a new file, goimports will automatically import the errors package (and not The code will perfectly compile. faillint would be able to detect and report it to you.


This tool is built on top of the excellent go/analysis package that makes it easy to write custom analyzers in Go. If you're interested in writing a tool, check out my Using go/analysis to write a custom linter blog post.

Part of the code is modified and based on astutil.UsesImport

You can’t perform that action at this time.