nolintlint: remove empty line in unused directive replacement (#4973)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
726b8153ca
commit
3797ed90c3
@ -252,12 +252,19 @@ func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) {
|
|||||||
|
|
||||||
// when detecting unused directives, we send all the directives through and filter them out in the nolint processor
|
// when detecting unused directives, we send all the directives through and filter them out in the nolint processor
|
||||||
if (l.needs & NeedsUnused) != 0 {
|
if (l.needs & NeedsUnused) != 0 {
|
||||||
removeNolintCompletely := &result.Replacement{
|
removeNolintCompletely := &result.Replacement{}
|
||||||
Inline: &result.InlineFix{
|
|
||||||
StartCol: pos.Column - 1,
|
startCol := pos.Column - 1
|
||||||
|
|
||||||
|
if startCol == 0 {
|
||||||
|
// if the directive starts from a new line, remove the line
|
||||||
|
removeNolintCompletely.NeedOnlyDelete = true
|
||||||
|
} else {
|
||||||
|
removeNolintCompletely.Inline = &result.InlineFix{
|
||||||
|
StartCol: startCol,
|
||||||
Length: end.Column - pos.Column,
|
Length: end.Column - pos.Column,
|
||||||
NewString: "",
|
NewString: "",
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(linters) == 0 {
|
if len(linters) == 0 {
|
||||||
|
@ -188,6 +188,25 @@ func foo() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "needs unused with one specific linter in a new line generates replacement",
|
||||||
|
needs: NeedsUnused,
|
||||||
|
contents: `
|
||||||
|
package bar
|
||||||
|
|
||||||
|
//nolint:somelinter
|
||||||
|
func foo() {
|
||||||
|
bad()
|
||||||
|
}`,
|
||||||
|
expected: []issueWithReplacement{
|
||||||
|
{
|
||||||
|
issue: "directive `//nolint:somelinter` is unused for linter \"somelinter\" at testing.go:4:1",
|
||||||
|
replacement: &result.Replacement{
|
||||||
|
NeedOnlyDelete: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "needs unused with multiple specific linters does not generate replacements",
|
desc: "needs unused with multiple specific linters does not generate replacements",
|
||||||
needs: NeedsUnused,
|
needs: NeedsUnused,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user