Skip to content

Commit 7c992af

Browse files
committed
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.
1 parent e5a3018 commit 7c992af

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

pkg/golinters/nolintlint/nolintlint.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,18 @@ func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) {
181181

182182
// check for, report and eliminate leading spaces so we can check for other issues
183183
if len(leadingSpace) > 0 {
184-
machineReadableReplacement := &result.Replacement{
185-
Inline: &result.InlineFix{
186-
StartCol: pos.Column - 1,
187-
Length: len(leadingSpace) + 2,
188-
NewString: "//",
189-
},
190-
}
191-
192184
if (l.needs & NeedsMachineOnly) != 0 {
193185
issue := NotMachine{BaseIssue: base}
194-
issue.BaseIssue.replacement = machineReadableReplacement
186+
issue.BaseIssue.replacement = &result.Replacement{
187+
Inline: &result.InlineFix{
188+
StartCol: pos.Column - 1,
189+
Length: len(leadingSpace) + 2,
190+
NewString: "//",
191+
},
192+
}
195193
issues = append(issues, issue)
196194
} else if len(leadingSpace) > 1 {
197195
issue := ExtraLeadingSpace{BaseIssue: base}
198-
issue.BaseIssue.replacement = machineReadableReplacement
199196
issues = append(issues, issue)
200197
}
201198
}

0 commit comments

Comments
 (0)