diff --git a/pkg/golinters/nolintlint/internal/nolintlint.go b/pkg/golinters/nolintlint/internal/nolintlint.go index c0134fd84fc2..45c925e1a5d2 100644 --- a/pkg/golinters/nolintlint/internal/nolintlint.go +++ b/pkg/golinters/nolintlint/internal/nolintlint.go @@ -252,17 +252,17 @@ 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 if (l.needs & NeedsUnused) != 0 { - removeNolintCompletely := &result.Replacement{ - Inline: &result.InlineFix{ + removeNolintCompletely := &result.Replacement{} + + if removeNolintCompletely.Inline.StartCol == 0 { + // if the directive starts from a new line, remove the line + removeNolintCompletely.NeedOnlyDelete = true + } else { + removeNolintCompletely.Inline = &result.InlineFix{ StartCol: pos.Column - 1, Length: end.Column - pos.Column, NewString: "", - }, - } - // if the directive starts from a new line, remove the line - if removeNolintCompletely.Inline.StartCol == 0 { - removeNolintCompletely.NeedOnlyDelete = true - removeNolintCompletely.Inline = nil + } } if len(linters) == 0 {