Skip to content

Commit

Permalink
chore: update lint to 1.56.2 and fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Apr 26, 2024
1 parent 9b944ef commit 443a365
Show file tree
Hide file tree
Showing 36 changed files with 373 additions and 331 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ linters:
- nakedret
- prealloc
- predeclared
- revive
# - revive // over-bearing for generated code, too many instances
- staticcheck
# - structcheck
- stylecheck
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"acceptables",
"argh",
"avfs",
"beezledub",
Expand Down
9 changes: 8 additions & 1 deletion generators/gola/content-parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ func readEntries(vfs storage.VirtualFS, directoryPath string) ([]fs.DirEntry, er

autoPattern := "*auto*.go"
testPattern := "*auto*_test.go"
entries = lo.Filter(entries, func(item fs.DirEntry, index int) bool {
entries = lo.Filter(entries, func(item fs.DirEntry, _ int) bool {
auto, _ := filepath.Match(autoPattern, item.Name())
test, _ := filepath.Match(testPattern, item.Name())

return !item.IsDir() && auto && !test
})

Expand Down Expand Up @@ -98,11 +99,14 @@ func parseContents(contents CodeContent) (*SignatureResult, error) {
index := strings.LastIndex(line, " {")
if index >= 0 {
signature := line[0 : index+1]

hashBuilder.WriteString(fmt.Sprintf("%v\n", strings.TrimSpace(signature)))

metrics[name].Func++
}
} else if strings.HasPrefix(line, "type") {
hashBuilder.WriteString(fmt.Sprintf("%v\n", strings.TrimSpace(line)))

metrics[name].Type++
}
}
Expand All @@ -113,6 +117,7 @@ func parseContents(contents CodeContent) (*SignatureResult, error) {

sha256hash := hash(hashBuilder.String())
outputBuilder := strings.Builder{}

outputBuilder.WriteString(fmt.Sprintf("===> [🤖] THIS-HASH: '%v'\n", sha256hash))
outputBuilder.WriteString(fmt.Sprintf("===> [👾] REGISTERED-HASH: '%v'\n", RegisteredHash))

Expand Down Expand Up @@ -141,6 +146,7 @@ func parseContents(contents CodeContent) (*SignatureResult, error) {
"✔️ Hashes are equal",
"💥 Api changes detected",
)

outputBuilder.WriteString(fmt.Sprintf(">>>> Status: %v\n", status))

return &SignatureResult{
Expand All @@ -154,6 +160,7 @@ func parseContents(contents CodeContent) (*SignatureResult, error) {

func hash(content string) string {
hasher := sha256.New()

hasher.Write([]byte(content))

return hex.EncodeToString(hasher.Sum(nil))
Expand Down
4 changes: 2 additions & 2 deletions generators/gola/gola_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package gola_test
import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
)

func TestGola(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion generators/gola/gomega-matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/generators/gola/internal/storage"

. "github.com/onsi/gomega/types"
. "github.com/onsi/gomega/types" //nolint:revive // gomega ok
)

type (
Expand Down
3 changes: 1 addition & 2 deletions generators/gola/hyper-gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"path/filepath"
"strings"

. "github.com/onsi/ginkgo/v2"
// . "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
)

type typeSpec struct {
Expand Down
4 changes: 2 additions & 2 deletions generators/gola/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gpmega ok
"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/generators/gola/internal/storage"
)
Expand Down
4 changes: 2 additions & 2 deletions generators/gola/source-code-data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"runtime"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok

"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/generators/gola/internal/storage"
Expand Down
4 changes: 2 additions & 2 deletions generators/gola/source-code-generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package gola_test
import (
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok

"github.com/snivilised/cobrass/generators/gola"
"github.com/snivilised/cobrass/generators/gola/internal/storage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
"github.com/spf13/cobra"

"github.com/snivilised/cobrass/src/assistant"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
"github.com/spf13/cobra"

"github.com/snivilised/cobrass/src/assistant"
Expand Down
3 changes: 3 additions & 0 deletions generators/ps/generate-option-validators.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1249,11 +1249,13 @@ Entry(nil, OvEntry{
},
Validator: func() assistant.OptionValidator {
$($spec.Assign)
return paramSet.BindValidated$($spec.TypeName)(
assistant.NewFlagInfo("$($lowerFlagName)", "$($spec.Short)", $default),
$bindTo,
func(value $($spec.GoType), flag *pflag.Flag) error {
$($assert)
return nil
},
)
Expand Down Expand Up @@ -1282,6 +1284,7 @@ Entry(nil, OvEntry{
&paramSet.Native.$($spec.SliceFlagName),
func(value $($sliceType), flag *pflag.Flag) error {
Expect(value).To($($spec.Equate)($($spec.ExpectSlice)))
return nil
},
)
Expand Down
4 changes: 2 additions & 2 deletions src/assistant/assistant_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package assistant_test
import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
)

func TestAssistant(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions src/assistant/cobra-container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package assistant_test
import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
"github.com/spf13/cobra"

"github.com/snivilised/cobrass/src/assistant"
Expand Down
4 changes: 2 additions & 2 deletions src/assistant/configuration/configuration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package configuration_test
import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
)

func TestConfiguration(t *testing.T) {
Expand Down
16 changes: 8 additions & 8 deletions src/assistant/configuration/global-config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path/filepath"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
"github.com/spf13/viper"
"go.uber.org/mock/gomock"

Expand Down Expand Up @@ -243,7 +243,7 @@ var _ = Describe("GlobalConfig", Ordered, func() {
mock.EXPECT().ConfigFileUsed().Return(e.expected)
},
expected: "cobrass.yml",
actual: func(e *configTE) any {
actual: func(_ *configTE) any {
full := config.ConfigFileUsed()
_ = mock.ConfigFileUsed()

Expand Down Expand Up @@ -419,7 +419,7 @@ var _ = Describe("GlobalConfig", Ordered, func() {

return config.GetTime(e.field)
},
assert: func(entry *configTE, actual any) {
assert: func(_ *configTE, _ any) {
// how does the time work in config?
//
},
Expand All @@ -437,7 +437,7 @@ var _ = Describe("GlobalConfig", Ordered, func() {

return config.GetSizeInBytes(e.field)
},
assert: func(entry *configTE, actual any) {
assert: func(_ *configTE, _ any) {
// how does the GetSizeInBytes work in config?
//
},
Expand Down Expand Up @@ -473,7 +473,7 @@ var _ = Describe("GlobalConfig", Ordered, func() {

return config.GetStringMap(e.field)
},
assert: func(entry *configTE, actual any) {
assert: func(_ *configTE, _ any) {
// how does the GetSizeInBytes work in config?
//
},
Expand Down Expand Up @@ -521,7 +521,7 @@ var _ = Describe("GlobalConfig", Ordered, func() {

return config.Sub(e.field)
},
assert: func(entry *configTE, actual any) {
assert: func(_ *configTE, _ any) {
//
},
}),
Expand All @@ -541,7 +541,7 @@ var _ = Describe("GlobalConfig", Ordered, func() {

return config.UnmarshalKey(e.field, &positions)
},
assert: func(entry *configTE, actual any) {
assert: func(_ *configTE, _ any) {
//
},
}),
Expand Down
10 changes: 7 additions & 3 deletions src/assistant/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (info *EnumInfo[E]) IsValidOrEmpty(value string) bool {
func (info *EnumInfo[E]) String() string {
keys := lo.Keys(info.reverseLookup)

return lo.Reduce(keys, func(agg string, current string, index int) string {
return lo.Reduce(keys, func(agg string, current string, _ int) string {
return fmt.Sprintf("%v%v(%v), ", agg, current, info.En(current))
}, "")
}
Expand All @@ -181,7 +181,7 @@ func (info *EnumInfo[E]) Acceptable() string {
keys := lo.Keys(info.reverseLookup)
sort.Strings(keys)

return "//" + lo.Reduce(keys, func(agg, current string, _ int) string {
return slashes + lo.Reduce(keys, func(agg, current string, _ int) string {
return fmt.Sprintf("%v%v/", agg, current)
}, "") + "/"
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func (info *EnumInfo[E]) AcceptablePrimes() string {
elements[i] = info.acceptables[v][0]
}

return "//" + strings.Join(elements, "/") + "//"
return slashes + strings.Join(elements, "/") + slashes
}

// NameOf returns the first acceptable name for the enum value specified.
Expand Down Expand Up @@ -311,3 +311,7 @@ func (es *EnumSlice[E]) AllAreValidOrEmpty() bool {
return es.Info.IsValidOrEmpty(v)
})
}

const (
slashes = "//"
)
20 changes: 10 additions & 10 deletions src/assistant/enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"slices"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
"github.com/samber/lo"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -143,14 +143,14 @@ var _ = Describe("Enum", func() {

Context("EnumSlice", func() {
DescribeTable("Values",
func(given, should string, source []string, expect []OutputFormatEnum) {
func(_, _ string, source []string, expect []OutputFormatEnum) {
outputFormatEnumSlice.Source = source

Expect(reflect.DeepEqual(
outputFormatEnumSlice.Values(), expect,
)).To(BeTrue())
},
func(given, should string, source []string, expect []OutputFormatEnum) string {
func(given, should string, _ []string, _ []OutputFormatEnum) string {
return fmt.Sprintf("🧪 --> 🍈 given: '%v', should: '%v'",
given, should)
},
Expand All @@ -169,12 +169,12 @@ var _ = Describe("Enum", func() {
)

DescribeTable("AllAreValid",
func(given, should string, source []string, expect bool) {
func(_, _ string, source []string, expect bool) {
outputFormatEnumSlice.Source = source

Expect(outputFormatEnumSlice.AllAreValid()).To(Equal(expect))
},
func(given, should string, source []string, expect bool) string {
func(given, should string, _ []string, _ bool) string {
return fmt.Sprintf("🧪 --> 🍈 given: '%v', should: '%v'",
given, should)
},
Expand All @@ -193,12 +193,12 @@ var _ = Describe("Enum", func() {
)

DescribeTable("AllAreValidOrEmpty",
func(given, should string, source []string, expect bool) {
func(_, _ string, source []string, expect bool) {
outputFormatEnumSlice.Source = source

Expect(outputFormatEnumSlice.AllAreValidOrEmpty()).To(Equal(expect))
},
func(given, should string, source []string, expect bool) string {
func(given, should string, _ []string, _ bool) string {
return fmt.Sprintf("🧪 --> 🍈 given: '%v', should: '%v'",
given, should)
},
Expand Down Expand Up @@ -271,7 +271,7 @@ var _ = Describe("Enum", func() {
wrapper := paramSet.BindValidatedEnum(
assistant.NewFlagInfo("format", "f", "xml"),
&outputFormatEnum.Source,
func(value string, flag *pflag.Flag) error {
func(value string, _ *pflag.Flag) error {
return lo.Ternary(outputFormatEnumInfo.IsValid(value), nil,
fmt.Errorf("Enum value: '%v' is not valid", value))
},
Expand All @@ -288,7 +288,7 @@ var _ = Describe("Enum", func() {
wrapper := paramSet.BindValidatedEnum(
assistant.NewFlagInfo("format", "f", "xml"),
&outputFormatEnum.Source,
func(value string, flag *pflag.Flag) error {
func(value string, _ *pflag.Flag) error {
return lo.Ternary(outputFormatEnum.IsValid(), nil,
fmt.Errorf("Enum value: '%v' is not valid", value))
},
Expand Down
Loading

0 comments on commit 443a365

Please sign in to comment.