From 7c992afc3684e36353f4ebf469118e1a2e5c9bf8 Mon Sep 17 00:00:00 2001 From: "Andrew S. Brown" Date: Sun, 27 Dec 2020 11:41:31 -0800 Subject: [PATCH] Don't try to remove leading whitespace when machine-readability isn't required It isn't possible to determine what the whitespace convention is otherwise. Fixes #1580. --- pkg/golinters/nolintlint/nolintlint.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pkg/golinters/nolintlint/nolintlint.go b/pkg/golinters/nolintlint/nolintlint.go index 1389dd31c433..4a1d8d61cb36 100644 --- a/pkg/golinters/nolintlint/nolintlint.go +++ b/pkg/golinters/nolintlint/nolintlint.go @@ -181,21 +181,18 @@ func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) { // check for, report and eliminate leading spaces so we can check for other issues if len(leadingSpace) > 0 { - machineReadableReplacement := &result.Replacement{ - Inline: &result.InlineFix{ - StartCol: pos.Column - 1, - Length: len(leadingSpace) + 2, - NewString: "//", - }, - } - if (l.needs & NeedsMachineOnly) != 0 { issue := NotMachine{BaseIssue: base} - issue.BaseIssue.replacement = machineReadableReplacement + issue.BaseIssue.replacement = &result.Replacement{ + Inline: &result.InlineFix{ + StartCol: pos.Column - 1, + Length: len(leadingSpace) + 2, + NewString: "//", + }, + } issues = append(issues, issue) } else if len(leadingSpace) > 1 { issue := ExtraLeadingSpace{BaseIssue: base} - issue.BaseIssue.replacement = machineReadableReplacement issues = append(issues, issue) } }