]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
share/mk/: lint-man-dash: Diagnose unescaped dashes
authorAlejandro Colomar <alx@kernel.org>
Mon, 22 Sep 2025 21:28:33 +0000 (23:28 +0200)
committerAlejandro Colomar <alx@kernel.org>
Thu, 25 Sep 2025 09:13:55 +0000 (11:13 +0200)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
share/mk/lint/man/_.mk
share/mk/lint/man/dash.mk [new file with mode: 0644]
share/mk/lint/man/dash.pcre2grep [new file with mode: 0644]

index ba25943d899cdc51763a8f1fdabd94a61125af79..850f0330237b6f14874983b3164fd03a9bb0628f 100644 (file)
@@ -9,6 +9,7 @@ MAKEFILE_LINT_MAN_INCLUDED := 1
 .PHONY: lint-man
 lint-man: \
        lint-man-blank \
+       lint-man-dash \
        lint-man-mandoc \
        lint-man-poems \
        lint-man-quote \
diff --git a/share/mk/lint/man/dash.mk b/share/mk/lint/man/dash.mk
new file mode 100644 (file)
index 0000000..6573b6d
--- /dev/null
@@ -0,0 +1,49 @@
+# Copyright, the authors of the Linux man-pages project
+# SPDX-License-Identifier: LGPL-3.0-only WITH LGPL-3.0-linking-exception
+
+
+ifndef MAKEFILE_LINT_MAN_DASH_INCLUDED
+MAKEFILE_LINT_MAN_DASH_INCLUDED := 1
+
+
+include $(MAKEFILEDIR)/build/man/nonso.mk
+include $(MAKEFILEDIR)/configure/build-depends/awk/awk.mk
+include $(MAKEFILEDIR)/configure/build-depends/coreutils/cat.mk
+include $(MAKEFILEDIR)/configure/build-depends/coreutils/echo.mk
+include $(MAKEFILEDIR)/configure/build-depends/coreutils/touch.mk
+include $(MAKEFILEDIR)/configure/build-depends/pcre2-utils/pcre2grep.mk
+include $(MAKEFILEDIR)/configure/build-depends/sed/sed.mk
+
+
+ext := .lint-man.dash.touch
+regexf := $(MAKEFILEDIR)/lint/man/dash.pcre2grep
+
+tgts := $(patsubst %, %$(ext), $(_NONSO))
+
+
+$(tgts): %$(ext): % $(regexf) $(MK) | $$(@D)/
+       $(info  $(INFO_)PCRE2GREP       $@)
+       $(CAT) <$< \
+       | if $(PCRE2GREP) -f '$(filter %.pcre2grep, $^)' >/dev/null; then \
+               >&2 $(ECHO) "lint-man-dash: $<: Unescaped dash:"; \
+               $(PCRE2GREP) -n -f '$(filter %.pcre2grep, $^)' <$< \
+               | $(SED) -E 's/([^:]+:)(.*)/\1\n\t\2/' \
+               | $(AWK) -F: \
+                       '/^[^\t]/{ printf("%7d:", $$1); }; \
+                        /^\t/{ print($$0); };' \
+               >&2; \
+               exit 1; \
+       fi;
+       $(TOUCH) $@
+
+
+.PHONY: lint-man-dash
+lint-man-dash: $(tgts);
+
+
+undefine ext
+undefine regexf
+undefine tgts
+
+
+endif  # include guard
diff --git a/share/mk/lint/man/dash.pcre2grep b/share/mk/lint/man/dash.pcre2grep
new file mode 100644 (file)
index 0000000..1ab6926
--- /dev/null
@@ -0,0 +1,4 @@
+^[^.](?:(?!\\").)* --*[[:alnum:]]
+^\.(BI|IB|BR|RB|IR|RI|SS|B|I|UR|MT|MR|SY)\b(?:(?!\\").)*~--*[[:alnum:]]
+^(?:(?!\\").)*\(--*[[:alnum:]]
+^(?:(?!\\").)*[,=] --*[[:alnum:]]