From 910a3b20064c3df2ae829ebc88315c50520b14fe Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 28 Jan 2019 19:26:41 +0100 Subject: [PATCH 1/2] Report missing or bad manifest arg type, or unecessary 'choices' usage --- package_linter.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/package_linter.py b/package_linter.py index a76e4a1..20333ee 100755 --- a/package_linter.py +++ b/package_linter.py @@ -231,13 +231,20 @@ def check_manifest(path): print_warning("[YEP-2.1]" + service + " service may not exist") if "install" in manifest["arguments"]: - types = ("domain", "path", "password", "user", "admin") - for nbr, typ in enumerate(types): - for install_arg in manifest["arguments"]["install"]: - if typ == install_arg["name"]: - if "type" not in install_arg: - print_wrong("[YEP-2.1] You should specify the type of the key with %s" % (typ)) + recognized_types = ("domain", "path", "boolean", "app", "password", "user", "string") + + for argument in manifest["arguments"]["install"]: + if not "type" in argument.keys(): + print_wrong("[YEP-2.1] You should specify the type of the argument '%s'. You can use : %s." % (argument["name"], ', '.join(recognized_types))) + elif argument["type"] not in recognized_types: + print_warning("[YEP-2.1] The type '%s' for argument '%s' is not recognized... it probably doesn't behave as you expect ? Choose among those instead : %s" % (argument["type"], argument["name"], ', '.join(recognized_types))) + + if "choices" in argument.keys(): + choices = [ c.lower() for c in argument["choices"] ] + if len(choices) == 2: + if ("true" in choices and "false" in choices) or ("yes" in choices and "no" in choices): + print_warning("Argument %s : you might want to simply use a boolean-type argument. No need to specify the choices list yourself." % argument["name"]) From 20a280e2d22a5640cffe20137d3af469db18902b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 7 Feb 2019 15:47:38 +0100 Subject: [PATCH 2/2] print_wrong -> print_error --- package_linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package_linter.py b/package_linter.py index 20333ee..699638a 100755 --- a/package_linter.py +++ b/package_linter.py @@ -236,7 +236,7 @@ def check_manifest(path): for argument in manifest["arguments"]["install"]: if not "type" in argument.keys(): - print_wrong("[YEP-2.1] You should specify the type of the argument '%s'. You can use : %s." % (argument["name"], ', '.join(recognized_types))) + print_error("[YEP-2.1] You should specify the type of the argument '%s'. You can use : %s." % (argument["name"], ', '.join(recognized_types))) elif argument["type"] not in recognized_types: print_warning("[YEP-2.1] The type '%s' for argument '%s' is not recognized... it probably doesn't behave as you expect ? Choose among those instead : %s" % (argument["type"], argument["name"], ', '.join(recognized_types)))