[stable-2.10] Fix yamllint sanity test line numbers.
Parse errors from libyaml now compensate for the offset of the documentation within a module.
(cherry picked from commit 1a0d8a51cd
)
Co-authored-by: Matt Clay <matt@mystile.com>
This commit is contained in:
parent
8cd66ce95a
commit
a707466c0b
2 changed files with 6 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- ansible-test - Report the correct line number in the ``yamllint`` sanity test when reporting ``libyaml`` parse errors in module documentation.
|
|
@ -119,16 +119,17 @@ class YamlChecker:
|
||||||
yaml_data = yaml_data[1:]
|
yaml_data = yaml_data[1:]
|
||||||
lineno += 1
|
lineno += 1
|
||||||
|
|
||||||
self.check_parsable(path, yaml_data)
|
self.check_parsable(path, yaml_data, lineno)
|
||||||
|
|
||||||
messages = list(linter.run(yaml_data, conf, path))
|
messages = list(linter.run(yaml_data, conf, path))
|
||||||
|
|
||||||
self.messages += [self.result_to_message(r, path, lineno - 1, key) for r in messages]
|
self.messages += [self.result_to_message(r, path, lineno - 1, key) for r in messages]
|
||||||
|
|
||||||
def check_parsable(self, path, contents):
|
def check_parsable(self, path, contents, lineno=1):
|
||||||
"""
|
"""
|
||||||
:type path: str
|
:type path: str
|
||||||
:type contents: str
|
:type contents: str
|
||||||
|
:type lineno: int
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
yaml.load(contents, Loader=TestLoader)
|
yaml.load(contents, Loader=TestLoader)
|
||||||
|
@ -136,7 +137,7 @@ class YamlChecker:
|
||||||
self.messages += [{'code': 'unparsable-with-libyaml',
|
self.messages += [{'code': 'unparsable-with-libyaml',
|
||||||
'message': '%s - %s' % (e.args[0], e.args[2]),
|
'message': '%s - %s' % (e.args[0], e.args[2]),
|
||||||
'path': path,
|
'path': path,
|
||||||
'line': e.problem_mark.line + 1,
|
'line': e.problem_mark.line + lineno,
|
||||||
'column': e.problem_mark.column + 1,
|
'column': e.problem_mark.column + 1,
|
||||||
'level': 'error',
|
'level': 'error',
|
||||||
}]
|
}]
|
||||||
|
|
Loading…
Reference in a new issue