Skip to content

Commit f1d1bb5

Browse files
committed
review
1 parent d01272c commit f1d1bb5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pkg/golinters/nolintlint/internal/nolintlint.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,19 @@ func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) {
252252

253253
// when detecting unused directives, we send all the directives through and filter them out in the nolint processor
254254
if (l.needs & NeedsUnused) != 0 {
255-
removeNolintCompletely := &result.Replacement{
256-
Inline: &result.InlineFix{
257-
StartCol: pos.Column - 1,
255+
removeNolintCompletely := &result.Replacement{}
256+
257+
startCol := pos.Column - 1
258+
259+
if startCol == 0 {
260+
// if the directive starts from a new line, remove the line
261+
removeNolintCompletely.NeedOnlyDelete = true
262+
} else {
263+
removeNolintCompletely.Inline = &result.InlineFix{
264+
StartCol: startCol,
258265
Length: end.Column - pos.Column,
259266
NewString: "",
260-
},
261-
}
262-
// if the directive starts from a new line, remove the line
263-
if removeNolintCompletely.Inline.StartCol == 0 {
264-
removeNolintCompletely.NeedOnlyDelete = true
265-
removeNolintCompletely.Inline = nil
267+
}
266268
}
267269

268270
if len(linters) == 0 {

0 commit comments

Comments
 (0)