Skip to content

Commit d9bd74b

Browse files
authored
ci: added forcetypeassert, misspell, and paralleltest lint rules (#120)
* ci: added `forcetypeassert` and `misspell` lint rules * added paralleltest
1 parent 7638382 commit d9bd74b

File tree

9 files changed

+119
-8
lines changed

9 files changed

+119
-8
lines changed

.golangci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ issues:
55
linters:
66
disable-all: true
77
enable:
8-
- deadcode
98
- durationcheck
109
- errcheck
1110
- exportloopref
11+
- forcetypeassert
1212
- gofmt
1313
- gosimple
1414
- ineffassign
1515
- makezero
16+
- misspell
1617
- nilerr
17-
# - paralleltest # Reference: https://github.com/kunwardeep/paralleltest/issues/14
18+
- paralleltest
1819
- predeclared
1920
- staticcheck
2021
- tenv
2122
- unconvert
2223
- unparam
23-
- varcheck
24+
- unused
2425
- vet

internal/hclogutils/args_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func TestFieldMapsToArgs(t *testing.T) {
151151
gotValues := make(map[string]interface{}, len(got)/2)
152152

153153
for i := 0; i < len(got); i += 2 {
154+
//nolint:forcetypeassert // Not needed in test of log mapping
154155
k, v := got[i].(string), got[i+1]
155156
gotKeys = append(gotKeys, k)
156157
gotValues[k] = v

internal/logging/provider.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ func GetProviderRootLogger(ctx context.Context) hclog.Logger {
1313
if logger == nil {
1414
return nil
1515
}
16-
return logger.(hclog.Logger)
16+
17+
hclogger, ok := logger.(hclog.Logger)
18+
if !ok {
19+
return nil
20+
}
21+
return hclogger
1722
}
1823

1924
// GetProviderRootLoggerOptions returns the root logger options used for
@@ -64,7 +69,13 @@ func GetProviderSubsystemLogger(ctx context.Context, subsystem string) hclog.Log
6469
if logger == nil {
6570
return nil
6671
}
67-
return logger.(hclog.Logger)
72+
73+
hclogger, ok := logger.(hclog.Logger)
74+
if !ok {
75+
return nil
76+
}
77+
78+
return hclogger
6879
}
6980

7081
// SetProviderSubsystemLogger sets `logger` as the logger for the named

internal/logging/sdk.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ func GetSDKRootLogger(ctx context.Context) hclog.Logger {
1313
if logger == nil {
1414
return nil
1515
}
16-
return logger.(hclog.Logger)
16+
17+
hclogger, ok := logger.(hclog.Logger)
18+
if !ok {
19+
return nil
20+
}
21+
22+
return hclogger
1723
}
1824

1925
// GetSDKRootLoggerOptions returns the root logger options used for
@@ -80,7 +86,13 @@ func GetSDKSubsystemLogger(ctx context.Context, subsystem string) hclog.Logger {
8086
if logger == nil {
8187
return nil
8288
}
83-
return logger.(hclog.Logger)
89+
90+
hclogger, ok := logger.(hclog.Logger)
91+
if !ok {
92+
return nil
93+
}
94+
95+
return hclogger
8496
}
8597

8698
// SetSDKSubsystemLogger sets `logger` as the logger for the named subsystem in

internal/logging/sink.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ func GetSink(ctx context.Context) hclog.Logger {
1313
if logger == nil {
1414
return nil
1515
}
16-
return logger.(hclog.Logger)
16+
17+
hclogger, ok := logger.(hclog.Logger)
18+
if !ok {
19+
return nil
20+
}
21+
22+
return hclogger
1723
}
1824

1925
// GetSinkOptions returns the root logger options used for

tflog/provider_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ func TestError(t *testing.T) {
566566
const testLogMsg = "System FOO has caused error BAR because of incorrectly configured BAZ"
567567

568568
func TestOmitLogWithFieldKeys(t *testing.T) {
569+
t.Parallel()
570+
569571
testCases := map[string]struct {
570572
msg string
571573
additionalFields []map[string]interface{}
@@ -650,6 +652,8 @@ func TestOmitLogWithFieldKeys(t *testing.T) {
650652
}
651653

652654
func TestOmitLogWithMessageRegexes(t *testing.T) {
655+
t.Parallel()
656+
653657
testCases := map[string]struct {
654658
msg string
655659
additionalFields []map[string]interface{}
@@ -734,6 +738,8 @@ func TestOmitLogWithMessageRegexes(t *testing.T) {
734738
}
735739

736740
func TestOmitLogWithMessageStrings(t *testing.T) {
741+
t.Parallel()
742+
737743
testCases := map[string]struct {
738744
msg string
739745
additionalFields []map[string]interface{}
@@ -818,6 +824,8 @@ func TestOmitLogWithMessageStrings(t *testing.T) {
818824
}
819825

820826
func TestMaskFieldValuesWithFieldKeys(t *testing.T) {
827+
t.Parallel()
828+
821829
testCases := map[string]struct {
822830
msg string
823831
additionalFields []map[string]interface{}
@@ -910,6 +918,8 @@ func TestMaskFieldValuesWithFieldKeys(t *testing.T) {
910918
}
911919

912920
func TestMaskAllFieldValuesRegexes(t *testing.T) {
921+
t.Parallel()
922+
913923
testCases := map[string]struct {
914924
msg string
915925
additionalFields []map[string]interface{}
@@ -1002,6 +1012,8 @@ func TestMaskAllFieldValuesRegexes(t *testing.T) {
10021012
}
10031013

10041014
func TestMaskAllFieldValuesStrings(t *testing.T) {
1015+
t.Parallel()
1016+
10051017
testCases := map[string]struct {
10061018
msg string
10071019
additionalFields []map[string]interface{}
@@ -1094,6 +1106,8 @@ func TestMaskAllFieldValuesStrings(t *testing.T) {
10941106
}
10951107

10961108
func TestMaskMessageRegexes(t *testing.T) {
1109+
t.Parallel()
1110+
10971111
testCases := map[string]struct {
10981112
msg string
10991113
additionalFields []map[string]interface{}
@@ -1186,6 +1200,8 @@ func TestMaskMessageRegexes(t *testing.T) {
11861200
}
11871201

11881202
func TestMaskMessageStrings(t *testing.T) {
1203+
t.Parallel()
1204+
11891205
testCases := map[string]struct {
11901206
msg string
11911207
additionalFields []map[string]interface{}
@@ -1278,6 +1294,8 @@ func TestMaskMessageStrings(t *testing.T) {
12781294
}
12791295

12801296
func TestMaskLogRegexes(t *testing.T) {
1297+
t.Parallel()
1298+
12811299
testCases := map[string]struct {
12821300
msg string
12831301
additionalFields []map[string]interface{}
@@ -1370,6 +1388,8 @@ func TestMaskLogRegexes(t *testing.T) {
13701388
}
13711389

13721390
func TestMaskLogStrings(t *testing.T) {
1391+
t.Parallel()
1392+
13731393
testCases := map[string]struct {
13741394
msg string
13751395
additionalFields []map[string]interface{}

tflog/subsystem_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ func TestSubsystemError(t *testing.T) {
575575
}
576576

577577
func TestSubsystemOmitLogWithFieldKeys(t *testing.T) {
578+
t.Parallel()
579+
578580
testCases := map[string]struct {
579581
msg string
580582
additionalFields []map[string]interface{}
@@ -660,6 +662,8 @@ func TestSubsystemOmitLogWithFieldKeys(t *testing.T) {
660662
}
661663

662664
func TestSubsystemOmitLogWithMessageRegexes(t *testing.T) {
665+
t.Parallel()
666+
663667
testCases := map[string]struct {
664668
msg string
665669
additionalFields []map[string]interface{}
@@ -745,6 +749,8 @@ func TestSubsystemOmitLogWithMessageRegexes(t *testing.T) {
745749
}
746750

747751
func TestSubsystemOmitLogWithMessageStrings(t *testing.T) {
752+
t.Parallel()
753+
748754
testCases := map[string]struct {
749755
msg string
750756
additionalFields []map[string]interface{}
@@ -830,6 +836,8 @@ func TestSubsystemOmitLogWithMessageStrings(t *testing.T) {
830836
}
831837

832838
func TestSubsystemMaskFieldValuesWithFieldKeys(t *testing.T) {
839+
t.Parallel()
840+
833841
testCases := map[string]struct {
834842
msg string
835843
additionalFields []map[string]interface{}
@@ -923,6 +931,8 @@ func TestSubsystemMaskFieldValuesWithFieldKeys(t *testing.T) {
923931
}
924932

925933
func TestSubsystemMaskAllFieldValuesRegexes(t *testing.T) {
934+
t.Parallel()
935+
926936
testCases := map[string]struct {
927937
msg string
928938
additionalFields []map[string]interface{}
@@ -1016,6 +1026,8 @@ func TestSubsystemMaskAllFieldValuesRegexes(t *testing.T) {
10161026
}
10171027

10181028
func TestSubsystemMaskAllFieldValuesStrings(t *testing.T) {
1029+
t.Parallel()
1030+
10191031
testCases := map[string]struct {
10201032
msg string
10211033
additionalFields []map[string]interface{}
@@ -1109,6 +1121,8 @@ func TestSubsystemMaskAllFieldValuesStrings(t *testing.T) {
11091121
}
11101122

11111123
func TestSubsystemMaskMessageRegexes(t *testing.T) {
1124+
t.Parallel()
1125+
11121126
testCases := map[string]struct {
11131127
msg string
11141128
additionalFields []map[string]interface{}
@@ -1202,6 +1216,8 @@ func TestSubsystemMaskMessageRegexes(t *testing.T) {
12021216
}
12031217

12041218
func TestSubsystemMaskMessageStrings(t *testing.T) {
1219+
t.Parallel()
1220+
12051221
testCases := map[string]struct {
12061222
msg string
12071223
additionalFields []map[string]interface{}
@@ -1295,6 +1311,8 @@ func TestSubsystemMaskMessageStrings(t *testing.T) {
12951311
}
12961312

12971313
func TestSubsystemMaskLogRegexes(t *testing.T) {
1314+
t.Parallel()
1315+
12981316
testCases := map[string]struct {
12991317
msg string
13001318
additionalFields []map[string]interface{}
@@ -1388,6 +1406,8 @@ func TestSubsystemMaskLogRegexes(t *testing.T) {
13881406
}
13891407

13901408
func TestSubsystemMaskLogStrings(t *testing.T) {
1409+
t.Parallel()
1410+
13911411
testCases := map[string]struct {
13921412
msg string
13931413
additionalFields []map[string]interface{}

tfsdklog/sdk_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ func TestError(t *testing.T) {
566566
const testLogMsg = "System FOO has caused error BAR because of incorrectly configured BAZ"
567567

568568
func TestOmitLogWithFieldKeys(t *testing.T) {
569+
t.Parallel()
570+
569571
testCases := map[string]struct {
570572
msg string
571573
additionalFields []map[string]interface{}
@@ -650,6 +652,8 @@ func TestOmitLogWithFieldKeys(t *testing.T) {
650652
}
651653

652654
func TestOmitLogWithMessageRegexes(t *testing.T) {
655+
t.Parallel()
656+
653657
testCases := map[string]struct {
654658
msg string
655659
additionalFields []map[string]interface{}
@@ -734,6 +738,8 @@ func TestOmitLogWithMessageRegexes(t *testing.T) {
734738
}
735739

736740
func TestOmitLogWithMessageStrings(t *testing.T) {
741+
t.Parallel()
742+
737743
testCases := map[string]struct {
738744
msg string
739745
additionalFields []map[string]interface{}
@@ -818,6 +824,8 @@ func TestOmitLogWithMessageStrings(t *testing.T) {
818824
}
819825

820826
func TestMaskFieldValuesWithFieldKeys(t *testing.T) {
827+
t.Parallel()
828+
821829
testCases := map[string]struct {
822830
msg string
823831
additionalFields []map[string]interface{}
@@ -910,6 +918,8 @@ func TestMaskFieldValuesWithFieldKeys(t *testing.T) {
910918
}
911919

912920
func TestMaskAllFieldValuesRegexes(t *testing.T) {
921+
t.Parallel()
922+
913923
testCases := map[string]struct {
914924
msg string
915925
additionalFields []map[string]interface{}
@@ -1002,6 +1012,8 @@ func TestMaskAllFieldValuesRegexes(t *testing.T) {
10021012
}
10031013

10041014
func TestMaskAllFieldValuesStrings(t *testing.T) {
1015+
t.Parallel()
1016+
10051017
testCases := map[string]struct {
10061018
msg string
10071019
additionalFields []map[string]interface{}
@@ -1094,6 +1106,8 @@ func TestMaskAllFieldValuesStrings(t *testing.T) {
10941106
}
10951107

10961108
func TestMaskMessageRegexes(t *testing.T) {
1109+
t.Parallel()
1110+
10971111
testCases := map[string]struct {
10981112
msg string
10991113
additionalFields []map[string]interface{}
@@ -1186,6 +1200,8 @@ func TestMaskMessageRegexes(t *testing.T) {
11861200
}
11871201

11881202
func TestMaskMessageStrings(t *testing.T) {
1203+
t.Parallel()
1204+
11891205
testCases := map[string]struct {
11901206
msg string
11911207
additionalFields []map[string]interface{}
@@ -1278,6 +1294,8 @@ func TestMaskMessageStrings(t *testing.T) {
12781294
}
12791295

12801296
func TestMaskLogRegexes(t *testing.T) {
1297+
t.Parallel()
1298+
12811299
testCases := map[string]struct {
12821300
msg string
12831301
additionalFields []map[string]interface{}
@@ -1370,6 +1388,8 @@ func TestMaskLogRegexes(t *testing.T) {
13701388
}
13711389

13721390
func TestMaskLogStrings(t *testing.T) {
1391+
t.Parallel()
1392+
13731393
testCases := map[string]struct {
13741394
msg string
13751395
additionalFields []map[string]interface{}

0 commit comments

Comments
 (0)