summaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authorFelix Fontein <felix@fontein.de>2024-07-06 01:35:54 +0200
committerGitHub <noreply@github.com>2024-07-06 01:35:54 +0200
commite5309ba29f5898e95ffe104412782c990858aaa0 (patch)
tree72c91b5498a24652ca35f90e2aa1c97b2cae5013 /test/lib
parentpackage_facts: fix warning logic (#83520) (diff)
downloadansible-e5309ba29f5898e95ffe104412782c990858aaa0.tar.xz
ansible-e5309ba29f5898e95ffe104412782c990858aaa0.zip
validate-modules: reject option/alias names equal up to casing belonging to different options (#83530)
* Reject option/alias names equal up to casing belonging to different options. * Update test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py
index ddfb8ca72d..990076e5bc 100644
--- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py
+++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py
@@ -838,6 +838,46 @@ class ModuleValidator(Validator):
msg='%s: %s' % (combined_path, error_message)
)
+ def _validate_option_docs(self, options, context=None):
+ if not isinstance(options, dict):
+ return
+ if context is None:
+ context = []
+
+ normalized_option_alias_names = dict()
+
+ def add_option_alias_name(name, option_name):
+ normalized_name = str(name).lower()
+ normalized_option_alias_names.setdefault(normalized_name, {}).setdefault(option_name, set()).add(name)
+
+ for option, data in options.items():
+ if 'suboptions' in data:
+ self._validate_option_docs(data.get('suboptions'), context + [option])
+ add_option_alias_name(option, option)
+ if 'aliases' in data and isinstance(data['aliases'], list):
+ for alias in data['aliases']:
+ add_option_alias_name(alias, option)
+
+ for normalized_name, options in normalized_option_alias_names.items():
+ if len(options) < 2:
+ continue
+
+ what = []
+ for option_name, names in sorted(options.items()):
+ if option_name in names:
+ what.append("option '%s'" % option_name)
+ else:
+ what.append("alias '%s' of option '%s'" % (sorted(names)[0], option_name))
+ msg = "Multiple options/aliases"
+ if context:
+ msg += " found in %s" % " -> ".join(context)
+ msg += " are equal up to casing: %s" % ", ".join(what)
+ self.reporter.error(
+ path=self.object_path,
+ code='option-equal-up-to-casing',
+ msg=msg,
+ )
+
def _validate_docs(self):
doc = None
# We have three ways of marking deprecated/removed files. Have to check each one
@@ -1015,6 +1055,9 @@ class ModuleValidator(Validator):
'invalid-documentation',
)
+ if doc:
+ self._validate_option_docs(doc.get('options'))
+
self._validate_all_semantic_markup(doc, returns)
if not self.collection: