Add mage target to automagically fix issues found by golangci

This commit is contained in:
kolaente 2020-10-11 18:34:57 +02:00
parent 267ac3234a
commit 56a6d6b511
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 10 additions and 1 deletions

View File

@ -434,16 +434,25 @@ func (Check) Goconst() {
runAndStreamOutput("goconst", ApiPackages...)
}
func (Check) Golangci() {
func checkGolangCiLintInstalled() {
mg.Deps(initVars)
if err := exec.Command("golangci-lint").Run(); err != nil && strings.Contains(err.Error(), "executable file not found") {
fmt.Println("Please manually install golangci-lint by running")
fmt.Println("curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0")
os.Exit(1)
}
}
func (Check) Golangci() {
checkGolangCiLintInstalled()
runAndStreamOutput("golangci-lint", "run")
}
func (Check) GolangciFix() {
checkGolangCiLintInstalled()
runAndStreamOutput("golangci-lint", "run", "--fix")
}
// Runs fmt-check, lint, got-swag, misspell-check, ineffasign-check, gocyclo-check, static-check, gosec-check, goconst-check all in parallel
func (Check) All() {
mg.Deps(initVars)