mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-25 22:30:42 +00:00
Merge pull request #31 from xoxys/fix-rule-taskseparation
trigger missing task separation check only for real task names
This commit is contained in:
commit
d39fbea56f
@ -5,6 +5,7 @@ from collections import defaultdict
|
|||||||
|
|
||||||
from ansiblelater.command.candidates import Error
|
from ansiblelater.command.candidates import Error
|
||||||
from ansiblelater.command.candidates import Result
|
from ansiblelater.command.candidates import Result
|
||||||
|
from ansiblelater.utils.rulehelper import get_normalized_tasks
|
||||||
from ansiblelater.utils.rulehelper import get_normalized_yaml
|
from ansiblelater.utils.rulehelper import get_normalized_yaml
|
||||||
|
|
||||||
|
|
||||||
@ -13,20 +14,28 @@ def check_line_between_tasks(candidate, settings):
|
|||||||
options.update(remove_empty=False)
|
options.update(remove_empty=False)
|
||||||
options.update(remove_markers=False)
|
options.update(remove_markers=False)
|
||||||
|
|
||||||
lines, errors = get_normalized_yaml(candidate, settings, options)
|
lines, line_errors = get_normalized_yaml(candidate, settings, options)
|
||||||
|
tasks, task_errors = get_normalized_tasks(candidate, settings)
|
||||||
description = "missing task separation (required: 1 empty line)"
|
description = "missing task separation (required: 1 empty line)"
|
||||||
|
|
||||||
task_regex = re.compile(r"-\sname:.*")
|
task_regex = re.compile(r"-\sname:(.*)")
|
||||||
prevline = "#file_start_marker"
|
prevline = "#file_start_marker"
|
||||||
|
|
||||||
allowed_prevline = ["---", "tasks:", "pre_tasks:", "post_tasks:", "block:"]
|
allowed_prevline = ["---", "tasks:", "pre_tasks:", "post_tasks:", "block:"]
|
||||||
|
|
||||||
|
errors = task_errors + line_errors
|
||||||
if not errors:
|
if not errors:
|
||||||
for i, line in lines:
|
for i, line in lines:
|
||||||
match = task_regex.search(line)
|
match = task_regex.search(line)
|
||||||
if match and prevline:
|
if match and prevline:
|
||||||
|
name = match.group(1).strip()
|
||||||
|
|
||||||
|
if not any(task.get("name") == name for task in tasks):
|
||||||
|
continue
|
||||||
|
|
||||||
if not any(item in prevline for item in allowed_prevline):
|
if not any(item in prevline for item in allowed_prevline):
|
||||||
errors.append(Error(i, description))
|
errors.append(Error(i, description))
|
||||||
|
|
||||||
prevline = line.strip()
|
prevline = line.strip()
|
||||||
|
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
Loading…
Reference in New Issue
Block a user