Skip to content

Commit

Permalink
staticcheck: fix incorrect range on suggested edit
Browse files Browse the repository at this point in the history
Signed-off-by: sourya <souryavatsyayan@gmail.com>
Closes: gh-867 [via git-merge-pr]
Closes gh-866
  • Loading branch information
sourya authored and dominikh committed Nov 15, 2020
1 parent d0bdcc7 commit 6054ba0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions staticcheck/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3381,6 +3381,9 @@ func CheckMissingEnumTypesInDeclaration(pass *analysis.Pass) (interface{}, error
for _, spec := range group[1:] {
nspec := *spec.(*ast.ValueSpec)
nspec.Type = typ
// The position of `spec` node excludes comments (if any).
// However, on generating the source back from the node, the comments are included. Setting `Comment` to nil ensures deduplication of comments.
nspec.Comment = nil
edits = append(edits, edit.ReplaceWithNode(pass.Fset, spec, &nspec))
}
report.Report(pass, group[0], "only the first constant in this group has an explicit type", report.Fixes(edit.Fix("add type to all constants in group", edits...)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (

const (
c6 int = 1 // want `only the first constant in this group has an explicit type`
c7 = 2
c7 = 2 // comment for testing https://github.com/dominikh/go-tools/issues/866
c8 = 3
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (

const (
c6 int = 1 // want `only the first constant in this group has an explicit type`
c7 int = 2
c7 int = 2 // comment for testing https://github.com/dominikh/go-tools/issues/866
c8 int = 3
)

Expand Down

0 comments on commit 6054ba0

Please sign in to comment.