From 9b24b5800350601be6f7c410a9ea144982c5bcfe Mon Sep 17 00:00:00 2001 From: chblodg Date: Thu, 20 Oct 2022 11:29:40 -0700 Subject: [PATCH] linter fixes (#24) * fixing version test * updating make file * adding additional linters and fixes Co-authored-by: christopher blodgett --- forgecli/forgeapi.go | 1 + forgecli/forgecli.go | 2 +- forgecli/helpers.go | 15 +++++++-------- go.mod | 5 ++--- go.sum | 11 +++++------ main.go | 1 + makefile | 19 ++++++++++++++++++- revive.toml | 30 ++++++++++++++++++++++++++++++ 8 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 revive.toml diff --git a/forgecli/forgeapi.go b/forgecli/forgeapi.go index 75fbbe0..f595d47 100644 --- a/forgecli/forgeapi.go +++ b/forgecli/forgeapi.go @@ -1,3 +1,4 @@ +// Package forgecli is main cli package forgecli // MinecraftGameID Default Minecraft Game ID for Forge diff --git a/forgecli/forgecli.go b/forgecli/forgecli.go index 0c5dea5..a7d8065 100644 --- a/forgecli/forgecli.go +++ b/forgecli/forgecli.go @@ -176,7 +176,7 @@ func (app *appEnv) GetModsDependencies() error { return nil } -func (app *appEnv) GetModsFromForge(modToGet JSONMod, releaseType ReleaseType) error { +func (app *appEnv) GetModsFromForge(modToGet JSONMod, _ ReleaseType) error { var resp ForgeMods pageIndex := 0 pageSize := 999 diff --git a/forgecli/helpers.go b/forgecli/helpers.go index f3102ce..f9c3c1f 100644 --- a/forgecli/helpers.go +++ b/forgecli/helpers.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -15,11 +14,11 @@ import ( "github.com/sirupsen/logrus" ) -type error interface { +type forgecliError interface { Error() string } -func check(e error) { +func check(e forgecliError) { if e != nil { logrus.Error(e.Error()) logrus.Error("Exiting...") @@ -97,7 +96,7 @@ func (app *appEnv) PrepareDestinationFolder() { app.EnsureDestination() } -func (app *appEnv) FetchForgeAPIJSON(url string, data interface{}) error { +func (app *appEnv) FetchForgeAPIJSON(url string, data interface{}) forgecliError { logrus.Debugf("Fetching: %s", url) req, err := http.NewRequest("GET", url, nil) check(err) @@ -111,7 +110,7 @@ func (app *appEnv) FetchForgeAPIJSON(url string, data interface{}) error { return json.NewDecoder(resp.Body).Decode(data) } -func (app *appEnv) FetchJSON(url string, data interface{}) error { +func (app *appEnv) FetchJSON(url string, data interface{}) forgecliError { logrus.Debugf("Fetching JSON: %s", url) resp, err := app.hc.Get(url) check(err) @@ -127,14 +126,14 @@ func (app *appEnv) LoadModsFromJSON() { jsonFile, err := os.Open(app.jsonFile) check(err) defer jsonFile.Close() - byteValue, _ := ioutil.ReadAll(jsonFile) + byteValue, _ := io.ReadAll(jsonFile) var result JSONMods json.Unmarshal([]byte(byteValue), &result) logrus.Debugf("Pulled from json file: %s", result) app.modsFromJSON = result } -func (app *appEnv) FetchAndSave(url, destPath string) error { +func (app *appEnv) FetchAndSave(url, destPath string) forgecliError { logrus.Infof("Downloading: %s", url) req, err := http.NewRequest("GET", url, nil) @@ -155,7 +154,7 @@ func (app *appEnv) FetchAndSave(url, destPath string) error { } func (app *appEnv) PrintDestinationFiles() { - files, err := ioutil.ReadDir(app.destination) + files, err := os.ReadDir(app.destination) if err != nil { log.Fatal(err) } diff --git a/go.mod b/go.mod index ab378cd..0515649 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,10 @@ go 1.17 require ( github.com/joho/godotenv v1.4.0 - github.com/sirupsen/logrus v1.8.1 + github.com/sirupsen/logrus v1.9.0 ) require ( - github.com/stretchr/testify v1.7.0 // indirect - golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect + golang.org/x/sys v0.1.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 0848de0..0a5b078 100644 --- a/go.sum +++ b/go.sum @@ -5,15 +5,14 @@ github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= diff --git a/main.go b/main.go index 2f43482..5d6efb1 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// Package main function only to call forgecli module package main import ( diff --git a/makefile b/makefile index a8b939a..768e83f 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,20 @@ -PHONY: test +.PHONY : upgrade +upgrade : + go get -u . + go mod download + go mod tidy + +.PHONY : build +build : + go build + +.PHONY : lint +lint : + golint ./... + gofmt -w -s . + revive -config revive.toml ./... + staticcheck ./... + +.PHONY: test test: go test ./... diff --git a/revive.toml b/revive.toml new file mode 100644 index 0000000..f9e2405 --- /dev/null +++ b/revive.toml @@ -0,0 +1,30 @@ +ignoreGeneratedHeader = false +severity = "warning" +confidence = 0.8 +errorCode = 0 +warningCode = 0 + +[rule.blank-imports] +[rule.context-as-argument] +[rule.context-keys-type] +[rule.dot-imports] +[rule.error-return] +[rule.error-strings] +[rule.error-naming] +[rule.exported] +[rule.if-return] +[rule.increment-decrement] +[rule.var-naming] +[rule.var-declaration] +[rule.package-comments] +[rule.range] +[rule.receiver-naming] +[rule.time-naming] +[rule.unexported-return] +[rule.indent-error-flow] +[rule.errorf] +[rule.empty-block] +[rule.superfluous-else] +[rule.unused-parameter] +[rule.unreachable-code] +[rule.redefines-builtin-id]