validate-modules: new module: fail if 'type' isn't documented

Don't require 'type' when:
- parameter name starts with an underscore
pull/57867/head
Pierre-Louis Bonicoli 5 years ago committed by Matt Clay
parent 8d635a82a4
commit c289006e05

@ -129,6 +129,8 @@ Errors
334 ``ANSIBLE_METADATA`` cannot be changed in a point release for a stable branch
335 argument_spec implies type="str" but documentation defines it as different data type
336 argument in argument_spec is not a valid python identifier
337 Type value is defined in ``argument_spec`` but documentation doesn't specify a type
338 documentation doesn't specify a type but argument in ``argument_spec`` use default type (``str``)
..
--------- -------------------
**4xx** **Syntax**

@ -1245,8 +1245,16 @@ class ModuleValidator(Validator):
# TODO: needs to recursively traverse suboptions
doc_type = docs.get('options', {}).get(arg, {}).get('type')
if 'type' in data:
if data['type'] != doc_type and doc_type is not None:
if 'type' in data and data['type'] is not None:
if doc_type is None:
if not arg.startswith('_'): # hidden parameter, for example _raw_params
self.reporter.error(
path=self.object_path,
code=337,
msg="Argument '%s' in argument_spec defines type as %r "
"but documentation doesn't define type" % (arg, data['type'])
)
elif data['type'] != doc_type:
self.reporter.error(
path=self.object_path,
code=325,
@ -1254,7 +1262,14 @@ class ModuleValidator(Validator):
"but documentation defines type as %r" % (arg, data['type'], doc_type)
)
else:
if doc_type != 'str' and doc_type is not None:
if doc_type is None:
self.reporter.error(
path=self.object_path,
code=338,
msg="Argument '%s' in argument_spec uses default type ('str') "
"but documentation doesn't define type" % (arg)
)
elif doc_type != 'str':
self.reporter.error(
path=self.object_path,
code=335,

Loading…
Cancel
Save