From 8417372e911d7d7f6d350847ed15ed48d080c768 Mon Sep 17 00:00:00 2001
From: Patrick Baudin <patrick.baudin@cea.fr>
Date: Thu, 16 Jun 2022 13:18:09 +0200
Subject: [PATCH] [Lint] using generic rules as much as possible

---
 share/Makefile.linting | 88 +++++++++++-------------------------------
 1 file changed, 22 insertions(+), 66 deletions(-)

diff --git a/share/Makefile.linting b/share/Makefile.linting
index a74db03be30..6e802df4558 100644
--- a/share/Makefile.linting
+++ b/share/Makefile.linting
@@ -128,28 +128,19 @@ endif
 .PHONY: clean-lint
 clean-lint:
 	echo "Cleaning LINT targets..."
-	$(RM) -r .lint
+	rm -rf .lint
 
 clean:: clean-lint
 
-.PHONY: clean-check-eoleof
-clean-check-eoleof:
-	echo "Cleaning LINT $(patsubst clean-%,%,$@) targets..."
-	find .lint -type f -name \*.$(patsubst clean-%,%,$@) | xargs -n 10 $(RM)
+#### clean-check-XXX targets
 
-.PHONY: clean-check-utf8
-clean-check-utf8:
-	echo "Cleaning LINT $(patsubst clean-%,%,$@) targets..."
-	find .lint -type f -name \*.$(patsubst clean-%,%,$@) | xargs -n 10 $(RM)
+LINT.clean-targets= \
+        clean-check-eoleof clean-check-utf8 clean-check-syntax clean-check-ident
+.PHONY: clean-check-eoleof clean-check-utf8 clean-check-syntax clean-check-ident
 
-.PHONY: clean-check-syntax
-clean-check-syntax:
-	echo "Cleaning LINT $(patsubst clean-%,%,$@) targets..."
-	find .lint -type f -name \*.$(patsubst clean-%,%,$@) | xargs -n 10 $(RM)
-
-.PHONY: clean-check-ident
-clean-check-indent:
-	echo "Cleaning LINT $(patsubst clean-%,%,$@) targets..."
+# Generic rule
+$(LINT.clean-targets):
+	echo "[LINT] Cleaning $(patsubst clean-%,%,$@) targets..."
 	find .lint -type f -name \*.$(patsubst clean-%,%,$@) | xargs -n 10 $(RM)
 
 ###############################
@@ -160,69 +151,34 @@ ifeq ($(LINT_FILE),)
 
 LINT.dir=$(wildcard $(LINT_DIR))
 
-.PHONY: check-utf8
-check-utf8:
-	echo "Checking UTF8..."
-	$(GIT) ls-files $(LINT.dir) -z \
-        | $(GIT) check-attr --stdin -z $@ \
-        | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
-        | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
+#### check-XXX targets
 
-.PHONY: fix-utf8
-fix-utf8:
-	echo "Fixing UTF8..."
-	$(GIT) ls-files $(LINT.dir) -z \
-        | $(GIT) check-attr --stdin -z $(patsubst fix-%,check-%,$@) \
-        | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
-        | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
+LINT.check-targets= \
+        check-syntax check-indent check-eoleof check-utf8
+.PHONY: check-syntax check-indent check-eoleof check-utf8
 
-.PHONY: check-eoleof
-check-eoleof:
-	echo "Checking EOL EOF..."
+# Generic rule
+$(LINT.check-targets):
+	echo "[LINT] Checking from GIT attribute $@..."
 	$(GIT) ls-files $(LINT.dir) -z \
         | $(GIT) check-attr --stdin -z $@ \
         | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
         | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
 
-.PHONY: fix-eoleof
-fix-eoleof:
-	echo "Fixing EOL EOF..."
-	$(GIT) ls-files $(LINT.dir) -z \
-        | $(GIT) check-attr --stdin -z $(patsubst fix-%,check-%,$@) \
-        | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
-        | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
+#### fix-XXX targets
 
-.PHONY: check-syntax
-check-syntax:
-	echo "Checking syntax..."
-	$(GIT) ls-files $(LINT.dir) -z \
-        | $(GIT) check-attr --stdin -z $@ \
-        | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
-        | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
+LINT.fix-targets= \
+        fix-eoleof fix-utf8 fix-syntax fix-ident
+.PHONY: fix-eoleof fix-utf8 fix-syntax fix-ident
 
-.PHONY: fix-syntax
-fix-syntax:
-	echo "Fixing syntax..."
+# Generic rule
+$(LINT.fix-targets):
+	echo "[LINT] Fixing from GIT attribute $(patsubst fix-%,check-%,$@)..."
 	$(GIT) ls-files $(LINT.dir) -z \
         | $(GIT) check-attr --stdin -z $(patsubst fix-%,check-%,$@) \
         | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
         | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
 
-.PHONY: check-indent
-check-indent:
-	echo "Checking indent..."
-	$(GIT) ls-files $(LINT.dir) -z \
-        | $(GIT) check-attr --stdin -z $@ \
-        | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
-        | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
-
-.PHONY: fix-indent
-fix-indent:
-	echo "Fixing indent..."
-	$(GIT) ls-files $(LINT.dir) -z \
-        | $(GIT) check-attr --stdin -z $(patsubs fix-,check-,$@) \
-        | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
-        | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
 
 else # LINT_FILE are given
 
-- 
GitLab