Skip to content

Commit 6e6f226

Browse files
committed
Add future warning if input variables are unreferenced
1 parent 65a8740 commit 6e6f226

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

pre_commit_hooks/check_autopkg_recipes.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,30 @@ def validate_no_superclass_procs(process, filename):
280280
return passed
281281

282282

283+
# def validate_unused_input_vars(recipe, recipe_text, filename):
284+
# """Warn if any input variables are not referenced in the recipe."""
285+
286+
# # List of variables that are commonly allowed to be unreferenced (lowercase).
287+
# ignored_vars = (
288+
# "name",
289+
# "pkginfo",
290+
# )
291+
292+
# passed = True
293+
# for input_var, _ in recipe.get("Input", {}).items():
294+
# if input_var.lower() in ignored_vars:
295+
# continue
296+
# subst = "%" + input_var + "%"
297+
# if subst not in recipe_text:
298+
# print(
299+
# "{}: WARNING: Input variable {} not referenced in recipe.".format(
300+
# filename, input_var
301+
# )
302+
# )
303+
304+
# return passed
305+
306+
283307
def validate_no_var_in_app_path(process, filename):
284308
"""Ensure %NAME% is not used in app paths that should be hard coded."""
285309

@@ -461,6 +485,9 @@ def main(argv=None):
461485
try:
462486
with open(filename, "rb") as openfile:
463487
recipe = plistlib.load(openfile)
488+
# For future implementation of validate_unused_input_vars()
489+
# with open(filename, "r") as openfile:
490+
# recipe_text = openfile.read()
464491

465492
except (ExpatError, ValueError) as err:
466493
print("{}: plist parsing error: {}".format(filename, err))
@@ -494,6 +521,13 @@ def main(argv=None):
494521
)
495522
retval = 1
496523

524+
# Validate that all input variables are used.
525+
# (Disabled for now because it's a little too opinionated, and doesn't take into account
526+
# whether environmental variables are used in custom processors.)
527+
# if args.strict:
528+
# if not validate_unused_input_vars(recipe, recipe_text, filename):
529+
# retval = 1
530+
497531
# If the Input key contains a pkginfo dict, make a best effort to validate its contents.
498532
input_key = recipe.get("Input", recipe.get("input", recipe.get("INPUT")))
499533
if input_key and "pkginfo" in input_key:

0 commit comments

Comments
 (0)