summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2010-04-10 14:19:11 +0200
committerJim Meyering <meyering@redhat.com>2010-04-10 20:26:39 +0200
commit8c4b6ba09be4eb3e7b2373a4b2d6c908c0836eaa (patch)
treeb6b5b7161f2c35389972d2f8c67aa2bea3928b12
parentac6feeb9f226247a53ab5b6c3aa24e40caabdc40 (diff)
downloadcoreutils-8c4b6ba09be4eb3e7b2373a4b2d6c908c0836eaa.tar.xz
maint: new syntax-check rule: prohibit empty lines at EOF
* cfg.mk (detect_empty_lines_at_EOF_): Define. (sc_prohibit_empty_lines_at_EOF): New rule. * .x-sc_prohibit_empty_lines_at_EOF: New file. Exempt pr test inputs. * Makefile.am (syntax_check_exceptions): Add it. Pádraig Brady suggested to parse the output of tail -n1.
-rw-r--r--.x-sc_prohibit_empty_lines_at_EOF1
-rw-r--r--Makefile.am1
-rw-r--r--cfg.mk24
3 files changed, 26 insertions, 0 deletions
diff --git a/.x-sc_prohibit_empty_lines_at_EOF b/.x-sc_prohibit_empty_lines_at_EOF
new file mode 100644
index 000000000..92571d699
--- /dev/null
+++ b/.x-sc_prohibit_empty_lines_at_EOF
@@ -0,0 +1 @@
+^tests/pr/
diff --git a/Makefile.am b/Makefile.am
index 1eb9c12c9..9a7f45c66 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -47,6 +47,7 @@ syntax_check_exceptions = \
.x-sc_po_check \
.x-sc_program_name \
.x-sc_prohibit_atoi_atof \
+ .x-sc_prohibit_empty_lines_at_EOF \
.x-sc_prohibit_fail_0 \
.x-sc_prohibit_magic_number_exit \
.x-sc_prohibit_stat_st_blocks \
diff --git a/cfg.mk b/cfg.mk
index 75ce77af6..dfc3b86a4 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -315,6 +315,30 @@ sc_space_before_open_paren:
else :; \
fi
+# The following tail+perl pipeline would be much more concise, and would
+# produce slightly better output (including counts) if written as
+# perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ...
+# but that would be far less efficient, reading the entire contents
+# of each file, rather than just the last few bytes of each.
+#
+# This is a perl script that operates on the output of
+# tail -n1 TWO_OR_MORE_FILES
+# Print the name of each file that ends in two or more newline bytes.
+# Exit nonzero if at least one such file is found, otherwise, exit 0.
+#
+# Use this if you want to remove trailing empty lines from selected files:
+# perl -pi -0777 -e 's/\n\n+$/\n/' files...
+#
+detect_empty_lines_at_EOF_ = \
+ /^==> ([^\n]+) <==\n\n/m and (print "$$1\n"), $$fail = 1; \
+ END { exit defined $$fail }
+
+sc_prohibit_empty_lines_at_EOF:
+ @tail -n1 $$($(VC_LIST_EXCEPT)) /dev/null \
+ | perl -00 -ne '$(detect_empty_lines_at_EOF_)' \
+ || { echo '$(ME): the above files end with empty line(s)' \
+ 1>&2; exit 1; } || :; \
+
include $(srcdir)/dist-check.mk
update-copyright-env = \