From c133cbcf6b0d6f28be2605bbdc5c3907b2be3871 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 6 Jan 2021 12:57:16 +0100 Subject: [PATCH] review: add keys and delete zero values. --- pkg/golinters/nolintlint/nolintlint_test.go | 106 +++++++++----------- 1 file changed, 49 insertions(+), 57 deletions(-) diff --git a/pkg/golinters/nolintlint/nolintlint_test.go b/pkg/golinters/nolintlint/nolintlint_test.go index ad9554540584..8ff65c848952 100644 --- a/pkg/golinters/nolintlint/nolintlint_test.go +++ b/pkg/golinters/nolintlint/nolintlint_test.go @@ -40,10 +40,10 @@ func foo() { other() //nolintother }`, expected: []issueWithReplacement{ - {"directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:5:1", nil}, - {"directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:7:9", nil}, - {"directive `//nolint //` should provide explanation such as `//nolint // this is why` at testing.go:8:9", nil}, - {"directive `//nolint // ` should provide explanation such as `//nolint // this is why` at testing.go:9:9", nil}, + {issue: "directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:5:1"}, + {issue: "directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:7:9"}, + {issue: "directive `//nolint //` should provide explanation such as `//nolint // this is why` at testing.go:8:9"}, + {issue: "directive `//nolint // ` should provide explanation such as `//nolint // this is why` at testing.go:9:9"}, }, }, { @@ -83,8 +83,8 @@ func foo() { bad() // nolint // because }`, expected: []issueWithReplacement{ - {"directive `//nolint` should mention specific linter such as `//nolint:my-linter` at testing.go:6:9", nil}, - {"directive `// nolint // because` should mention specific linter such as `// nolint:my-linter` at testing.go:7:9", nil}, + {issue: "directive `//nolint` should mention specific linter such as `//nolint:my-linter` at testing.go:6:9"}, + {issue: "directive `// nolint // because` should mention specific linter such as `// nolint:my-linter` at testing.go:7:9"}, }, }, { @@ -97,18 +97,16 @@ func foo() { bad() // nolint good() //nolint }`, - expected: []issueWithReplacement{ - { - "directive `// nolint` should be written without leading space as `//nolint` at testing.go:5:9", - &result.Replacement{ - Inline: &result.InlineFix{ - StartCol: 10, - Length: 1, - NewString: "", - }, + expected: []issueWithReplacement{{ + issue: "directive `// nolint` should be written without leading space as `//nolint` at testing.go:5:9", + replacement: &result.Replacement{ + Inline: &result.InlineFix{ + StartCol: 10, + Length: 1, + NewString: "", }, }, - }, + }}, }, { desc: "extra spaces in front of directive are reported", @@ -119,18 +117,16 @@ func foo() { bad() // nolint good() // nolint }`, - expected: []issueWithReplacement{ - { - "directive `// nolint` should not have more than one leading space at testing.go:5:9", - &result.Replacement{ - Inline: &result.InlineFix{ - StartCol: 10, - Length: 2, - NewString: " ", - }, + expected: []issueWithReplacement{{ + issue: "directive `// nolint` should not have more than one leading space at testing.go:5:9", + replacement: &result.Replacement{ + Inline: &result.InlineFix{ + StartCol: 10, + Length: 2, + NewString: " ", }, }, - }, + }}, }, { desc: "spaces are allowed in comma-separated list of linters", @@ -144,7 +140,7 @@ func foo() { good() // nolint: linter1, linter2 }`, expected: []issueWithReplacement{ - {"directive `// nolint:linter1 linter2` should match `// nolint[:] [// ]` at testing.go:6:9", nil}, //nolint:lll // this is a string + {issue: "directive `// nolint:linter1 linter2` should match `// nolint[:] [// ]` at testing.go:6:9"}, //nolint:lll // this is a string }, }, { @@ -166,18 +162,16 @@ package bar func foo() { bad() //nolint }`, - expected: []issueWithReplacement{ - { - "directive `//nolint` is unused at testing.go:5:9", - &result.Replacement{ - Inline: &result.InlineFix{ - StartCol: 8, - Length: 8, - NewString: "", - }, + expected: []issueWithReplacement{{ + issue: "directive `//nolint` is unused at testing.go:5:9", + replacement: &result.Replacement{ + Inline: &result.InlineFix{ + StartCol: 8, + Length: 8, + NewString: "", }, }, - }, + }}, }, { desc: "needs unused with one specific linter generates replacement", @@ -188,18 +182,16 @@ package bar func foo() { bad() //nolint:somelinter }`, - expected: []issueWithReplacement{ - { - "directive `//nolint:somelinter` is unused for linter \"somelinter\" at testing.go:5:9", - &result.Replacement{ - Inline: &result.InlineFix{ - StartCol: 8, - Length: 19, - NewString: "", - }, + expected: []issueWithReplacement{{ + issue: "directive `//nolint:somelinter` is unused for linter \"somelinter\" at testing.go:5:9", + replacement: &result.Replacement{ + Inline: &result.InlineFix{ + StartCol: 8, + Length: 19, + NewString: "", }, }, - }, + }}, }, { desc: "needs unused with multiple specific linters generates a replacement for each linter", @@ -212,8 +204,8 @@ func foo() { }`, expected: []issueWithReplacement{ { - "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter1\" at testing.go:5:9", - &result.Replacement{ + issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter1\" at testing.go:5:9", + replacement: &result.Replacement{ Inline: &result.InlineFix{ StartCol: 17, Length: 8, @@ -222,8 +214,8 @@ func foo() { }, }, { - "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter2\" at testing.go:5:9", - &result.Replacement{ + issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter2\" at testing.go:5:9", + replacement: &result.Replacement{ Inline: &result.InlineFix{ StartCol: 25, Length: 8, @@ -232,8 +224,8 @@ func foo() { }, }, { - "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter3\" at testing.go:5:9", - &result.Replacement{ + issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter3\" at testing.go:5:9", + replacement: &result.Replacement{ Inline: &result.InlineFix{ StartCol: 33, Length: 7, @@ -254,8 +246,8 @@ func foo() { }`, expected: []issueWithReplacement{ { - "directive `//nolint:linter1, linter2` is unused for linter \"linter1\" at testing.go:5:10", - &result.Replacement{ + issue: "directive `//nolint:linter1, linter2` is unused for linter \"linter1\" at testing.go:5:10", + replacement: &result.Replacement{ Inline: &result.InlineFix{ StartCol: 18, Length: 8, @@ -264,8 +256,8 @@ func foo() { }, }, { - "directive `//nolint:linter1, linter2` is unused for linter \"linter2\" at testing.go:5:10", - &result.Replacement{ + issue: "directive `//nolint:linter1, linter2` is unused for linter \"linter2\" at testing.go:5:10", + replacement: &result.Replacement{ Inline: &result.InlineFix{ StartCol: 26, Length: 8,