diff mbox series

[v2,5/7] tests/style: check for commonly doubled up words

Message ID 20220704152303.760983-6-berrange@redhat.com
State New
Headers show
Series tests: introduce a tree-wide code style checking facility | expand

Commit Message

Daniel P. Berrangé July 4, 2022, 3:23 p.m. UTC
This style check looks for cases where the words

  the then in an on if is it but for or at and do to

are repeated in a sentence. It doesn't use the simple regex match logic
because it needs to match repeats across lines, so has a custom crafted
rule.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/style-excludes.mak | 12 ++++++++++++
 tests/style.mak          | 24 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
diff mbox series

Patch

diff --git a/tests/style-excludes.mak b/tests/style-excludes.mak
index 32c0e9c328..931dd03a64 100644
--- a/tests/style-excludes.mak
+++ b/tests/style-excludes.mak
@@ -2,3 +2,15 @@ 
 #
 # Filenames that should be excluded from specific
 # style checks performed by style.mak
+
+exclude_file_name_regexp--sc_prohibit_doubled_word = \
+	disas/sparc\.c \
+	hw/char/terminal3270\.c \
+	include/crypto/afsplit\.h \
+	qemu-options\.hx \
+	scripts/checkpatch\.pl \
+	target/s390x/tcg/insn-data\.def \
+	pc-bios/slof\.bin \
+	tests/qemu-iotests/142(\.out)? \
+	tests/qtest/arm-cpu-features\.c \
+	ui/cursor\.c
diff --git a/tests/style.mak b/tests/style.mak
index ae658395c9..4056bde619 100644
--- a/tests/style.mak
+++ b/tests/style.mak
@@ -28,3 +28,27 @@  sc_int_assign_bool:
 	@prohibit='\<int\>.*= *(true|false)\b' \
 	halt='use bool type for boolean values' \
 	$(_sc_search_regexp)
+
+prohibit_doubled_words_ = \
+    the then in an on if is it but for or at and do to can
+# expand the regex before running the check to avoid using expensive captures
+prohibit_doubled_word_expanded_ = \
+    $(join $(prohibit_doubled_words_),$(addprefix \s+,$(prohibit_doubled_words_)))
+prohibit_doubled_word_RE_ ?= \
+    /\b(?:$(subst $(_sp),|,$(prohibit_doubled_word_expanded_)))\b/gims
+prohibit_doubled_word_ =						\
+    -e 'while ($(prohibit_doubled_word_RE_))'				\
+    $(perl_filename_lineno_text_)
+
+# Define this to a regular expression that matches
+# any filename:dd:match lines you want to ignore.
+# The default is to ignore no matches.
+ignore_doubled_word_match_RE_ ?= ^$$
+
+sc_prohibit_doubled_word:
+	@$(VC_LIST_EXCEPT)						\
+	  | xargs perl -n -0777 $(prohibit_doubled_word_)		\
+	  | $(GREP) -vE '$(ignore_doubled_word_match_RE_)'		\
+	  | $(GREP) .							\
+	  && { echo '$(ME): doubled words' 1>&2; exit 1; }		\
+	  || :