diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2120d0c..67841df 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -9,13 +9,16 @@ on: jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ 1.17.x, 1.18.x, 1.19.x, 1.20.x ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: ${{ matrix.go-version }} - name: Test run: go test -v ./... @@ -24,27 +27,15 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v3 + with: + go-version: '1.20' + - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.29 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go. - # skip-go-installation: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true + version: v1.51.2 + skip-cache: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..69612d0 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,58 @@ +run: + timeout: 5m + modules-download-mode: readonly + + +output: + format: line-number + + # Print lines of code with issue. + # Default: true + print-issued-lines: false + + + # Make issues output unique by line. + # Default: true + uniq-by-line: false + + + +linters: + enable-all: true + disable: + - wrapcheck + - varnamelen + - thelper + - testpackage + - paralleltest + - gochecknoglobals + - forcetypeassert + - wsl + - dupl + - nonamedreturns + - nakedret + - lll + - godot + - gomnd + - godox # temporary + - errorlint + - typecheck + - forbidigo + + # deprecated + - interfacer + - varcheck + - nosnakecase + - deadcode + - scopelint + - structcheck + - golint + - ifshort + - exhaustivestruct + - maligned + +issues: + exclude-rules: + - path: _test\.go + linters: + - funlen diff --git a/adjust_test.go b/adjust_test.go index 3cf4cee..5eae017 100644 --- a/adjust_test.go +++ b/adjust_test.go @@ -9,8 +9,8 @@ import ( ) func TestClient_SetAdjust(t *testing.T) { - var testAction = AdjustActionIncrease - var testProp = AdjustPropBright + testAction := AdjustActionIncrease + testProp := AdjustPropBright tests := map[string]struct { tr transportFn @@ -38,8 +38,8 @@ func TestClient_SetAdjust(t *testing.T) { } func TestClient_SetBackgroundAdjust(t *testing.T) { - var testAction = AdjustActionIncrease - var testProp = AdjustPropBright + testAction := AdjustActionIncrease + testProp := AdjustPropBright tests := map[string]struct { tr transportFn diff --git a/client_test.go b/client_test.go index 07ed0a6..e430d44 100644 --- a/client_test.go +++ b/client_test.go @@ -2,9 +2,10 @@ package yeelight import ( "context" - "github.com/stretchr/testify/assert" "reflect" "testing" + + "github.com/stretchr/testify/assert" ) func TestNew(t *testing.T) { diff --git a/cron_test.go b/cron_test.go index c3a7773..3c6ff97 100644 --- a/cron_test.go +++ b/cron_test.go @@ -43,6 +43,7 @@ func TestClient_AddCron(t *testing.T) { }) } } + func TestClient_GetCron(t *testing.T) { tests := map[string]struct { on bool diff --git a/discovery.go b/discovery.go index 87d110b..4c86b36 100644 --- a/discovery.go +++ b/discovery.go @@ -98,7 +98,7 @@ func readReadDiscoveryPayload(in string) (DiscoveryResultItem, error) { const crlf = "\r\n" if strings.HasSuffix(in, crlf) { - in = in + crlf + in += crlf } resp, err := http.ReadResponse(bufio.NewReader(strings.NewReader(in)), nil) diff --git a/errors_test.go b/errors_test.go index 30f1851..103c9af 100644 --- a/errors_test.go +++ b/errors_test.go @@ -8,5 +8,4 @@ import ( func TestUnknownError_Error(t *testing.T) { assert.Equal(t, "im_test_error", UnknownError("im_test_error").Error()) - } diff --git a/example/main.go b/example/main.go index 6f7abb2..b5ebc79 100644 --- a/example/main.go +++ b/example/main.go @@ -10,6 +10,7 @@ import ( "github.com/oherych/yeelight" ) +//nolint:gocritic func main() { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() diff --git a/flow_test.go b/flow_test.go index f579b79..6c24294 100644 --- a/flow_test.go +++ b/flow_test.go @@ -9,9 +9,9 @@ import ( ) func TestClient_StartColorFlow(t *testing.T) { - var testCount = 12 - var testAction = FlowActionTurnOff - var testExpressions = []FlowExpression{ + testCount := 12 + testAction := FlowActionTurnOff + testExpressions := []FlowExpression{ { Duration: time.Minute, Mode: FlowModeColor, @@ -59,9 +59,9 @@ func TestClient_StartColorFlow(t *testing.T) { } func TestClient_StartBackgroundColorFlow(t *testing.T) { - var testCount = 12 - var testAction = FlowActionTurnOff - var testExpressions = []FlowExpression{ + testCount := 12 + testAction := FlowActionTurnOff + testExpressions := []FlowExpression{ { Duration: time.Minute, Mode: FlowModeColor, diff --git a/listen.go b/listen.go deleted file mode 100644 index 60166bb..0000000 --- a/listen.go +++ /dev/null @@ -1,7 +0,0 @@ -package yeelight - -import "context" - -func (c Client) Listen(ctx context.Context) (<-chan string, error) { - return nil, nil -} diff --git a/raw.go b/raw.go index 80ef0b5..8477425 100644 --- a/raw.go +++ b/raw.go @@ -93,7 +93,7 @@ func defaultTransport(ctx context.Context, host string, raw string) ([]byte, err res, err := bufio.NewReader(conn).ReadBytes('\n') if err != nil { - return nil, fmt.Errorf("cannot read command result %s", err) + return nil, fmt.Errorf("cannot read command result %w", err) } return res, nil