Skip to content

Commit fbe92bc

Browse files
committed
reviewed golangci.yml and fixed some issues
1 parent 16d0ada commit fbe92bc

File tree

36 files changed

+84
-60
lines changed

36 files changed

+84
-60
lines changed

build/ci/golangci.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,28 @@ linters:
6969
comparison: false
7070
exhaustive:
7171
default-signifies-exhaustive: true
72-
gosec:
73-
severity: medium
72+
recvcheck:
73+
disable-builtin: false
74+
exclusions:
75+
- "*.UnmarshalText"
76+
- "*.UnmarshalJSON"
77+
- "*.UnmarshalYAML"
78+
- "*.UnmarshalXML"
79+
- "*.UnmarshalBinary"
80+
- "*.GobDecode"
81+
- "*.String"
82+
- "*.Scan"
7483
staticcheck:
7584
checks:
7685
- "all"
77-
- "-QF*"
78-
- "-S1039" # unnecessary use of fmt.Sprintf
79-
# assigning the result of this type assertion to a variable could eliminate type assertions in switch cases
86+
# Following are too verbose. Re-enable if we could control output based on severities
87+
- "-QF*" # Quickfixes
88+
- "-ST1*" # Stylistic issues.
8089
# TODO Tech debt to fix
81-
- "-S*"
90+
- "-S*" # Any other code simplication issues. Too many places (~100)
91+
- "-S1034" # "could eliminate this type assertion". Too many places (~100)
92+
- "-SA1019" # "Using a deprecated function, variable, constant or field". Re-enable when OPA is migrated
93+
- "-SA1006" # "printf-style function without additional arguments". We probably won't fix these
8294
exclusions:
8395
generated: lax
8496
presets:
@@ -102,12 +114,12 @@ severity:
102114
- linters:
103115
- contextcheck
104116
- noctx
105-
- staticcheck
106117
- recvcheck
107118
severity: warning
108119
- linters:
109120
- errorlint
110121
- exhaustive
122+
- staticcheck
111123
- unused
112124
severity: info
113125

cmd/lanai-cli/cmdutils/flag_base64.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (v *Base64Value) Set(s string) error {
4949
return nil
5050
}
5151

52-
func (v Base64Value) Type() string {
52+
func (v *Base64Value) Type() string {
5353
return "base64"
5454
}
5555

@@ -78,7 +78,7 @@ func (v Base64Value) Type() string {
7878
// panic("implement me")
7979
//}
8080

81-
func (v Base64Value) decode(s string) ([]byte, error) {
81+
func (v *Base64Value) decode(s string) ([]byte, error) {
8282
var data []byte
8383
_, e := base64.StdEncoding.Decode([]byte(s), data)
8484
return data, e

cmd/lanai-cli/cmdutils/go_cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func GoModTidy(ctx context.Context, extraShellOptions []ShCmdOptions, opts ...Go
272272
}
273273

274274
func GetGoMod(ctx context.Context, opts ...GoCmdOptions) (*GoMod, error) {
275-
cmd := fmt.Sprintf("go mod edit -json")
275+
cmd := "go mod edit -json"
276276
for _, f := range opts {
277277
f(&cmd)
278278
}

cmd/lanai-cli/cmdutils/matcher_strings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func WithSubString(substr string, caseInsensitive bool) StringMatcher {
6464
}
6565

6666
func AnyNonEmptyString() StringMatcher {
67-
desc := fmt.Sprintf("matches any non-empty string")
67+
desc := "matches any non-empty string"
6868
return &GenericMatcher[string]{
6969
MatchFunc: func(_ context.Context, value string) (bool, error) {
7070
return value != "", nil

cmd/lanai-cli/cmdutils/shell.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ func RunShellCommands(ctx context.Context, opts ...ShCmdOptions) (uint8, error)
132132
}
133133

134134
func runSingleCommand(ctx context.Context, cmd string, opt *ShCmdOption) (uint8, error){
135-
p, err := syntax.NewParser().Parse(strings.NewReader(cmd), "")
136-
if err != nil {
137-
return 1, err
135+
p, e := syntax.NewParser().Parse(strings.NewReader(cmd), "")
136+
if e != nil {
137+
return 1, e
138138
}
139139

140-
r, err := interp.New(
140+
r, e := interp.New(
141141
interp.Params("-e"),
142142
interp.Dir(opt.Dir),
143143
interp.Env(expand.ListEnviron(opt.Env...)),
144144
interp.OpenHandler(openHandler),
145145
interp.StdIO(opt.Stdin, opt.Stdout, opt.Stderr),
146146
)
147-
if err != nil {
148-
return 1, err
147+
if e != nil {
148+
return 1, e
149149
}
150150

151151
if opt.ShowCmd && !ShCmdLogDisabled {
@@ -169,7 +169,7 @@ func runSingleCommand(ctx context.Context, cmd string, opt *ShCmdOption) (uint8,
169169
}
170170

171171
if e := r.Run(ctx, p); e != nil {
172-
if status, ok := interp.IsExitStatus(err); ok {
172+
if status, ok := interp.IsExitStatus(e); ok {
173173
return status, e
174174
}
175175
return 1, e

cmd/lanai-cli/deps/dropreplace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func RunDropReplace(cmd *cobra.Command, _ []string) error {
7070
if e != nil {
7171
return fmt.Errorf("failed to drop invalid replace: %v", e)
7272
}
73-
changed = len(dropped) != 0
73+
changed = changed || len(dropped) != 0
7474

7575
if changed {
7676
if e := cmdutils.GoModTidy(cmd.Context(), nil); e != nil {
@@ -79,7 +79,7 @@ func RunDropReplace(cmd *cobra.Command, _ []string) error {
7979
}
8080

8181
// mark changes if requested
82-
msg := fmt.Sprintf("dropped replaces in go.mod for CI/CD process")
82+
msg := "dropped replaces in go.mod for CI/CD process"
8383
tag, e := markChangesIfRequired(cmd.Context(), msg, cmdutils.GitFilePattern("go.mod", "go.sum"))
8484
if e == nil && tag != "" {
8585
logger.WithContext(cmd.Context()).Infof(`Modified go.mod/go.sum are tagged with Git Tag [%s]`, tag)

cmd/lanai-cli/deps/updatedep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func RunUpdateDep(cmd *cobra.Command, _ []string) error {
7171
}
7272

7373
// mark changes if requested
74-
msg := fmt.Sprintf("updated versions of private modules")
74+
msg := "updated versions of private modules"
7575
tag, e := markChangesIfRequired(cmd.Context(), msg, cmdutils.GitFilePattern("go.mod", "go.sum"))
7676
if e == nil && tag != "" {
7777
logger.WithContext(cmd.Context()).Infof(`Modified go.mod/go.sum are tagged with Git Tag [%s]`, tag)

pkg/appconfig/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ type ProviderMeta struct {
6666
Precedence int //the precedence for which the settings will take effect.
6767
}
6868

69-
func (m ProviderMeta) GetSettings() map[string]interface{} {
69+
func (m *ProviderMeta) GetSettings() map[string]interface{} {
7070
return m.Settings
7171
}
7272

73-
func (m ProviderMeta) Order() int {
73+
func (m *ProviderMeta) Order() int {
7474
return m.Precedence
7575
}
7676

77-
func (m ProviderMeta) IsLoaded() bool {
77+
func (m *ProviderMeta) IsLoaded() bool {
7878
return m.Loaded
7979
}
8080

pkg/appconfig/provider_group.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ func NewStaticProviderGroup(order int, providers ...Provider) *StaticProviderGro
3535
}
3636
}
3737

38-
func (g StaticProviderGroup) Order() int {
38+
func (g *StaticProviderGroup) Order() int {
3939
return g.Precedence
4040
}
4141

42-
func (g StaticProviderGroup) Providers(_ context.Context, _ bootstrap.ApplicationConfig) []Provider {
42+
func (g *StaticProviderGroup) Providers(_ context.Context, _ bootstrap.ApplicationConfig) []Provider {
4343
return g.StaticProviders
4444
}
4545

pkg/data/types/pqcrypt/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type EncryptedRaw struct {
123123
}
124124

125125
// GormDataType implements schema.GormDataTypeInterface
126-
func (EncryptedRaw) GormDataType() string {
126+
func (*EncryptedRaw) GormDataType() string {
127127
return "jsonb"
128128
}
129129

0 commit comments

Comments
 (0)