Make golangci-lint more strict (#150)

* Reformat some YAML files

* Make `golangci-lint` more strict
This commit is contained in:
Joshua Spence
2023-06-23 09:00:12 +10:00
committed by GitHub
parent 5f0ca38414
commit 206f4be940
13 changed files with 105 additions and 76 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"archive/tar"
"archive/zip"
"context"
"encoding/json"
"errors"
"fmt"
@@ -20,7 +21,12 @@ import (
)
func downloadJar(url *url.URL, outputDir string) (string, error) {
debResp, err := http.Get(url.String())
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url.String(), nil)
if err != nil {
return "", fmt.Errorf("unable to download deb: %w", err)
}
debResp, err := http.DefaultClient.Do(req)
if err != nil {
return "", fmt.Errorf("unable to download deb: %w", err)
}
@@ -147,7 +153,7 @@ func extractJSON(jarFile, fieldsDir string) error {
return fmt.Errorf("unable to marshal setting %q: %w", k, err)
}
err = os.WriteFile(filepath.Join(fieldsDir, fileName), data, 0755)
err = os.WriteFile(filepath.Join(fieldsDir, fileName), data, 0o755)
if err != nil {
return fmt.Errorf("unable to write new settings file: %w", err)
}

View File

@@ -247,7 +247,7 @@ func main() {
panic(err)
}
err = os.MkdirAll(fieldsDir, 0755)
err = os.MkdirAll(fieldsDir, 0o755)
if err != nil {
panic(err)
}
@@ -434,7 +434,7 @@ func main() {
}
_ = os.Remove(filepath.Join(outDir, goFile))
if err := os.WriteFile(filepath.Join(outDir, goFile), ([]byte)(code), 0644); err != nil {
if err := os.WriteFile(filepath.Join(outDir, goFile), ([]byte)(code), 0o644); err != nil {
panic(err)
}
}
@@ -453,7 +453,7 @@ const UnifiVersion = %q
panic(err)
}
if err := os.WriteFile(filepath.Join(outDir, "version.generated.go"), versionGo, 0644); err != nil {
if err := os.WriteFile(filepath.Join(outDir, "version.generated.go"), versionGo, 0o644); err != nil {
panic(err)
}
@@ -476,17 +476,18 @@ func (r *Resource) processFields(fields map[string]interface{}) {
}
}
func (r *Resource) fieldInfoFromValidation(name string, validation interface{}) (fieldInfo *FieldInfo, err error) {
func (r *Resource) fieldInfoFromValidation(name string, validation interface{}) (*FieldInfo, error) {
fieldName := strcase.ToCamel(name)
fieldName = cleanName(fieldName, fieldReps)
empty := &FieldInfo{}
var fieldInfo *FieldInfo
switch validation := validation.(type) {
case []interface{}:
if len(validation) == 0 {
fieldInfo = NewFieldInfo(fieldName, name, "string", "", false, true, "")
err = r.FieldProcessor(fieldName, fieldInfo)
err := r.FieldProcessor(fieldName, fieldInfo)
return fieldInfo, err
}
if len(validation) > 1 {
@@ -519,7 +520,7 @@ func (r *Resource) fieldInfoFromValidation(name string, validation interface{})
result.Fields[child.FieldName] = child
}
err = r.FieldProcessor(fieldName, result)
err := r.FieldProcessor(fieldName, result)
r.Types[typeName] = result
return result, err
@@ -535,7 +536,6 @@ func (r *Resource) fieldInfoFromValidation(name string, validation interface{})
return fieldInfo, r.FieldProcessor(fieldName, fieldInfo)
default:
if _, err := strconv.ParseFloat(normalized, 64); err == nil {
if normalized == "09" || normalized == "09.09" {
fieldValidation = ""
}

View File

@@ -2,8 +2,9 @@ package main
import (
"fmt"
assert "github.com/stretchr/testify/assert"
"testing"
assert "github.com/stretchr/testify/assert"
)
func TestFieldInfoFromValidation(t *testing.T) {
@@ -37,7 +38,7 @@ func TestFieldInfoFromValidation(t *testing.T) {
}
fieldInfo, err := resource.fieldInfoFromValidation("fieldName", c.validation)
//actualType, actualComment, actualOmitEmpty, err := fieldInfoFromValidation(c.validation)
// actualType, actualComment, actualOmitEmpty, err := fieldInfoFromValidation(c.validation)
if err != nil {
t.Fatal(err)
}

View File

@@ -1,6 +1,7 @@
package main
import (
"context"
"encoding/json"
"net/http"
"net/url"
@@ -19,7 +20,7 @@ func latestUnifiVersion() (*version.Version, *url.URL, error) {
query.Add("filter", firmwareUpdateApiFilter("product", unifiControllerProduct))
url.RawQuery = query.Encode()
req, err := http.NewRequest(http.MethodGet, url.String(), nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url.String(), nil)
if err != nil {
return nil, nil, err
}