Add goconst-check

This commit is contained in:
kolaente 2020-09-01 22:11:20 +02:00
parent 1596a4266a
commit 0ccaaf943d
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 6 additions and 1 deletions

View File

@ -62,6 +62,7 @@ var (
"gocyclo-check": GocycloCheck,
"static-check": StaticCheck,
"gosec-check": GoSecCheck,
"goconst-check": GoconstCheck,
}
)
@ -187,7 +188,7 @@ func runAndStreamOutput(cmd string, args ...string) {
// Will check if the tool exists and if not install it from the provided import path
// If any errors occur, it will exit with a status code of 1.
func checkAndInstallGoTool(tool, importPath string) {
if err := exec.Command(tool).Run(); err != nil {
if err := exec.Command(tool).Run(); err != nil && strings.Contains(err.Error(), "executable file not found") {
fmt.Printf("%s not installed, installing %s...\n", tool, importPath)
if err := exec.Command("go", "install", Goflags[0], importPath).Run(); err != nil {
fmt.Printf("Error installing %s\n", tool)
@ -350,7 +351,11 @@ func GoSecCheck() {
runAndStreamOutput("gosec", "./...")
}
// Checks for repeated strings that could be replaced by a constant
func GoconstCheck() {
checkAndInstallGoTool("goconst", "github.com/jgautheron/goconst/cmd/goconst")
runAndStreamOutput("goconst", ApiPackages...)
}
}