8000 fix some linting failures and configure golangci-lint by dklimpel · Pull Request #922 · goss-org/goss · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix some linting failures and configure golangci-lint #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 6, 2024
Merged
3 changes: 1 addition & 2 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
only-new-issues: true
version: v1.59
16 changes: 16 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
linters:
# Disable all linters.
# Default: false
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
# default linter
# - errcheck # there are to many failures at the moment
- gosimple
- govet
- ineffassign
- staticcheck
- unused
# custom linter
- gofmt
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ htmlcov:
go test -v -coverpkg=./... -coverprofile=c.out ./...
go tool cover -html ./c.out


lint:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we change this to also run golangci-lint.

lint: golangci-lint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think golint does not exist anymore and golint can be replaced by golangci-lint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, didn't even notice that, yeah.. we can replace golint in the lint target with golangci-lint that makes more sense.

So much has changed in the go ecosystem since Goss was originally written.

$(info INFO: Starting build $@)
golint $(pkgs) || true
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59
golangci-lint run --timeout 5m $(pkgs) || true

vet:
$(info INFO: Starting build $@)
Expand Down
8 changes: 0 additions & 8 deletions cmd/goss/goss.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,6 @@ func addAlphaFlagIfNeeded(app *cli.App) {
}
}

const msgFormat string = `WARNING: goss for this platform (%q) is alpha-quality, work-in-progress and community-supported.

You should not expect everything to work. Treat linux as the canonical behaviour to expect.

Please see https://github.com/goss-org/goss/tree/master/docs/platform-feature-parity.md to set your expectations and see progress.
Please file issues via https://github.com/goss-org/goss/issues/new/choose
Pull requests and bug reports very welcome.`

func fatalAlphaIfNeeded(c *cli.Context) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
if c.GlobalString("use-alpha") != A3DB "1" {
Expand Down
8 changes: 0 additions & 8 deletions matchers/have_patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ func (m *HavePatternsMatcher) NegatedFailureResult(actual interface{}) MatcherRe
}
}

func appendMissingStrings(message string, missingElements []string) string {
if len(missingElements) == 0 {
return message
}
return fmt.Sprintf("%s\nthe missing elements were\n%s", message,
format.Object(missingElements, 1))
}

type patternMatcher interface {
Match(string) bool
Pattern() string
Expand Down
3 changes: 1 addition & 2 deletions matchers/type_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"

Expand Down Expand Up @@ -108,7 +107,7 @@ func (t ReaderToString) Transform(i interface{}) (interface{}, error) {
return nil, fmt.Errorf("Expected io.reader, Got:%s", format.Object(i, 1))
}

b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions outputs/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func (r Json) ValidOptions() []*formatOption {
func (r Json) Output(w io.Writer, results <-chan []resource.TestResult,
outConfig util.OutputConfig) (exitCode int) {

var pretty bool
pretty = util.IsValueInList(foPretty, outConfig.FormatOptions)
var pretty bool = util.IsValueInList(foPretty, outConfig.FormatOptions)
includeRaw := !util.IsValueInList(foExcludeRaw, outConfig.FormatOptions)

sort := util.IsValueInList(foSort, outConfig.FormatOptions)
Expand Down
3 changes: 1 addition & 2 deletions outputs/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func (r JUnit) Output(w io.Writer, results <-chan []resource.TestResult,
// ISO8601 timeformat
timestamp := time.Now().Format(time.RFC3339)

var summary map[int]string
summary = make(map[int]string)
var summary map[int]string = make(map[int]string)

var startTime time.Time
var endTime time.Time
Expand Down
3 changes: 1 addition & 2 deletions outputs/nagios.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func (r Nagios) Output(w io.Writer, results <-chan []resource.TestResult,

var startTime time.Time
var endTime time.Time
var summary map[int]string
summary = make(map[int]string)
var summary map[int]string = make(map[int]string)

for resultGroup := range results {
for _, testResult := range resultGroup {
Expand Down
6 changes: 3 additions & 3 deletions outputs/rspecish.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func (r Rspecish) Output(w io.Writer, results <-chan []resource.TestResult,
switch testResult.Result {
case resource.SUCCESS:
logTrace("TRACE", "SUCCESS", testResult, false)
fmt.Fprintf(w, green("."))
fmt.Fprint(w, green("."))
case resource.SKIP:
logTrace("TRACE", "SKIP", testResult, false)
fmt.Fprintf(w, yellow("S"))
fmt.Fprint(w, yellow("S"))
failedOrSkippedGroup = append(failedOrSkippedGroup, testResult)
skipped++
case resource.FAIL:
logTrace("TRACE", "FAIL", testResult, false)
fmt.Fprintf(w, red("F"))
fmt.Fprint(w, red("F"))
failedOrSkippedGroup = append(failedOrSkippedGroup, testResult)
failed++
}
Expand Down
3 changes: 1 addition & 2 deletions outputs/tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func (r Tap) Output(w io.Writer, results <-chan []resource.TestResult,
testCount := 0
failed := 0

var summary map[int]string
summary = make(map[int]string)
var summary map[int]string = make(map[int]string)

for resultGroup := range results {
for _, testResult := range resultGroup {
Expand Down
4 changes: 3 additions & 1 deletion resource/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Addr struct {
Skip bool `json:"skip,omitempty" yaml:"skip,omitempty"`
}

type idKey struct{}

const (
AddrResourceKey = "addr"
AddResourceName = "Addr"
Expand Down Expand Up @@ -51,7 +53,7 @@ func (a *Addr) GetAddress() string {
}

func (a *Addr) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", a.ID())
ctx := context.WithValue(context.Background(), idKey{}, a.ID())
Comment on lines -54 to +56
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was:

resource/addr.go:54:49: SA1029: should not use built-in type string as key for value; define your own type to avoid collisions (staticcheck)
	ctx := context.WithValue(context.Background(), "id", a.ID())

skip := a.Skip

if a.Timeout == 0 {
Expand Down
2 changes: 1 addition & 1 deletion resource/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *Command) GetExec() string {
}

func (c *Command) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", c.ID())
ctx := context.WithValue(context.Background(), idKey{}, c.ID())
skip := c.Skip

if c.Timeout == 0 {
Expand Down
2 changes: 1 addition & 1 deletion resource/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (d *DNS) GetResolve() string {
}

func (d *DNS) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", d.ID())
ctx := context.WithValue(context.Background(), idKey{}, d.ID())
skip := d.Skip
if d.Timeout == 0 {
d.Timeout = 500
Expand Down
2 changes: 1 addition & 1 deletion resource/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (f *File) GetPath() string {
}

func (f *File) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", f.ID())
ctx := context.WithValue(context.Background(), idKey{}, f.ID())
skip := f.Skip
sysFile := sys.NewFile(ctx, f.GetPath(), sys, util.Config{})

Expand Down
2 changes: 1 addition & 1 deletion resource/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (g *Group) GetGroupname() string {
}

func (g *Group) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", g.ID())
ctx := context.WithValue(context.Background(), idKey{}, g.ID())
skip := g.Skip
sysgroup := sys.NewGroup(ctx, g.GetGroupname(), sys, util.Config{})

Expand Down
2 changes: 1 addition & 1 deletion resource/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *HTTP) getURL() string {
}

func (u *HTTP) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", u.ID())
ctx := context.WithValue(context.Background(), idKey{}, u.ID())
skip := u.Skip
if u.Timeout == 0 {
u.Timeout = 5000
Expand Down
2 changes: 1 addition & 1 deletion resource/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (i *Interface) GetName() string {
}

func (i *Interface) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", i.ID())
ctx := context.WithValue(context.Background(), idKey{}, i.ID())
skip := i.Skip
sysInterface := sys.NewInterface(ctx, i.GetName(), sys, util.Config{})

Expand Down
2 changes: 1 addition & 1 deletion resource/kernel_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (k *KernelParam) GetName() string {
}

func (k *KernelParam) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", k.ID())
ctx := context.WithValue(context.Background(), idKey{}, k.ID())
skip := k.Skip
sysKernelParam := sys.NewKernelParam(ctx, k.GetName(), sys, util.Config{})

Expand Down
2 changes: 1 addition & 1 deletion resource/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (m *Mount) GetMountPoint() string {
}

func (m *Mount) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", m.ID())
ctx := context.WithValue(context.Background(), idKey{}, m.ID())
skip := m.Skip

if m.Timeout == 0 {
Expand Down
2 changes: 1 addition & 1 deletion resource/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *Package) GetName() string {
}

func (p *Package) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", p.ID())
ctx := context.WithValue(context.Background(), idKey{}, p.ID())
skip := p.Skip
sysPkg := sys.NewPackage(ctx, p.GetName(), sys, util.Config{})

Expand Down
2 changes: 1 addition & 1 deletion resource/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *Port) GetPort() string {
}

func (p *Port) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", p.ID())
ctx := context.WithValue(context.Background(), idKey{}, p.ID())
skip := p.Skip
sysPort := sys.NewPort(ctx, p.GetPort(), sys, util.Config{})

Expand Down
2 changes: 1 addition & 1 deletion resource/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (p *Process) GetComm() string {
}

func (p *Process) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", p.ID())
ctx := context.WithValue(context.Background(), idKey{}, p.ID())
skip := p.Skip
sysProcess := sys.NewProcess(ctx, p.GetComm(), sys, util.Config{})

Expand Down
14 changes: 0 additions & 14 deletions resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync"

"github.com/goss-org/goss/system"
"github.com/oleiade/reflections"
)

type Resource interface {
Expand Down Expand Up @@ -66,18 +64,6 @@ func deprecateAtoI(depr any, desc string) any {
return float64(i)
}

func validAttrs(i any, t string) (map[string]bool, error) {
validAttrs := make(map[string]bool)
tags, err := reflections.Tags(i, t)
if err != nil {
return nil, err
}
for _, v := range tags {
validAttrs[strings.Split(v, ",")[0]] = true
}
return validAttrs, nil
}

func shouldSkip(results []TestResult) bool {
if len(results) < 1 {
return false
Expand Down
Loading
0