Skip to content
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

fix some linting failures and configure golangci-lint #922

Merged
merged 14 commits into from
Jun 6, 2024
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
- gosimple
- govet
- ineffassign
- staticcheck
- unused
# custom linter
- gofmt
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ htmlcov:
go test -v -coverpkg=./... -coverprofile=c.out ./...
go tool cover -html ./c.out

.PHONY: golangci-lint
golangci-lint:
$(info INFO: Starting build $@)
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run --timeout 5m $(pkgs)

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 $@)
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") != "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
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
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
30 changes: 15 additions & 15 deletions resource/resource_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (r AddrMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Addr
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -140,7 +140,7 @@ func (r CommandMap) AppendSysResourceIfExists(sr string, sys *system.System) (*C
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -241,7 +241,7 @@ func (r DNSMap) AppendSysResourceIfExists(sr string, sys *system.System) (*DNS,
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -342,7 +342,7 @@ func (r FileMap) AppendSysResourceIfExists(sr string, sys *system.System) (*File
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -443,7 +443,7 @@ func (r GossfileMap) AppendSysResourceIfExists(sr string, sys *system.System) (*
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -544,7 +544,7 @@ func (r GroupMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Gro
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -645,7 +645,7 @@ func (r PackageMap) AppendSysResourceIfExists(sr string, sys *system.System) (*P
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -746,7 +746,7 @@ func (r PortMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Port
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -847,7 +847,7 @@ func (r ProcessMap) AppendSysResourceIfExists(sr string, sys *system.System) (*P
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -948,7 +948,7 @@ func (r ServiceMap) AppendSysResourceIfExists(sr string, sys *system.System) (*S
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -1049,7 +1049,7 @@ func (r UserMap) AppendSysResourceIfExists(sr string, sys *system.System) (*User
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -1150,7 +1150,7 @@ func (r KernelParamMap) AppendSysResourceIfExists(sr string, sys *system.System)
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -1251,7 +1251,7 @@ func (r MountMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Mou
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -1352,7 +1352,7 @@ func (r InterfaceMap) AppendSysResourceIfExists(sr string, sys *system.System) (
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down Expand Up @@ -1453,7 +1453,7 @@ func (r HTTPMap) AppendSysResourceIfExists(sr string, sys *system.System) (*HTTP
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down
2 changes: 1 addition & 1 deletion resource/resource_list_genny.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r ResourceTypeMap) AppendSysResourceIfExists(sr string, sys *system.System
if err != nil {
return nil, nil, false, err
}
if e, _ := sysres.Exists(); e != true {
if e, _ := sysres.Exists(); !e {
return res, sysres, false, nil
}
if old_res, ok := r[res.ID()]; ok {
Expand Down
4 changes: 0 additions & 4 deletions resource/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ func HumanOutcomes() map[int]string {
return humanOutcomes
}

const (
maxScanTokenSize = 10 * 1024 * 1024
)

type ValidateError string

func (g ValidateError) Error() string { return string(g) }
Expand Down
1 change: 0 additions & 1 deletion system/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const (
type DefFile struct {
path string
realPath string
fi os.FileInfo
loaded bool
err error
}
Expand Down
3 changes: 1 addition & 2 deletions system/kernel_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ type KernelParam interface {
}

type DefKernelParam struct {
key string
value string
key string
}

func NewDefKernelParam(_ context.Context, key string, system *System, config util.Config) KernelParam {
Expand Down
5 changes: 1 addition & 4 deletions system/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@ type Service interface {
}

func invalidService(s string) bool {
if strings.ContainsRune(s, '/') {
return true
}
return false
return strings.ContainsRune(s, '/')
}
12 changes: 9 additions & 3 deletions system/service_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (s *ServiceSystemd) Exists() (bool, error) {
return false, nil
}
cmd := util.NewCommand("systemctl", "-q", "list-unit-files", "--type=service")
cmd.Run()
if err := cmd.Run(); err != nil {
return false, err
}
if strings.Contains(cmd.Stdout.String(), fmt.Sprintf("%s.service", s.service)) {
return true, cmd.Err
}
Expand All @@ -54,7 +56,9 @@ func (s *ServiceSystemd) Enabled() (bool, error) {
return false, nil
}
cmd := util.NewCommand("systemctl", "-q", "is-enabled", s.service)
cmd.Run()
if err := cmd.Run(); err != nil {
return false, err
}
if cmd.Status == 0 {
return true, cmd.Err
}
Expand All @@ -73,7 +77,9 @@ func (s *ServiceSystemd) Running() (bool, error) {
return false, nil
}
cmd := util.NewCommand("systemctl", "-q", "is-active", s.service)
cmd.Run()
if err := cmd.Run(); err != nil {
return false, err
}
if cmd.Status == 0 {
return true, cmd.Err
}
Expand Down