Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PositionFor instead of Position #7

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (v *visitor) Visit(node ast.Node) ast.Visitor {
startMsg := checkStart(v.fset, stmt.Lbrace, first)

if wantNewline && startMsg == nil {
v.messages = append(v.messages, Message{v.fset.Position(stmt.Pos()), MessageTypeAddAfter, `multi-line statement should be followed by a newline`})
v.messages = append(v.messages, Message{v.fset.PositionFor(stmt.Pos(), false), MessageTypeAddAfter, `multi-line statement should be followed by a newline`})
} else if !wantNewline && startMsg != nil {
v.messages = append(v.messages, *startMsg)
}
Expand All @@ -106,7 +106,7 @@ func checkMultiLine(v *visitor, body *ast.BlockStmt, stmtStart ast.Node) {
}

func posLine(fset *token.FileSet, pos token.Pos) int {
return fset.Position(pos).Line
return fset.PositionFor(pos, false).Line
}

func firstAndLast(comments []*ast.CommentGroup, fset *token.FileSet, start, end token.Pos, stmts []ast.Stmt) (ast.Node, ast.Node) {
Expand Down Expand Up @@ -141,7 +141,7 @@ func checkStart(fset *token.FileSet, start token.Pos, first ast.Node) *Message {
}

if posLine(fset, start)+1 < posLine(fset, first.Pos()) {
pos := fset.Position(start)
pos := fset.PositionFor(start, false)
return &Message{pos, MessageTypeLeading, `unnecessary leading newline`}
}

Expand All @@ -154,7 +154,7 @@ func checkEnd(fset *token.FileSet, end token.Pos, last ast.Node) *Message {
}

if posLine(fset, end)-1 > posLine(fset, last.End()) {
pos := fset.Position(end)
pos := fset.PositionFor(end, false)
return &Message{pos, MessageTypeTrailing, `unnecessary trailing newline`}
}

Expand Down