Skip to content

Commit

Permalink
linter fixes (#24)
Browse files Browse the repository at this point in the history
* fixing version test

* updating make file

* adding additional linters and fixes

Co-authored-by: christopher blodgett <christopher.blodgett@gmail.com>
  • Loading branch information
shotah and christopher blodgett authored Oct 20, 2022
1 parent d0102c7 commit 9b24b58
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 19 deletions.
1 change: 1 addition & 0 deletions forgecli/forgeapi.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package forgecli is main cli
package forgecli

// MinecraftGameID Default Minecraft Game ID for Forge
Expand Down
2 changes: 1 addition & 1 deletion forgecli/forgecli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions forgecli/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand All @@ -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...")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
11 changes: 5 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main function only to call forgecli module
package main

import (
Expand Down
19 changes: 18 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -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 ./...
30 changes: 30 additions & 0 deletions revive.toml
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 9b24b58

Please sign in to comment.