Skip to content

Commit

Permalink
ci: added forcetypeassert, misspell, and paralleltest lint rules (
Browse files Browse the repository at this point in the history
#120)

* ci: added `forcetypeassert` and `misspell` lint rules

* added paralleltest
  • Loading branch information
austinvalle committed Jan 24, 2023
1 parent 7638382 commit d9bd74b
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 8 deletions.
7 changes: 4 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ issues:
linters:
disable-all: true
enable:
- deadcode
- durationcheck
- errcheck
- exportloopref
- forcetypeassert
- gofmt
- gosimple
- ineffassign
- makezero
- misspell
- nilerr
# - paralleltest # Reference: https://github.com/kunwardeep/paralleltest/issues/14
- paralleltest
- predeclared
- staticcheck
- tenv
- unconvert
- unparam
- varcheck
- unused
- vet
1 change: 1 addition & 0 deletions internal/hclogutils/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func TestFieldMapsToArgs(t *testing.T) {
gotValues := make(map[string]interface{}, len(got)/2)

for i := 0; i < len(got); i += 2 {
//nolint:forcetypeassert // Not needed in test of log mapping
k, v := got[i].(string), got[i+1]
gotKeys = append(gotKeys, k)
gotValues[k] = v
Expand Down
15 changes: 13 additions & 2 deletions internal/logging/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ func GetProviderRootLogger(ctx context.Context) hclog.Logger {
if logger == nil {
return nil
}
return logger.(hclog.Logger)

hclogger, ok := logger.(hclog.Logger)
if !ok {
return nil
}
return hclogger
}

// GetProviderRootLoggerOptions returns the root logger options used for
Expand Down Expand Up @@ -64,7 +69,13 @@ func GetProviderSubsystemLogger(ctx context.Context, subsystem string) hclog.Log
if logger == nil {
return nil
}
return logger.(hclog.Logger)

hclogger, ok := logger.(hclog.Logger)
if !ok {
return nil
}

return hclogger
}

// SetProviderSubsystemLogger sets `logger` as the logger for the named
Expand Down
16 changes: 14 additions & 2 deletions internal/logging/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ func GetSDKRootLogger(ctx context.Context) hclog.Logger {
if logger == nil {
return nil
}
return logger.(hclog.Logger)

hclogger, ok := logger.(hclog.Logger)
if !ok {
return nil
}

return hclogger
}

// GetSDKRootLoggerOptions returns the root logger options used for
Expand Down Expand Up @@ -80,7 +86,13 @@ func GetSDKSubsystemLogger(ctx context.Context, subsystem string) hclog.Logger {
if logger == nil {
return nil
}
return logger.(hclog.Logger)

hclogger, ok := logger.(hclog.Logger)
if !ok {
return nil
}

return hclogger
}

// SetSDKSubsystemLogger sets `logger` as the logger for the named subsystem in
Expand Down
8 changes: 7 additions & 1 deletion internal/logging/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ func GetSink(ctx context.Context) hclog.Logger {
if logger == nil {
return nil
}
return logger.(hclog.Logger)

hclogger, ok := logger.(hclog.Logger)
if !ok {
return nil
}

return hclogger
}

// GetSinkOptions returns the root logger options used for
Expand Down
20 changes: 20 additions & 0 deletions tflog/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ func TestError(t *testing.T) {
const testLogMsg = "System FOO has caused error BAR because of incorrectly configured BAZ"

func TestOmitLogWithFieldKeys(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -650,6 +652,8 @@ func TestOmitLogWithFieldKeys(t *testing.T) {
}

func TestOmitLogWithMessageRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -734,6 +738,8 @@ func TestOmitLogWithMessageRegexes(t *testing.T) {
}

func TestOmitLogWithMessageStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -818,6 +824,8 @@ func TestOmitLogWithMessageStrings(t *testing.T) {
}

func TestMaskFieldValuesWithFieldKeys(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -910,6 +918,8 @@ func TestMaskFieldValuesWithFieldKeys(t *testing.T) {
}

func TestMaskAllFieldValuesRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1002,6 +1012,8 @@ func TestMaskAllFieldValuesRegexes(t *testing.T) {
}

func TestMaskAllFieldValuesStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1094,6 +1106,8 @@ func TestMaskAllFieldValuesStrings(t *testing.T) {
}

func TestMaskMessageRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1186,6 +1200,8 @@ func TestMaskMessageRegexes(t *testing.T) {
}

func TestMaskMessageStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1278,6 +1294,8 @@ func TestMaskMessageStrings(t *testing.T) {
}

func TestMaskLogRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1370,6 +1388,8 @@ func TestMaskLogRegexes(t *testing.T) {
}

func TestMaskLogStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down
20 changes: 20 additions & 0 deletions tflog/subsystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ func TestSubsystemError(t *testing.T) {
}

func TestSubsystemOmitLogWithFieldKeys(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -660,6 +662,8 @@ func TestSubsystemOmitLogWithFieldKeys(t *testing.T) {
}

func TestSubsystemOmitLogWithMessageRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -745,6 +749,8 @@ func TestSubsystemOmitLogWithMessageRegexes(t *testing.T) {
}

func TestSubsystemOmitLogWithMessageStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -830,6 +836,8 @@ func TestSubsystemOmitLogWithMessageStrings(t *testing.T) {
}

func TestSubsystemMaskFieldValuesWithFieldKeys(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -923,6 +931,8 @@ func TestSubsystemMaskFieldValuesWithFieldKeys(t *testing.T) {
}

func TestSubsystemMaskAllFieldValuesRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1016,6 +1026,8 @@ func TestSubsystemMaskAllFieldValuesRegexes(t *testing.T) {
}

func TestSubsystemMaskAllFieldValuesStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1109,6 +1121,8 @@ func TestSubsystemMaskAllFieldValuesStrings(t *testing.T) {
}

func TestSubsystemMaskMessageRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1202,6 +1216,8 @@ func TestSubsystemMaskMessageRegexes(t *testing.T) {
}

func TestSubsystemMaskMessageStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1295,6 +1311,8 @@ func TestSubsystemMaskMessageStrings(t *testing.T) {
}

func TestSubsystemMaskLogRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1388,6 +1406,8 @@ func TestSubsystemMaskLogRegexes(t *testing.T) {
}

func TestSubsystemMaskLogStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down
20 changes: 20 additions & 0 deletions tfsdklog/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ func TestError(t *testing.T) {
const testLogMsg = "System FOO has caused error BAR because of incorrectly configured BAZ"

func TestOmitLogWithFieldKeys(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -650,6 +652,8 @@ func TestOmitLogWithFieldKeys(t *testing.T) {
}

func TestOmitLogWithMessageRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -734,6 +738,8 @@ func TestOmitLogWithMessageRegexes(t *testing.T) {
}

func TestOmitLogWithMessageStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -818,6 +824,8 @@ func TestOmitLogWithMessageStrings(t *testing.T) {
}

func TestMaskFieldValuesWithFieldKeys(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -910,6 +918,8 @@ func TestMaskFieldValuesWithFieldKeys(t *testing.T) {
}

func TestMaskAllFieldValuesRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1002,6 +1012,8 @@ func TestMaskAllFieldValuesRegexes(t *testing.T) {
}

func TestMaskAllFieldValuesStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1094,6 +1106,8 @@ func TestMaskAllFieldValuesStrings(t *testing.T) {
}

func TestMaskMessageRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1186,6 +1200,8 @@ func TestMaskMessageRegexes(t *testing.T) {
}

func TestMaskMessageStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1278,6 +1294,8 @@ func TestMaskMessageStrings(t *testing.T) {
}

func TestMaskLogRegexes(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down Expand Up @@ -1370,6 +1388,8 @@ func TestMaskLogRegexes(t *testing.T) {
}

func TestMaskLogStrings(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
msg string
additionalFields []map[string]interface{}
Expand Down
Loading

0 comments on commit d9bd74b

Please sign in to comment.