Make golangci-lint more strict (#150)
* Reformat some YAML files * Make `golangci-lint` more strict
This commit is contained in:
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
@@ -1,11 +1,11 @@
|
|||||||
---
|
---
|
||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: "gomod"
|
- package-ecosystem: 'github-actions'
|
||||||
directory: "/"
|
directory: '/'
|
||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: 'daily'
|
||||||
- package-ecosystem: "github-actions"
|
- package-ecosystem: 'gomod'
|
||||||
directory: "/"
|
directory: '/'
|
||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: 'daily'
|
||||||
|
|||||||
48
.github/workflows/ci.yaml
vendored
48
.github/workflows/ci.yaml
vendored
@@ -3,47 +3,47 @@ on:
|
|||||||
pull_request: {}
|
pull_request: {}
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "main"
|
- 'main'
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- 'v*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: "ubuntu-latest"
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: "actions/checkout@v3.3.0"
|
- uses: 'actions/checkout@v3.3.0'
|
||||||
- uses: "actions/setup-go@v4"
|
- uses: 'actions/setup-go@v4'
|
||||||
- run: "go build ./..."
|
- run: 'go build ./...'
|
||||||
|
|
||||||
generate:
|
generate:
|
||||||
needs: "build"
|
needs: 'build'
|
||||||
runs-on: "ubuntu-latest"
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: "actions/checkout@v3.3.0"
|
- uses: 'actions/checkout@v3.3.0'
|
||||||
- uses: "actions/setup-go@v4"
|
- uses: 'actions/setup-go@v4'
|
||||||
|
|
||||||
- run: "go generate unifi/device.go"
|
- run: 'go generate unifi/device.go'
|
||||||
- run: "git diff --compact-summary --exit-code"
|
- run: 'git diff --compact-summary --exit-code'
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
runs-on: "ubuntu-latest"
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: "actions/checkout@v3.3.0"
|
- uses: 'actions/checkout@v3.3.0'
|
||||||
- uses: "actions/setup-go@v4"
|
- uses: 'actions/setup-go@v4'
|
||||||
- uses: "golangci/golangci-lint-action@v3"
|
- uses: 'golangci/golangci-lint-action@v3'
|
||||||
with:
|
with:
|
||||||
skip-pkg-cache: true
|
skip-pkg-cache: true
|
||||||
|
|
||||||
test:
|
test:
|
||||||
needs: "build"
|
needs: 'build'
|
||||||
runs-on: "ubuntu-latest"
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: "actions/checkout@v3.3.0"
|
- uses: 'actions/checkout@v3.3.0'
|
||||||
- uses: "actions/setup-go@v4"
|
- uses: 'actions/setup-go@v4'
|
||||||
- run: "go test ./..."
|
- run: 'go test ./...'
|
||||||
|
|
||||||
yamllint:
|
yamllint:
|
||||||
runs-on: "ubuntu-latest"
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: "actions/checkout@v3.3.0"
|
- uses: 'actions/checkout@v3.3.0'
|
||||||
- uses: "ibiqlik/action-yamllint@v3"
|
- uses: 'ibiqlik/action-yamllint@v3'
|
||||||
|
|||||||
14
.github/workflows/generate.yaml
vendored
14
.github/workflows/generate.yaml
vendored
@@ -1,19 +1,19 @@
|
|||||||
---
|
---
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 0 * * *"
|
- cron: '0 0 * * *'
|
||||||
workflow_dispatch: {}
|
workflow_dispatch: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
fields:
|
fields:
|
||||||
runs-on: "ubuntu-latest"
|
runs-on: 'ubuntu-latest'
|
||||||
steps:
|
steps:
|
||||||
- uses: "actions/checkout@v3.3.0"
|
- uses: 'actions/checkout@v3.3.0'
|
||||||
- uses: "actions/setup-go@v4"
|
- uses: 'actions/setup-go@v4'
|
||||||
|
|
||||||
# TODO: Automatically merge the PR if tests pass.
|
# TODO: Automatically merge the PR if tests pass.
|
||||||
- run: "go generate unifi/fields.go"
|
- run: 'go generate unifi/fields.go'
|
||||||
- uses: "peter-evans/create-pull-request@v5"
|
- uses: 'peter-evans/create-pull-request@v5'
|
||||||
with:
|
with:
|
||||||
delete-branch: true
|
delete-branch: true
|
||||||
title: "Update to latest controller version"
|
title: 'Update to latest controller version'
|
||||||
|
|||||||
@@ -1,21 +1,44 @@
|
|||||||
---
|
---
|
||||||
linters:
|
linters:
|
||||||
disable-all: true
|
enable-all: true
|
||||||
enable:
|
disable:
|
||||||
- "deadcode"
|
- 'depguard'
|
||||||
- "errcheck"
|
- 'tagliatelle'
|
||||||
- "errorlint"
|
|
||||||
- "gofmt"
|
# Temporary
|
||||||
- "gosimple"
|
- 'cyclop'
|
||||||
- "govet"
|
- 'dupl'
|
||||||
- "ineffassign"
|
- 'exhaustruct'
|
||||||
- "makezero"
|
- 'forbidigo'
|
||||||
- "misspell"
|
- 'funlen'
|
||||||
- "nakedret"
|
- 'gochecknoglobals'
|
||||||
- "nilerr"
|
- 'gocognit'
|
||||||
- "staticcheck"
|
- 'goconst'
|
||||||
- "structcheck"
|
- 'gocritic'
|
||||||
- "unconvert"
|
- 'gocyclo'
|
||||||
- "unparam"
|
- 'godox'
|
||||||
- "unused"
|
- 'goerr113'
|
||||||
- "varcheck"
|
- 'gomnd'
|
||||||
|
- 'gosec'
|
||||||
|
- 'lll'
|
||||||
|
- 'maintidx'
|
||||||
|
- 'nestif'
|
||||||
|
- 'nlreturn'
|
||||||
|
- 'paralleltest'
|
||||||
|
- 'revive'
|
||||||
|
- 'stylecheck'
|
||||||
|
- 'varnamelen'
|
||||||
|
- 'wrapcheck'
|
||||||
|
- 'wsl'
|
||||||
|
|
||||||
|
# Deprecated
|
||||||
|
- 'deadcode'
|
||||||
|
- 'exhaustivestruct'
|
||||||
|
- 'golint'
|
||||||
|
- 'ifshort'
|
||||||
|
- 'interfacer'
|
||||||
|
- 'maligned'
|
||||||
|
- 'nosnakecase'
|
||||||
|
- 'scopelint'
|
||||||
|
- 'structcheck'
|
||||||
|
- 'varcheck'
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -20,7 +21,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func downloadJar(url *url.URL, outputDir string) (string, error) {
|
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 {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to download deb: %w", err)
|
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)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to write new settings file: %w", err)
|
return fmt.Errorf("unable to write new settings file: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(fieldsDir, 0755)
|
err = os.MkdirAll(fieldsDir, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -434,7 +434,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ = os.Remove(filepath.Join(outDir, goFile))
|
_ = 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)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -453,7 +453,7 @@ const UnifiVersion = %q
|
|||||||
panic(err)
|
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)
|
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 := strcase.ToCamel(name)
|
||||||
fieldName = cleanName(fieldName, fieldReps)
|
fieldName = cleanName(fieldName, fieldReps)
|
||||||
|
|
||||||
empty := &FieldInfo{}
|
empty := &FieldInfo{}
|
||||||
|
var fieldInfo *FieldInfo
|
||||||
|
|
||||||
switch validation := validation.(type) {
|
switch validation := validation.(type) {
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
if len(validation) == 0 {
|
if len(validation) == 0 {
|
||||||
fieldInfo = NewFieldInfo(fieldName, name, "string", "", false, true, "")
|
fieldInfo = NewFieldInfo(fieldName, name, "string", "", false, true, "")
|
||||||
err = r.FieldProcessor(fieldName, fieldInfo)
|
err := r.FieldProcessor(fieldName, fieldInfo)
|
||||||
return fieldInfo, err
|
return fieldInfo, err
|
||||||
}
|
}
|
||||||
if len(validation) > 1 {
|
if len(validation) > 1 {
|
||||||
@@ -519,7 +520,7 @@ func (r *Resource) fieldInfoFromValidation(name string, validation interface{})
|
|||||||
result.Fields[child.FieldName] = child
|
result.Fields[child.FieldName] = child
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.FieldProcessor(fieldName, result)
|
err := r.FieldProcessor(fieldName, result)
|
||||||
r.Types[typeName] = result
|
r.Types[typeName] = result
|
||||||
return result, err
|
return result, err
|
||||||
|
|
||||||
@@ -535,7 +536,6 @@ func (r *Resource) fieldInfoFromValidation(name string, validation interface{})
|
|||||||
return fieldInfo, r.FieldProcessor(fieldName, fieldInfo)
|
return fieldInfo, r.FieldProcessor(fieldName, fieldInfo)
|
||||||
default:
|
default:
|
||||||
if _, err := strconv.ParseFloat(normalized, 64); err == nil {
|
if _, err := strconv.ParseFloat(normalized, 64); err == nil {
|
||||||
|
|
||||||
if normalized == "09" || normalized == "09.09" {
|
if normalized == "09" || normalized == "09.09" {
|
||||||
fieldValidation = ""
|
fieldValidation = ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
assert "github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
assert "github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFieldInfoFromValidation(t *testing.T) {
|
func TestFieldInfoFromValidation(t *testing.T) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -19,7 +20,7 @@ func latestUnifiVersion() (*version.Version, *url.URL, error) {
|
|||||||
query.Add("filter", firmwareUpdateApiFilter("product", unifiControllerProduct))
|
query.Add("filter", firmwareUpdateApiFilter("product", unifiControllerProduct))
|
||||||
url.RawQuery = query.Encode()
|
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 {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// just to fix compile issues with the import
|
// just to fix compile issues with the import.
|
||||||
var (
|
var (
|
||||||
_ fmt.Formatter
|
_ fmt.Formatter
|
||||||
_ context.Context
|
_ context.Context
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ func (c *Client) UpdateDevice(ctx context.Context, site string, d *Device) (*Dev
|
|||||||
|
|
||||||
func (c *Client) GetDevice(ctx context.Context, site, id string) (*Device, error) {
|
func (c *Client) GetDevice(ctx context.Context, site, id string) (*Device, error) {
|
||||||
devices, err := c.ListDevice(ctx, site)
|
devices, err := c.ListDevice(ctx, site)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ func (c *Client) ListSites(ctx context.Context) ([]Site, error) {
|
|||||||
|
|
||||||
func (c *Client) GetSite(ctx context.Context, id string) (*Site, error) {
|
func (c *Client) GetSite(ctx context.Context, id string) (*Site, error) {
|
||||||
sites, err := c.ListSites(ctx)
|
sites, err := c.ListSites(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func (c *Client) setAPIUrlStyle(ctx context.Context) error {
|
|||||||
// see https://github.com/unifi-poller/unifi/blob/4dc44f11f61a2e08bf7ec5b20c71d5bced837b5d/unifi.go#L101-L104
|
// see https://github.com/unifi-poller/unifi/blob/4dc44f11f61a2e08bf7ec5b20c71d5bced837b5d/unifi.go#L101-L104
|
||||||
// and https://github.com/unifi-poller/unifi/commit/43a6b225031a28f2b358f52d03a7217c7b524143
|
// and https://github.com/unifi-poller/unifi/commit/43a6b225031a28f2b358f52d03a7217c7b524143
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", c.baseURL.String(), nil)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -243,7 +243,7 @@ func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody int
|
|||||||
c.csrf = resp.Header.Get("x-csrf-token")
|
c.csrf = resp.Header.Get("x-csrf-token")
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != http.StatusOK {
|
||||||
errBody := struct {
|
errBody := struct {
|
||||||
Meta meta `json:"meta"`
|
Meta meta `json:"meta"`
|
||||||
Data []struct {
|
Data []struct {
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ func (c *Client) CreateUser(ctx context.Context, site string, d *User) (*User, e
|
|||||||
return nil, &NotFoundError{}
|
return nil, &NotFoundError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
new := respBody.Data[0].Data[0]
|
user := respBody.Data[0].Data[0]
|
||||||
|
|
||||||
return &new, nil
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]interface{}) ([]User, error) {
|
func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]interface{}) ([]User, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user