Skip to content

Commit

Permalink
review: add keys and delete zero values.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jan 6, 2021
1 parent db6956d commit c133cbc
Showing 1 changed file with 49 additions and 57 deletions.
106 changes: 49 additions & 57 deletions pkg/golinters/nolintlint/nolintlint_test.go
Expand Up @@ -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"},
},
},
{
Expand Down Expand Up @@ -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"},
},
},
{
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -144,7 +140,7 @@ func foo() {
good() // nolint: linter1, linter2
}`,
expected: []issueWithReplacement{
{"directive `// nolint:linter1 linter2` should match `// nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9", nil}, //nolint:lll // this is a string
{issue: "directive `// nolint:linter1 linter2` should match `// nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9"}, //nolint:lll // this is a string
},
},
{
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit c133cbc

Please sign in to comment.