Skip to content

Commit 358d325

Browse files
chore(deps): update golangci-lint (#186)
* chore(deps): bump github.com/fxamacker/cbor/v2 from 2.7.0 to 2.8.0 Bumps [github.com/fxamacker/cbor/v2](https://github.com/fxamacker/cbor) from 2.7.0 to 2.8.0. - [Release notes](https://github.com/fxamacker/cbor/releases) - [Commits](fxamacker/cbor@v2.7.0...v2.8.0) --- updated-dependencies: - dependency-name: github.com/fxamacker/cbor/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * updated the comments and golang ci lint Signed-off-by: Gergely Brautigam <[email protected]> --------- Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Gergely Brautigam <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gergely Brautigam <[email protected]>
1 parent 81051f9 commit 358d325

19 files changed

+92
-101
lines changed

.golangci.yaml

+35-78
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
version: "2"
2+
13
run:
2-
go: "1.23"
4+
go: "1.24"
35
timeout: 10m
46
tests: false
57
allow-parallel-runners: true
68
issues-exit-code: 2
79

810
linters:
9-
enable-all: true
11+
default: all
1012
disable:
1113
- bodyclose
1214
- containedctx # Struct should not contain context, action does.
@@ -15,18 +17,13 @@ linters:
1517
- depguard
1618
- dogsled
1719
- dupl # Check code duplications.
18-
- execinquery
1920
- exhaustive # Doesn't really make sense.
2021
- exhaustruct # Doesn't really make sense.
21-
- exportloopref
2222
- forcetypeassert # Priority: that can lead to serious crashes.
2323
- funlen # Break long functions.
24-
- gci
2524
- gochecknoglobals
2625
- gochecknoinits # Init functions cause an import to have side effects,
2726
- err113
28-
- goimports # acts weirdly, dci handles imports anyway
29-
- gomnd # Give constant values a name with constants.
3027
- interfacebloat
3128
- ireturn # Accept interface, return concrate.
3229
- lll
@@ -45,75 +42,35 @@ linters:
4542
- wrapcheck
4643
- wsl
4744

48-
linters-settings:
49-
gci:
50-
sections:
51-
- standard
52-
- blank
53-
- dot
54-
- default
55-
- prefix(github.com/open-component-model/ocm)
56-
custom-order: true
57-
funlen:
58-
lines: 110
59-
statements: 60
60-
cyclop:
61-
max-complexity: 60
62-
skip-tests: true
63-
gocognit:
64-
min-complexity: 60
65-
nolintlint:
66-
allow-unused: false
67-
require-explanation: true
68-
require-specific: false
69-
varnamelen:
70-
ignore-names:
71-
- err
72-
- wg
73-
- id
74-
lll:
75-
line-length: 120
76-
gosec:
77-
exclude-generated: true
45+
settings:
46+
funlen:
47+
lines: 110
48+
statements: 60
49+
cyclop:
50+
max-complexity: 60
51+
gocognit:
52+
min-complexity: 60
53+
nolintlint:
54+
allow-unused: false
55+
require-explanation: true
56+
require-specific: false
57+
varnamelen:
58+
ignore-names:
59+
- err
60+
- wg
61+
- id
62+
revive:
63+
rules:
64+
- name: package-comments
65+
disabled: true
66+
- name: exported
67+
disabled: true
68+
69+
lll:
70+
line-length: 120
7871

79-
issues:
80-
exclude-files:
81-
- v1beta1/types_jsonschema.go
82-
- v1beta1/marshal.go
83-
- v1beta1/marshal_test.go
84-
exclude:
85-
- composites
86-
exclude-rules:
87-
- path: cmds/
88-
linters:
89-
- forbidigo
90-
- source: "https://"
91-
linters:
92-
- lll
93-
- text: "shadow: declaration of \"err\""
94-
linters:
95-
- govet
96-
- text: "shadow: declaration of \"ok\""
97-
linters:
98-
- govet
99-
- path: _test\.go
100-
linters:
101-
- gocyclo
102-
- errcheck
103-
- gosec
104-
- dupl
105-
- funlen
106-
- scopelint
107-
- text: "Spec.DeepCopyInto undefined"
108-
linters:
109-
- typecheck
110-
- text: "G601: Implicit memory aliasing in for loop"
111-
# Ignored cos why not, that was the request.
112-
linters:
113-
- gosec
114-
- source: "// .* #\\d+"
115-
linters:
116-
- godox
117-
- path: ignore/.*\.go
118-
linters:
119-
- dupword
72+
exclusions:
73+
paths:
74+
- v1beta1/types_jsonschema.go
75+
- v1beta1/marshal.go
76+
- v1beta1/marshal_test.go

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ clean: ## Runs go clean
5454
go clean -i
5555

5656
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
57-
GOLANGCI_LINT_VERSION ?= v1.60.1
57+
GOLANGCI_LINT_VERSION ?= v2.0.2
5858

5959
golangci-lint: $(GOLANGCI_LINT)
6060
$(GOLANGCI_LINT): $(LOCALBIN)

cmd/config_file_schema.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package cmd
22

3+
// URLs contains url configuration.
34
type URLs struct {
45
URL string `json:"url"`
56
Username string `json:"username,omitempty"`
67
Password string `json:"password,omitempty"`
78
Token string `json:"token,omitempty"`
89
}
910

11+
// GITUrls contains git url configuration.
1012
type GITUrls struct {
1113
URL string `json:"url"`
1214
Username string `json:"username,omitempty"`

cmd/config_handler.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67

78
"k8s.io/apimachinery/pkg/util/yaml"
89

910
"github.com/Skarlso/crd-to-sample-yaml/pkg"
1011
)
1112

13+
// ConfigHandler contains config.
1214
type ConfigHandler struct {
1315
configFileLocation string
1416
}
1517

18+
// CRDs returns schema types gathered from a config.
1619
func (h *ConfigHandler) CRDs() ([]*pkg.SchemaType, error) {
1720
if _, err := os.Stat(h.configFileLocation); os.IsNotExist(err) {
1821
return nil, fmt.Errorf("file under '%s' does not exist", h.configFileLocation)
1922
}
20-
content, err := os.ReadFile(h.configFileLocation)
23+
content, err := os.ReadFile(filepath.Clean(h.configFileLocation))
2124
if err != nil {
2225
return nil, fmt.Errorf("failed to read file: %w", err)
2326
}

cmd/crd.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
)
1414

1515
const (
16+
// FormatHTML is a setting that is accepted as a format output type. The type is HTML.
1617
FormatHTML = "html"
18+
// FormatYAML is a setting that is accepted as a format output type. The type is YAML.
1719
FormatYAML = "yaml"
1820
)
1921

@@ -35,6 +37,7 @@ type crdGenArgs struct {
3537

3638
var crdArgs = &crdGenArgs{}
3739

40+
// Handler defines an interface for all CRD providers to return Schemas.
3841
type Handler interface {
3942
CRDs() ([]*pkg.SchemaType, error)
4043
}
@@ -108,7 +111,7 @@ func runGenerate(_ *cobra.Command, _ []string) error {
108111
} else {
109112
outputLocation := filepath.Join(crdArgs.output, crd.Kind+"_sample."+crdArgs.format)
110113
// closed later during render
111-
outputFile, err := os.Create(outputLocation)
114+
outputFile, err := os.Create(filepath.Clean(outputLocation))
112115
if err != nil {
113116
errs = append(errs, fmt.Errorf("failed to create file at: '%s': %w", outputLocation, err))
114117

cmd/file_handler.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67

78
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
89
"k8s.io/apimachinery/pkg/util/yaml"
@@ -11,16 +12,18 @@ import (
1112
"github.com/Skarlso/crd-to-sample-yaml/pkg/sanitize"
1213
)
1314

15+
// FileHandler provides options for a file provider.
1416
type FileHandler struct {
1517
location string
1618
group string
1719
}
1820

21+
// CRDs returns schemas parsed out of a file.
1922
func (h *FileHandler) CRDs() ([]*pkg.SchemaType, error) {
2023
if _, err := os.Stat(h.location); os.IsNotExist(err) {
2124
return nil, fmt.Errorf("file under '%s' does not exist", h.location)
2225
}
23-
content, err := os.ReadFile(h.location)
26+
content, err := os.ReadFile(filepath.Clean(h.location))
2427
if err != nil {
2528
return nil, fmt.Errorf("failed to read file: %w", err)
2629
}

cmd/folder_handler.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import (
1313
"github.com/Skarlso/crd-to-sample-yaml/pkg/sanitize"
1414
)
1515

16+
// FolderHandler scans folders and returns schemas found in that folder.
1617
type FolderHandler struct {
1718
location string
1819
group string
1920
}
2021

22+
// CRDs goes through schemas in folders.
2123
func (h *FolderHandler) CRDs() ([]*pkg.SchemaType, error) {
2224
if _, err := os.Stat(h.location); os.IsNotExist(err) {
2325
return nil, fmt.Errorf("file under '%s' does not exist", h.location)
@@ -40,7 +42,7 @@ func (h *FolderHandler) CRDs() ([]*pkg.SchemaType, error) {
4042
return nil
4143
}
4244

43-
content, err := os.ReadFile(path)
45+
content, err := os.ReadFile(filepath.Clean(path))
4446
if err != nil {
4547
return fmt.Errorf("failed to read file: %w", err)
4648
}

cmd/git_handler.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/Skarlso/crd-to-sample-yaml/pkg/sanitize"
2020
)
2121

22+
// GitHandler contains data to parse git configuration and values.
2223
type GitHandler struct {
2324
URL string
2425
Username string
@@ -32,6 +33,7 @@ type GitHandler struct {
3233
group string // this is used by the configfile.
3334
}
3435

36+
// CRDs returns a list of crds parsed out from crds contained in a git repository.
3537
func (g *GitHandler) CRDs() ([]*pkg.SchemaType, error) {
3638
opts, err := g.constructGitOptions()
3739
if err != nil {

cmd/kube_handler.go

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/Skarlso/crd-to-sample-yaml/pkg"
1616
)
1717

18+
// KubeHandler contains data for a kubernetes resource.
1819
type KubeHandler struct {
1920
crd string
2021
group string
@@ -23,6 +24,7 @@ type KubeHandler struct {
2324
resource string
2425
}
2526

27+
// CRDs returns schemas found in a cluster that have been installed.
2628
func (h *KubeHandler) CRDs() ([]*pkg.SchemaType, error) {
2729
kubeconfig := os.Getenv("KUBECONFIG")
2830
if kubeconfig == "" {

cmd/test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func init() {
3636

3737
func runTest(cmd *cobra.Command, args []string) {
3838
if len(args) == 0 {
39-
fmt.Fprintf(os.Stderr, "test needs an argument where the tests are located at")
39+
_, _ = fmt.Fprintf(os.Stderr, "test needs an argument where the tests are located at")
4040

4141
os.Exit(1)
4242
}
@@ -81,7 +81,7 @@ func displayWarnings(warnings []tests.Outcome) error {
8181
t.AppendSeparator()
8282
t.Render()
8383

84-
fmt.Fprintf(os.Stdout, "\nTests total: %d, failed: %d, passed: %d\n", len(warnings), errs, len(warnings)-errs)
84+
_, _ = fmt.Fprintf(os.Stdout, "\nTests total: %d, failed: %d, passed: %d\n", len(warnings), errs, len(warnings)-errs)
8585

8686
if errs > 0 {
8787
return fmt.Errorf("%d test(s) failed", errs)

go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
module github.com/Skarlso/crd-to-sample-yaml
22

3-
go 1.23.0
4-
5-
toolchain go1.23.2
3+
go 1.24.1
64

75
require (
86
github.com/brianvoe/gofakeit/v6 v6.28.0
97
github.com/fatih/color v1.18.0
10-
github.com/fxamacker/cbor/v2 v2.7.0
8+
github.com/fxamacker/cbor/v2 v2.8.0
119
github.com/go-git/go-git/v5 v5.14.0
1210
github.com/google/go-cmp v0.7.0
1311
github.com/jedib0t/go-pretty/v6 v6.6.7

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
4949
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
5050
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
5151
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
52-
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
53-
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
52+
github.com/fxamacker/cbor/v2 v2.8.0 h1:fFtUGXUzXPHTIUdne5+zzMPTfffl3RD5qYnkY40vtxU=
53+
github.com/fxamacker/cbor/v2 v2.8.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
5454
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
5555
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
5656
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=

pkg/matches/matchsnapshot/matcher.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ import (
1414
"github.com/Skarlso/crd-to-sample-yaml/pkg/tests"
1515
)
1616

17+
// MatcherName is the name of this matcher YAML.
1718
const MatcherName = "matchSnapshot"
1819

20+
// Config contains configuration details for the Matcher. Path, ignoring errors and minimal setting.
1921
type Config struct {
2022
Path string `yaml:"path"`
2123
IgnoreErrors []string `yaml:"ignoreErrors,omitempty"`
2224
Minimal bool `yaml:"minimal"`
2325
}
2426

27+
// Matcher is a snapshot based matcher.
2528
type Matcher struct {
2629
Updater Updater
2730
}
@@ -32,6 +35,7 @@ func init() {
3235
}, MatcherName)
3336
}
3437

38+
// Match actually does the matching.
3539
func (m *Matcher) Match(ctx context.Context, crdLocation string, payload []byte) error {
3640
c := Config{}
3741
if err := yaml.Unmarshal(payload, &c); err != nil {
@@ -79,7 +83,7 @@ func (m *Matcher) Match(ctx context.Context, crdLocation string, payload []byte)
7983
return err
8084
}
8185

82-
content, err := os.ReadFile(crdLocation)
86+
content, err := os.ReadFile(filepath.Clean(crdLocation))
8387
if err != nil {
8488
return fmt.Errorf("failed to read source template: %w", err)
8589
}
@@ -89,7 +93,7 @@ func (m *Matcher) Match(ctx context.Context, crdLocation string, payload []byte)
8993
for _, s := range snapshots {
9094
// one snapshot will contain a single version and the validation
9195
// will know which version to check against
92-
snapshotContent, err := os.ReadFile(s)
96+
snapshotContent, err := os.ReadFile(filepath.Clean(s))
9397
if err != nil {
9498
return fmt.Errorf("failed to read snapshot template: %w", err)
9599
}

0 commit comments

Comments
 (0)