From 7da98ef3494a25bb42d2798176f2185c70e0a8a7 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 6 Feb 2025 08:19:22 -0500 Subject: [PATCH] test: Rename the reflowed comments test to make it easier to find This makes running one-of executions of this a bit easier. --- test/.gitignore | 2 +- test/Makefile | 10 +++++----- ...{comment_parser.go => reflowed-comments.go} | 18 ++++++++++++++---- test/test-govet.sh | 3 ++- 4 files changed, 22 insertions(+), 11 deletions(-) rename test/{comment_parser.go => reflowed-comments.go} (92%) diff --git a/test/.gitignore b/test/.gitignore index c993889f..f9240613 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1 @@ -comment_parser +reflowed-comments diff --git a/test/Makefile b/test/Makefile index 869e1e54..c6efbc94 100644 --- a/test/Makefile +++ b/test/Makefile @@ -32,11 +32,11 @@ SHELL = /usr/bin/env bash all: build -build: comment_parser +build: reflowed-comments clean: - @rm -f comment_parser || true + @rm -f reflowed-comments || true -comment_parser: comment_parser.go - @echo "Generating: comment_parser..." - go build comment_parser.go +reflowed-comments: reflowed-comments.go + @echo "Generating: reflowed-comments..." + go build reflowed-comments.go diff --git a/test/comment_parser.go b/test/reflowed-comments.go similarity index 92% rename from test/comment_parser.go rename to test/reflowed-comments.go index 33dd84d3..925f7333 100644 --- a/test/comment_parser.go +++ b/test/reflowed-comments.go @@ -39,6 +39,10 @@ const ( // CommentPrefix is the prefix we look for at the beginning of comments. 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 = "//go:" @@ -149,14 +153,20 @@ func Check(filename string) error { break // skip to the end of this block } - if s != commentPrefixTrimmed && !strings.HasPrefix(s, CommentPrefix) { - return fmt.Errorf("location (%s) missing comment prefix", ident) + // Allow a comment prefix that starts with a space or + // 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 s = "" } - s = strings.TrimPrefix(s, CommentPrefix) + if strings.HasPrefix(s, CommentPrefix) { + s = strings.TrimPrefix(s, CommentPrefix) + } else if strings.HasPrefix(s, CommentPrefixTab) { + s = strings.TrimPrefix(s, CommentPrefixTab) + } block = append(block, s) } @@ -196,7 +206,7 @@ func IsWrappedProperly(lines []string, length int) error { blank = false 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 diff --git a/test/test-govet.sh b/test/test-govet.sh index cc878153..ad8a654a 100755 --- a/test/test-govet.sh +++ b/test/test-govet.sh @@ -122,7 +122,8 @@ function reflowed-comments() { return 0 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