diff mbox series

[v2,4/6] tests: add linter check for pipe placement style

Message ID e4b548c65e93e5de70e043114a9a54bdc25160d4.1537223021.git.matvore@google.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/6] CodingGuidelines: add shell piping guidelines | expand

Commit Message

Matthew DeVore Sept. 17, 2018, 10:24 p.m. UTC
---
 t/Makefile | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/t/Makefile b/t/Makefile
index c83fd1886..4eceabbd5 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -78,7 +78,7 @@  check-chainlint:
 	done && exit $$err
 
 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
-	test-lint-filenames
+	test-lint-filenames test-lint-pipes
 
 test-lint-duplicates:
 	@dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
@@ -101,6 +101,16 @@  test-lint-filenames:
 		test -z "$$bad" || { \
 		echo >&2 "non-portable file name(s): $$bad"; exit 1; }
 
+test-lint-pipes:
+	@# Do not use \ to join lines when the next line starts with a
+	@# pipe. Instead, end the prior line with the pipe, and allow that to
+	@# join the lines implicitly.
+	@bad="$$(${PERL_PATH} -n0e 'm/(\n[^\n|]+\\\n[\t ]+\|[^\n]*)/ and \
+	      print qq{$$ARGV:$$1\n\n}' $(T))"; \
+		test -z "$$bad" || { \
+		printf >&2 "pipe at start of line in file(s):\n%s\n" "$$bad"; \
+		exit 1; }
+
 aggregate-results-and-cleanup: $(T)
 	$(MAKE) aggregate-results
 	$(MAKE) clean