Skip to content

Commit

Permalink
make: add lint-model for sanity checking
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Aug 31, 2023
1 parent 2caee07 commit 7f99c40
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Mk/plugins.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2022 Franco Fichtner <[email protected]>
# Copyright (c) 2015-2023 Franco Fichtner <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -313,6 +313,27 @@ lint-xml:
@find ${.CURDIR}/src \
-name "*.xml" -type f -print0 | xargs -0 -n1 xmllint --noout

lint-model:
# XXX "default" must be changed to upper case "Default"
@if [ -d ${.CURDIR}/src/opnsense/mvc/app/models ]; then for MODEL in $$(find ${.CURDIR}/src/opnsense/mvc/app/models -depth 3 \
-name "*.xml"); do \
(xmllint $${MODEL} --xpath '//*[@type and not(@type="ArrayField") and (not(Required) or Required="N") and default]' 2> /dev/null | grep '^<' || true) | while read LINE; do \
echo "$${MODEL}: $${LINE} has a spurious default value set"; \
done; \
(xmllint $${MODEL} --xpath '//*[@type and not(@type="ArrayField") and default=""]' 2> /dev/null | grep '^<' || true) | while read LINE; do \
echo "$${MODEL}: $${LINE} has an empty default value set"; \
done; \
(xmllint $${MODEL} --xpath '//*[@type and not(@type="ArrayField") and BlankDesc="None"]' 2> /dev/null | grep '^<' || true) | while read LINE; do \
echo "$${MODEL}: $${LINE} blank description is the default"; \
done; \
(xmllint $${MODEL} --xpath '//*[@type and not(@type="ArrayField") and BlankDesc and Required="Y"]' 2> /dev/null | grep '^<' || true) | while read LINE; do \
echo "$${MODEL}: $${LINE} blank description not applicable on required field"; \
done; \
(xmllint $${MODEL} --xpath '//*[@type and not(@type="ArrayField") and BlankDesc and Multiple="Y"]' 2> /dev/null | grep '^<' || true) | while read LINE; do \
echo "$${MODEL}: $${LINE} blank description not applicable on multiple field"; \
done; \
done; fi

lint-exec: check
.for DIR in ${.CURDIR}/src/opnsense/scripts ${.CURDIR}/src/etc/rc.d ${.CURDIR}/src/etc/rc.syshook.d
.if exists(${DIR})
Expand All @@ -337,7 +358,7 @@ lint-php: check
-type f -print0 | xargs -0 -n1 php -l
.endif

lint: lint-desc lint-shell lint-xml lint-exec lint-php
lint: lint-desc lint-shell lint-xml lint-model lint-exec lint-php

sweep: check
find ${.CURDIR}/src -type f -name "*.map" -print0 | \
Expand Down

0 comments on commit 7f99c40

Please sign in to comment.