Skip to content

Commit

Permalink
Assume single whitespace was intended when multiple leading whitespac…
Browse files Browse the repository at this point in the history
…es are encountered
  • Loading branch information
ashanbrown committed Dec 28, 2020
1 parent 7c992af commit db6956d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
17 changes: 10 additions & 7 deletions pkg/golinters/nolintlint/nolintlint.go
Expand Up @@ -181,18 +181,21 @@ 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 {
removeWhitespace := &result.Replacement{
Inline: &result.InlineFix{
StartCol: pos.Column + 1,
Length: len(leadingSpace),
NewString: "",
},
}
if (l.needs & NeedsMachineOnly) != 0 {
issue := NotMachine{BaseIssue: base}
issue.BaseIssue.replacement = &result.Replacement{
Inline: &result.InlineFix{
StartCol: pos.Column - 1,
Length: len(leadingSpace) + 2,
NewString: "//",
},
}
issue.BaseIssue.replacement = removeWhitespace
issues = append(issues, issue)
} else if len(leadingSpace) > 1 {
issue := ExtraLeadingSpace{BaseIssue: base}
issue.BaseIssue.replacement = removeWhitespace
issue.BaseIssue.replacement.Inline.NewString = " " // assume a single space was intended
issues = append(issues, issue)
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/golinters/nolintlint/nolintlint_test.go
Expand Up @@ -102,9 +102,9 @@ func foo() {
"directive `// nolint` should be written without leading space as `//nolint` at testing.go:5:9",
&result.Replacement{
Inline: &result.InlineFix{
StartCol: 8,
Length: 3,
NewString: "//",
StartCol: 10,
Length: 1,
NewString: "",
},
},
},
Expand All @@ -124,9 +124,9 @@ func foo() {
"directive `// nolint` should not have more than one leading space at testing.go:5:9",
&result.Replacement{
Inline: &result.InlineFix{
StartCol: 8,
Length: 4,
NewString: "//",
StartCol: 10,
Length: 2,
NewString: " ",
},
},
},
Expand Down

0 comments on commit db6956d

Please sign in to comment.