Most instances of ;; in C code are mistakes, where the second semicolon is a no-op. This rule tries to make it easy to flag the typos occuring at the end of a statement. It intentionally does not flag for(;;) loops, and misses grammar problems in comments if the problem occurs in the middle of the line.
Shell files (including configure.ac and Makefile.am, which can contain shell snippets) are too likely to use case statements where ;; is legitimate, so those are not scanned. * top/maint.mk (sc_prohibit_double_semicolon): New rule. Signed-off-by: Eric Blake <ebl...@redhat.com> --- I think this regex captures the earlier discussion on balancing between false positives vs. avoiding false negatives. Thoughts before I push it? ChangeLog | 3 +++ top/maint.mk | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index dc88544..e2aa0a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2014-09-04 Eric Blake <ebl...@redhat.com> + maintainer-makefile: add syntax check for useless ';;' + * top/maint.mk (sc_prohibit_double_semicolon): New rule. + error: drop spurious semicolon * lib/error.c (__error_at_line): Fix ';;'. diff --git a/top/maint.mk b/top/maint.mk index e5a3782..2aa2219 100644 --- a/top/maint.mk +++ b/top/maint.mk @@ -996,6 +996,14 @@ sc_prohibit_undesirable_word_seq: | grep -vE '$(ignore_undesirable_word_sequence_RE_)' | grep . \ && { echo '$(ME): undesirable word sequence' >&2; exit 1; } || : +# Except for shell files and for loops, double semicolon is probably a mistake +sc_prohibit_double_semicolon: + @prohibit='; *;[ {} \]*(/[/*]|$$)' \ + in_vc_files='\.[chly]$$' \ + exclude='for *\(.*\)' \ + halt="Double semicolon detected" \ + $(_sc_search_regexp) + _ptm1 = use "test C1 && test C2", not "test C1 -''a C2" _ptm2 = use "test C1 || test C2", not "test C1 -''o C2" # Using test's -a and -o operators is not portable. -- 1.9.3