Skip to content

Commit

Permalink
Merge pull request #31 from jaypipes/fix-lint
Browse files Browse the repository at this point in the history
clean up any linter failures
  • Loading branch information
jaypipes authored Jun 20, 2024
2 parents 0eff693 + b870af3 commit c4a51f5
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 52 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: harden runner
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
with:
egress-policy: block
disable-sudo: true
Expand All @@ -28,14 +28,14 @@ jobs:
objects.githubusercontent.com:443
proxy.golang.org:443
- name: checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: setup go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 1.21
- name: lint
uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 # v3.6.0
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
with:
version: v1.53
version: v1.59.1
args: --timeout=5m0s --verbose
only-new-issues: true
6 changes: 6 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
linters-settings:
staticcheck:
checks:
- all
- '-ST1000' # ignore at least one file in package should have comment
- '-EXC0003' # ignore the stuttered name error
3 changes: 1 addition & 2 deletions assertion/json/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ func JSONUnmarshalError(err error, node *yaml.Node) error {
"%w: %s at line %d, column %d",
ErrJSONUnmarshalError, err, node.Line, node.Column,
)
} else {
return fmt.Errorf("%w: %s", ErrJSONUnmarshalError, err)
}
return fmt.Errorf("%w: %s", ErrJSONUnmarshalError, err)
}

// JSONPathInvalid returns an ErrParse when a JSONPath expression could not be
Expand Down
14 changes: 7 additions & 7 deletions assertion/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error {
if err := valNode.Decode(&paths); err != nil {
return err
}
for path, _ := range paths {
for path := range paths {
if len(path) == 0 || path[0] != '$' {
return JSONPathInvalidNoRoot(path, valNode)
}
Expand All @@ -121,7 +121,7 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error {
if err := valNode.Decode(&pathFormats); err != nil {
return err
}
for pathFormat, _ := range pathFormats {
for pathFormat := range pathFormats {
if len(pathFormat) == 0 || pathFormat[0] != '$' {
return JSONPathInvalidNoRoot(pathFormat, valNode)
}
Expand Down Expand Up @@ -229,9 +229,9 @@ func (a *assertions) pathsOK() bool {
a.Fail(JSONPathNotFound(path, err))
return false
}
switch got.(type) {
switch got := got.(type) {
case string:
if expVal != got.(string) {
if expVal != got {
a.Fail(JSONPathNotEqual(path, expVal, got))
return false
}
Expand All @@ -241,7 +241,7 @@ func (a *assertions) pathsOK() bool {
a.Fail(JSONPathConversionError(path, expVal, got))
return false
}
if expValInt != got.(int) {
if expValInt != got {
a.Fail(JSONPathNotEqual(path, expVal, got))
return false
}
Expand All @@ -251,7 +251,7 @@ func (a *assertions) pathsOK() bool {
a.Fail(JSONPathConversionError(path, expVal, got))
return false
}
if expValFloat != got.(float64) {
if expValFloat != got {
a.Fail(JSONPathNotEqual(path, expVal, got))
return false
}
Expand All @@ -261,7 +261,7 @@ func (a *assertions) pathsOK() bool {
a.Fail(JSONPathConversionError(path, expVal, got))
return false
}
if expValBool != got.(bool) {
if expValBool != got {
a.Fail(JSONPathNotEqual(path, expVal, got))
return false
}
Expand Down
4 changes: 2 additions & 2 deletions assertion/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package json_test

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -92,7 +92,7 @@ paths:
}

func content() []byte {
b, _ := ioutil.ReadFile(filepath.Join("testdata", "books.json"))
b, _ := os.ReadFile(filepath.Join("testdata", "books.json"))
return b
}

Expand Down
2 changes: 2 additions & 0 deletions debug/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func Printf(
}
msg := fmt.Sprintf(format, args...)
for _, w := range writers {
//nolint:errcheck
w.Write([]byte(msg))
}
}
Expand All @@ -57,6 +58,7 @@ func Println(
}
msg := fmt.Sprintf(format, args...)
for _, w := range writers {
//nolint:errcheck
w.Write([]byte(msg))
}
}
2 changes: 1 addition & 1 deletion fixture/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestStarter(t *testing.T) {

assert.False(started)

f.Start(context.TODO())
_ = f.Start(context.TODO())

assert.True(started)
}
Expand Down
16 changes: 7 additions & 9 deletions fixture/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"strconv"

"github.com/PaesslerAG/jsonpath"
Expand Down Expand Up @@ -49,11 +48,11 @@ func (f *jsonFixture) State(path string) interface{} {
if err != nil {
return nil
}
switch got.(type) {
switch got := got.(type) {
case string:
return got.(string)
return got
case float64:
return strconv.FormatFloat(got.(float64), 'f', 0, 64)
return strconv.FormatFloat(got, 'f', 0, 64)
default:
return nil
}
Expand All @@ -64,17 +63,16 @@ func (f *jsonFixture) State(path string) interface{} {
func New(data interface{}) (gdttypes.Fixture, error) {
var err error
var b []byte
switch data.(type) {
switch data := data.(type) {
case io.Reader:
r := data.(io.Reader)
b, err = ioutil.ReadAll(r)
b, err = io.ReadAll(data)
if err != nil {
return nil, err
}
case []byte:
b = data.([]byte)
b = data
case string:
b = []byte(data.(string))
b = []byte(data)
}
f := jsonFixture{
data: interface{}(nil),
Expand Down
11 changes: 7 additions & 4 deletions plugin/exec/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func (a *Action) Do(

debug.Println(ctx, "exec: %s %s", target, args)

var cmd *exec.Cmd
cmd = exec.CommandContext(ctx, target, args...)
cmd := exec.CommandContext(ctx, target, args...)

outpipe, err := cmd.StdoutPipe()
if err != nil {
Expand All @@ -78,13 +77,17 @@ func (a *Action) Do(
return err
}
if outbuf != nil {
outbuf.ReadFrom(outpipe)
if _, err = outbuf.ReadFrom(outpipe); err != nil {
debug.Println(ctx, "exec: error reading from stdout: %s", err)
}
if outbuf.Len() > 0 {
debug.Println(ctx, "exec: stdout: %s", outbuf.String())
}
}
if errbuf != nil {
errbuf.ReadFrom(errpipe)
if _, err = errbuf.ReadFrom(errpipe); err != nil {
debug.Println(ctx, "exec: error reading from stderr: %s", err)
}
if errbuf.Len() > 0 {
debug.Println(ctx, "exec: stderr: %s", errbuf.String())
}
Expand Down
13 changes: 0 additions & 13 deletions plugin/exec/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"gopkg.in/yaml.v3"

"github.com/gdt-dev/gdt/errors"
gdttypes "github.com/gdt-dev/gdt/types"
)

type execDefaults struct{}
Expand Down Expand Up @@ -47,15 +46,3 @@ func (d *Defaults) UnmarshalYAML(node *yaml.Node) error {
}
return nil
}

// fromBaseDefaults returns an exec plugin-specific Defaults from a Spec
func fromBaseDefaults(base *gdttypes.Defaults) *Defaults {
if base == nil {
return nil
}
d := base.For(pluginName)
if d == nil {
return nil
}
return d.(*Defaults)
}
8 changes: 4 additions & 4 deletions plugin/exec/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"context"
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -196,7 +195,7 @@ func TestExecSleepTimeout(t *testing.T) {

// The test should have failed...
require.NotNil(err)
debugout := fmt.Sprintf("%s", outerr)
debugout := string(outerr)
require.Contains(debugout, "assertion failed: timeout exceeded")
}

Expand Down Expand Up @@ -273,6 +272,7 @@ func TestFailExecTimeoutCascade(t *testing.T) {

ctx := gdtcontext.New(gdtcontext.WithDebug())
err = s.Run(ctx, t)
require.Nil(err)
}

func TestExecTimeoutCascade(t *testing.T) {
Expand All @@ -288,7 +288,7 @@ func TestExecTimeoutCascade(t *testing.T) {
// The test should have failed...
require.NotNil(err)

debugout := fmt.Sprintf("%s", outerr)
debugout := string(outerr)
require.Contains(debugout, "using timeout of 500ms (expected: false) [scenario default]")
require.Contains(debugout, "using timeout of 20ms (expected: true)")
}
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestExecOnFail(t *testing.T) {
// The test should have failed...
require.NotNil(err)

debugout := fmt.Sprintf("%s", outerr)
debugout := string(outerr)
require.Contains(debugout, "assertion failed: not equal: expected dat but got cat")
require.Contains(debugout, "echo [bad kitty]")
}
3 changes: 1 addition & 2 deletions scenario/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package scenario

import (
"io"
"io/ioutil"

"gopkg.in/yaml.v3"

Expand All @@ -20,7 +19,7 @@ func FromReader(
r io.Reader,
mods ...ScenarioModifier,
) (*Scenario, error) {
contents, err := ioutil.ReadAll(r)
contents, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions scenario/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"context"
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
Expand All @@ -35,7 +34,8 @@ func TestRun(t *testing.T) {
require.Nil(err)
require.NotNil(s)

s.Run(context.TODO(), t)
err = s.Run(context.TODO(), t)
require.Nil(err)
}

func TestPriorRun(t *testing.T) {
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestRetryTestOverride(t *testing.T) {
// The test should have failed...
require.NotNil(err)

debugout := fmt.Sprintf("%s", outerr)
debugout := string(outerr)
require.Contains(debugout, "[gdt] [retry-test-override] run: exceeded max attempts 2. stopping.")
}

Expand Down
2 changes: 1 addition & 1 deletion suite/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func FromDir(

if err := filepath.Walk(
dirPath,
func(path string, info os.FileInfo, err error) error {
func(path string, info os.FileInfo, _ error) error {
if info.IsDir() {
return nil
}
Expand Down

0 comments on commit c4a51f5

Please sign in to comment.