Skip to content

Commit

Permalink
Rename messages to issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed May 15, 2020
1 parent ce8f52a commit eae25e3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
34 changes: 17 additions & 17 deletions godot.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

const noPeriodMessage = "Top level comment should end in a period"

// Message contains a message of linting error.
type Message struct {
// Issue contains a message of linting error.
type Issue struct {
Pos token.Position
Message string
}
Expand All @@ -38,43 +38,43 @@ var (
)

// Run runs this linter on the provided code.
func Run(file *ast.File, fset *token.FileSet, settings Settings) []Message {
msgs := []Message{}
func Run(file *ast.File, fset *token.FileSet, settings Settings) []Issue {
issues := []Issue{}

// Check all top-level comments
if settings.CheckAll {
for _, group := range file.Comments {
if ok, msg := check(fset, group); !ok {
msgs = append(msgs, msg)
if ok, iss := check(fset, group); !ok {
issues = append(issues, iss)
}
}
return msgs
return issues
}

// Check only declaration comments
for _, decl := range file.Decls {
switch d := decl.(type) {
case *ast.GenDecl:
if ok, msg := check(fset, d.Doc); !ok {
msgs = append(msgs, msg)
if ok, iss := check(fset, d.Doc); !ok {
issues = append(issues, iss)
}
case *ast.FuncDecl:
if ok, msg := check(fset, d.Doc); !ok {
msgs = append(msgs, msg)
if ok, iss := check(fset, d.Doc); !ok {
issues = append(issues, iss)
}
}
}
return msgs
return issues
}

func check(fset *token.FileSet, group *ast.CommentGroup) (ok bool, msg Message) {
func check(fset *token.FileSet, group *ast.CommentGroup) (ok bool, iss Issue) {
if group == nil || len(group.List) == 0 {
return true, Message{}
return true, Issue{}
}

// Check only top-level comments
if fset.Position(group.Pos()).Column > 1 {
return true, Message{}
return true, Issue{}
}

// Get last element from comment group - it can be either
Expand All @@ -84,11 +84,11 @@ func check(fset *token.FileSet, group *ast.CommentGroup) (ok bool, msg Message)

line, ok := checkComment(last.Text)
if ok {
return true, Message{}
return true, Issue{}
}
pos := fset.Position(last.Slash)
pos.Line += line
return false, Message{
return false, Issue{
Pos: pos,
Message: noPeriodMessage,
}
Expand Down
44 changes: 22 additions & 22 deletions godot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,16 @@ func TestIntegration(t *testing.T) {
t.Fatalf("Failed to parse file %s: %v", testFile, err)
}

msgs := Run(file, fset, Settings{CheckAll: false})
if len(msgs) != len(expected) {
t.Fatalf("Invalid number of result messages\n expected: %d\n got: %d",
len(expected), len(msgs))
issues := Run(file, fset, Settings{CheckAll: false})
if len(issues) != len(expected) {
t.Fatalf("Invalid number of result issues\n expected: %d\n got: %d",
len(expected), len(issues))
}
for i := range msgs {
if msgs[i].Pos.Filename != expected[i].Pos.Filename ||
msgs[i].Pos.Line != expected[i].Pos.Line {
for i := range issues {
if issues[i].Pos.Filename != expected[i].Pos.Filename ||
issues[i].Pos.Line != expected[i].Pos.Line {
t.Fatalf("Unexpected position\n expected %s\n got %s",
expected[i].Pos, msgs[i].Pos)
expected[i].Pos, issues[i].Pos)
}
}
})
Expand All @@ -272,34 +272,34 @@ func TestIntegration(t *testing.T) {
t.Fatalf("Failed to parse file %s: %v", testFile, err)
}

msgs := Run(file, fset, Settings{CheckAll: true})
if len(msgs) != len(expected) {
t.Fatalf("Invalid number of result messages\n expected: %d\n got: %d",
len(expected), len(msgs))
issues := Run(file, fset, Settings{CheckAll: true})
if len(issues) != len(expected) {
t.Fatalf("Invalid number of result issues\n expected: %d\n got: %d",
len(expected), len(issues))
}
for i := range msgs {
if msgs[i].Pos.Filename != expected[i].Pos.Filename ||
msgs[i].Pos.Line != expected[i].Pos.Line {
for i := range issues {
if issues[i].Pos.Filename != expected[i].Pos.Filename ||
issues[i].Pos.Line != expected[i].Pos.Line {
t.Fatalf("Unexpected position\n expected %d:%d\n got %d:%d",
expected[i].Pos.Line, expected[i].Pos.Column,
msgs[i].Pos.Line, msgs[i].Pos.Column,
issues[i].Pos.Line, issues[i].Pos.Column,
)
}
}
})
}

// readTestFile reads comments from file. If comment contains "PASS",
// it should not be among error messages. If comment contains "FAIL",
// it should be among error messages.
func readTestFile(file string) ([]Message, error) {
// it should not be among issues. If comment contains "FAIL", it should
// be among error issues.
func readTestFile(file string) ([]Issue, error) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, file, nil, parser.ParseComments)
if err != nil {
return nil, err
}

var msgs []Message
var issues []Issue
for _, group := range f.Comments {
if group == nil || len(group.List) == 0 {
continue
Expand All @@ -313,13 +313,13 @@ func readTestFile(file string) ([]Message, error) {
if strings.Contains(line, "FAIL") {
pos := fset.Position(com.Slash)
pos.Line += i
msgs = append(msgs, Message{
issues = append(issues, Issue{
Pos: pos,
Message: noPeriodMessage,
})
}
}
}
}
return msgs, nil
return issues, nil
}

0 comments on commit eae25e3

Please sign in to comment.