This repository has been archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate staticcheck as an extra command Fixes #91
- Loading branch information
1 parent
1343c5a
commit 4f2ffd1
Showing
12 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package staticcheck | ||
|
||
import ( | ||
"github.com/pieterclaerhout/go-james/internal" | ||
"github.com/pieterclaerhout/go-james/internal/staticchecker" | ||
"github.com/tucnak/climax" | ||
) | ||
|
||
// StaticcheckCmd defines the build command | ||
var StaticcheckCmd = climax.Command{ | ||
Name: "staticcheck", | ||
Brief: "Perform a static analysis of the code using staticcheck", | ||
Help: "Perform a static analysis of the code using staticcheck", | ||
Flags: []climax.Flag{}, | ||
Handle: func(ctx climax.Context) int { | ||
|
||
tool := staticchecker.StaticChecker{} | ||
|
||
executor := internal.NewExecutor("") | ||
return executor.RunTool(tool, true) | ||
|
||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,8 @@ | |
}, | ||
"test": { | ||
"extra_args": [] | ||
}, | ||
"staticcheck": { | ||
"checks": ["all", "-ST1005", "-ST1000"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package staticchecker | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/kballard/go-shellquote" | ||
"github.com/pieterclaerhout/go-james/internal/common" | ||
"github.com/pieterclaerhout/go-james/internal/config" | ||
) | ||
|
||
const staticcheckPackagePath = "honnef.co/go/tools/cmd/staticcheck" | ||
|
||
// StaticChecker implements the "staticcheck" command | ||
type StaticChecker struct { | ||
common.CommandRunner | ||
common.FileSystem | ||
common.Golang | ||
} | ||
|
||
// Execute executes the command | ||
func (staticChecker StaticChecker) Execute(project common.Project, cfg config.Config) error { | ||
|
||
staticcheckCmdPath := staticChecker.GoBin("staticcheck") | ||
|
||
if !staticChecker.FileExists(staticcheckCmdPath) { | ||
staticChecker.LogPathCreation("Installing:", staticcheckCmdPath) | ||
} | ||
|
||
env := map[string]string{} | ||
installCmd := []string{"go", "get", "-u", staticcheckPackagePath} | ||
if output, err := staticChecker.RunReturnOutput(installCmd, project.Path, env); err != nil { | ||
staticChecker.LogError(output) | ||
return err | ||
} | ||
|
||
staticcheckCmd := []string{staticcheckCmdPath} | ||
if len(cfg.Staticcheck.Checks) > 0 { | ||
staticcheckCmd = append(staticcheckCmd, "-checks") | ||
staticcheckCmd = append(staticcheckCmd, strings.Join(cfg.Staticcheck.Checks, ",")) | ||
} | ||
staticcheckCmd = append(staticcheckCmd, "./...") | ||
|
||
staticChecker.LogInfo("> Running:", shellquote.Join(staticcheckCmd...)) | ||
|
||
err := staticChecker.RunToStdout(staticcheckCmd, project.Path, map[string]string{}) | ||
if err != nil && err.Error() != "exit status 1" { | ||
return err | ||
} | ||
|
||
return nil | ||
|
||
} | ||
|
||
// RequiresBuild indicates if a build is required before running the command | ||
func (staticChecker StaticChecker) RequiresBuild() bool { | ||
return false | ||
} |