Skip to content

Commit

Permalink
Don't try to remove leading whitespace when machine-readability isn't…
Browse files Browse the repository at this point in the history
… required

It isn't possible to determine what the whitespace convention is otherwise.

Fixes #1580.
  • Loading branch information
ashanbrown committed Dec 27, 2020
1 parent e5a3018 commit 7c992af
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkg/golinters/nolintlint/nolintlint.go
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 7c992af

Please sign in to comment.