0
votes

In my small project, I have a script that ensures proper code quality by running static code checks, for example, I use errcheck to verify that I handle every error in my code. In dep, there was a special section for that kind of dependencies, called required

Use this for: linters, generators, and other development tools that:

  • Are needed by your project
  • Aren't imported by your project, directly or transitively

For go modules, I can fetch given version of errcheck by executing: go get github.com/kisielk/[email protected]

But then, it will be removed from go.mod when I execute: go mod tidy. Is it possible to avoid such a situation?

1
you can just import the errcheck with _ instead of the name, so goimports won't remove the import and go mod tidy should work - tclass

1 Answers

1
votes

In Go modules, there is currently no distinction between “code“, “test”, and “tool” dependencies: a dependency is a dependency.

If you want to record a specific version of a tool, you can add an import of that tool's path in a source file that is normally excluded by build constraints, such as // +build tools.

For example:

// +build tools

// Package tools records tool dependencies. It cannot actually be compiled.
package tools

import _ "github.com/kisielk/errcheck"

(As JimB noted, see http://golang.org/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module for more detail.)