Skip to content

Commit b1f4347

Browse files
authored
chore: add support for thelper, reassign, canonicalheader (#4072)
1 parent dd557be commit b1f4347

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+228
-13
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ linters:
1111
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
1212
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
1313
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
14+
- canonicalheader # canonicalheader checks whether net/http.Header uses canonical header [fast: false, auto-fix: false]
1415
- copyloopvar # copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false]
1516
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
1617
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
@@ -50,6 +51,7 @@ linters:
5051
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
5152
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
5253
- protogetter # Reports direct reads from proto message fields when getters should be used [fast: false, auto-fix: true]
54+
- reassign # Checks that package variables are not reassigned [fast: false, auto-fix: false]
5355
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
5456
- rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false]
5557
- sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false]
@@ -58,6 +60,7 @@ linters:
5860
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
5961
- testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false]
6062
- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
63+
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
6164
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
6265
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false]
6366
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]

internal/args/args_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func TestGetArgType(t *testing.T) {
170170

171171
run := func(tc *TestCase) func(*testing.T) {
172172
return func(t *testing.T) {
173+
t.Helper()
173174
res, err := args.GetArgType(tc.ArgType, tc.Name)
174175
if tc.expectedError == "" {
175176
require.NoError(t, err)

internal/args/marshal_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestMarshal(t *testing.T) {
2222

2323
run := func(testCase TestCase) func(t *testing.T) {
2424
return func(t *testing.T) {
25+
t.Helper()
2526
args, err := args.MarshalStruct(testCase.data)
2627

2728
if testCase.error == "" {
@@ -235,6 +236,7 @@ func TestMarshalValue(t *testing.T) {
235236

236237
run := func(testCase TestCase) func(t *testing.T) {
237238
return func(t *testing.T) {
239+
t.Helper()
238240
value, err := args.MarshalValue(testCase.data)
239241

240242
if testCase.error == "" {

internal/args/unmarshal_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestUnmarshalStruct(t *testing.T) {
2929

3030
run := func(testCase TestCase) func(t *testing.T) {
3131
return func(t *testing.T) {
32+
t.Helper()
3233
if testCase.data == nil {
3334
testCase.data = reflect.New(reflect.TypeOf(testCase.expected).Elem()).Interface()
3435
}
@@ -540,6 +541,7 @@ func TestIsUmarshalableValue(t *testing.T) {
540541

541542
run := func(testCase TestCase) func(t *testing.T) {
542543
return func(t *testing.T) {
544+
t.Helper()
543545
value := args.IsUmarshalableValue(testCase.data)
544546
assert.Equal(t, testCase.expected, value)
545547
}

internal/core/autocomplete_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type autoCompleteTestCase struct {
8686

8787
func runAutocompleteTest(ctx context.Context, tc *autoCompleteTestCase) func(*testing.T) {
8888
return func(t *testing.T) {
89+
t.Helper()
8990
words := tc.Words
9091
if len(words) == 0 {
9192
name := strings.Replace(t.Name(), "TestAutocomplete/", "", -1)

internal/core/bootstrap_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func TestInterruptError(t *testing.T) {
149149
),
150150
Cmd: "scw -o json test empty success",
151151
Check: func(t *testing.T, ctx *core.CheckFuncCtx) {
152+
t.Helper()
152153
assert.Equal(t, "[]\n", string(ctx.Stdout))
153154
},
154155
}))

internal/core/build_info_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func Test_CheckVersion(t *testing.T) {
3434
Cmd: "scw plop",
3535
Check: core.TestCheckCombine(
3636
func(t *testing.T, ctx *core.CheckFuncCtx) {
37+
t.Helper()
3738
assert.Equal(t, "A new version of scw is available (2.5.4), beware that you are currently running 1.20.0\n", ctx.LogBuffer)
3839
},
3940
),
@@ -48,6 +49,7 @@ func Test_CheckVersion(t *testing.T) {
4849
Cmd: "scw plop -D",
4950
Check: core.TestCheckCombine(
5051
func(t *testing.T, ctx *core.CheckFuncCtx) {
52+
t.Helper()
5153
assert.Contains(t, ctx.LogBuffer, "version is up to date (99.99.0)\n")
5254
},
5355
),
@@ -65,6 +67,7 @@ func Test_CheckVersion(t *testing.T) {
6567
Cmd: "scw plop -D",
6668
Check: core.TestCheckCombine(
6769
func(t *testing.T, ctx *core.CheckFuncCtx) {
70+
t.Helper()
6871
assert.Contains(t, ctx.LogBuffer, "version was already checked during past 24 hours\n")
6972
},
7073
),
@@ -86,6 +89,7 @@ func Test_CheckVersion(t *testing.T) {
8689
Cmd: "scw plop",
8790
Check: core.TestCheckCombine(
8891
func(t *testing.T, ctx *core.CheckFuncCtx) {
92+
t.Helper()
8993
assert.Contains(t, ctx.LogBuffer, "A new version of scw is available (2.5.4), beware that you are currently running 1.0.0\n")
9094
},
9195
),

internal/core/checks_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func TestCheckAPIKey(t *testing.T) {
7575
Check: core.TestCheckCombine(
7676
core.TestCheckExitCode(0),
7777
func(t *testing.T, ctx *core.CheckFuncCtx) {
78+
t.Helper()
7879
assert.True(t, strings.HasPrefix(ctx.LogBuffer, "Current api key expires in"))
7980
},
8081
),

internal/core/cobra_utils_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ func Test_MultiPositionalArg(t *testing.T) {
280280
core.TestCheckExitCode(0),
281281
core.TestCheckGolden(),
282282
func(t *testing.T, ctx *core.CheckFuncCtx) {
283+
t.Helper()
283284
res := ctx.Result.(*testAcceptMultiPositionalArgsType)
284285
assert.Len(t, res.NameIDs, 1)
285286
assert.Equal(t, "pos1", res.NameIDs[0])
@@ -295,6 +296,7 @@ func Test_MultiPositionalArg(t *testing.T) {
295296
core.TestCheckExitCode(0),
296297
core.TestCheckGolden(),
297298
func(t *testing.T, ctx *core.CheckFuncCtx) {
299+
t.Helper()
298300
res := ctx.Result.(*testAcceptMultiPositionalArgsType)
299301
assert.Len(t, res.NameIDs, 3)
300302
assert.Equal(t, "pos1", res.NameIDs[0])

internal/core/command_interceptor_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func Test_CombineCommandInterceptor(t *testing.T) {
2727

2828
run := func(tc *TestCase) func(t *testing.T) {
2929
return func(t *testing.T) {
30+
t.Helper()
3031
interceptor := core.CombineCommandInterceptor(tc.Interceptors...)
3132
res, _ := interceptor(nil, nil, runner)
3233
assert.Equal(t, tc.Expected, res)

0 commit comments

Comments
 (0)