bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] maint: new syntax-check rule: prohibit empty lines at EOF


From: Jim Meyering
Subject: Re: [PATCH] maint: new syntax-check rule: prohibit empty lines at EOF
Date: Sat, 10 Apr 2010 22:44:16 +0200

Jim Meyering wrote:

> Jim Meyering wrote:
>> Pádraig Brady wrote:
>>> On 10/04/10 13:53, Jim Meyering wrote:
>>>> Here's a rule I'm adding to coreutils' cfg.mk.
>>>> However, I would like to use it several other projects,
>>>> so rather than duplicating it in each, I'm thinking of
>>>> putting it in gnulib's maint.mk.
>>>>
>>>> Opinions?
>>>>
>>>> I know that at least Bruno likes to retain trailing empty
>>>> lines in modules/ files.  But for a class of files like that,
>>>> it's easy to exempt "^modules/" or to omit the rule altogether.
>>>>
>>>> Does anyone object to my adding this syntax check to maint.mk?
>>>>
>>>> Aside from that, can anyone improve on the code?
>>>> The multi-line Perl script is the only way I could get
>>>> the efficiency I wanted, but there may well be another
>>>> more concise way.
>>>
>>> Maybe something like this?
>>> tail -n1 files... | sed -n 's/==> \(.*\) <==/\1/; t blanks;d; :blanks 
>>> h;n;/^ *$/{x;p};'
>>> Though that won't work on solaris for example.
>>
>> Good idea to parse tail output.
>> This floats my boat:
>>
>>   tail -n1 ... | perl -00 -ne '/^==> ([^\n]+) <==\n\n/m and print "$1\n"'
>>
>> Several of the syntax-check rules already rely on perl,
>> and since this would search only version-controlled files,
>> we should be safe in assuming no name includes a newline.
>
> I added the code to make it produce the exit status we need:

Here's what I've pushed to gnulib.

>From 4e5f703a24180a7c058ebb5d7557ca2113877aa4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 10 Apr 2010 22:36:37 +0200
Subject: [PATCH] maint.mk: new syntax-check rule: prohibit empty lines at end 
of file

* top/maint.mk (sc_prohibit_empty_lines_at_EOF): New rule.
---
 ChangeLog    |    3 +++
 top/maint.mk |   23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e66d23e..c128892 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2010-04-10  Jim Meyering  <address@hidden>

+       maint.mk: new syntax-check rule: prohibit empty lines at end of file
+       * top/maint.mk (sc_prohibit_empty_lines_at_EOF): New rule.
+
        maint.mk: correct a diagnostic
        * top/maint.mk (sc_prohibit_HAVE_MBRTOWC): Fix obsolete use of $re
        in diagnostic; now use $prohibit.
diff --git a/top/maint.mk b/top/maint.mk
index df8e150..6bfb4c1 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -659,6 +659,29 @@ sc_prohibit_cvs_keyword:
        halt='do not use CVS keyword expansion'                         \
          $(_sc_search_regexp)

+# The following tail+perl pipeline would be 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; } || :;                                   \
+
 # Make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
 # This is a bit of a kludge, since it prevents use of the string
 # even in comments, but for now it does the job with no false positives.
--
1.7.1.rc0.264.g94f6e




reply via email to

[Prev in Thread] Current Thread [Next in Thread]