test: Rename the reflowed comments test to make it easier to find
This makes running one-of executions of this a bit easier.
This commit is contained in:
2
test/.gitignore
vendored
2
test/.gitignore
vendored
@@ -1 +1 @@
|
|||||||
comment_parser
|
reflowed-comments
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ SHELL = /usr/bin/env bash
|
|||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
build: comment_parser
|
build: reflowed-comments
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -f comment_parser || true
|
@rm -f reflowed-comments || true
|
||||||
|
|
||||||
comment_parser: comment_parser.go
|
reflowed-comments: reflowed-comments.go
|
||||||
@echo "Generating: comment_parser..."
|
@echo "Generating: reflowed-comments..."
|
||||||
go build comment_parser.go
|
go build reflowed-comments.go
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ const (
|
|||||||
// CommentPrefix is the prefix we look for at the beginning of comments.
|
// CommentPrefix is the prefix we look for at the beginning of comments.
|
||||||
CommentPrefix = "// "
|
CommentPrefix = "// "
|
||||||
|
|
||||||
|
// CommentPrefixTab is the prefix we look for at the beginning of
|
||||||
|
// comments when we have a tab instead of a space.
|
||||||
|
CommentPrefixTab = "//\t"
|
||||||
|
|
||||||
// CommentGolangPrefix is the magic golang prefix that tools use.
|
// CommentGolangPrefix is the magic golang prefix that tools use.
|
||||||
CommentGolangPrefix = "//go:"
|
CommentGolangPrefix = "//go:"
|
||||||
|
|
||||||
@@ -149,14 +153,20 @@ func Check(filename string) error {
|
|||||||
break // skip to the end of this block
|
break // skip to the end of this block
|
||||||
}
|
}
|
||||||
|
|
||||||
if s != commentPrefixTrimmed && !strings.HasPrefix(s, CommentPrefix) {
|
// Allow a comment prefix that starts with a space or
|
||||||
return fmt.Errorf("location (%s) missing comment prefix", ident)
|
// one that starts with a tab. (Common for code blocks!)
|
||||||
|
if s != commentPrefixTrimmed && !strings.HasPrefix(s, CommentPrefix) && !strings.HasPrefix(s, CommentPrefixTab) {
|
||||||
|
return fmt.Errorf("location (%s) missing comment prefix, has: %s", ident, s)
|
||||||
}
|
}
|
||||||
if s == commentPrefixTrimmed { // blank lines
|
if s == commentPrefixTrimmed { // blank lines
|
||||||
s = ""
|
s = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(s, CommentPrefix) {
|
||||||
s = strings.TrimPrefix(s, CommentPrefix)
|
s = strings.TrimPrefix(s, CommentPrefix)
|
||||||
|
} else if strings.HasPrefix(s, CommentPrefixTab) {
|
||||||
|
s = strings.TrimPrefix(s, CommentPrefixTab)
|
||||||
|
}
|
||||||
|
|
||||||
block = append(block, s)
|
block = append(block, s)
|
||||||
}
|
}
|
||||||
@@ -196,7 +206,7 @@ func IsWrappedProperly(lines []string, length int) error {
|
|||||||
blank = false
|
blank = false
|
||||||
|
|
||||||
if line != strings.TrimSpace(line) {
|
if line != strings.TrimSpace(line) {
|
||||||
return fmt.Errorf("line %d wasn't trimmed properly", lineno)
|
return fmt.Errorf("line %d wasn't trimmed properly: %s", lineno, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(line, " ") { // double spaces
|
if strings.Contains(line, " ") { // double spaces
|
||||||
@@ -122,7 +122,8 @@ function reflowed-comments() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./test/comment_parser "$1"
|
# Name this to match the function so it's easy to run this by itself.
|
||||||
|
./test/reflowed-comments "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# run go vet on a per-package basis
|
# run go vet on a per-package basis
|
||||||
|
|||||||
Reference in New Issue
Block a user