2021-01-30 15:52:48 +00:00
|
|
|
from collections import defaultdict
|
|
|
|
|
2024-01-25 20:40:15 +00:00
|
|
|
from ansiblelater.rule import RuleBase
|
2021-01-30 15:52:48 +00:00
|
|
|
|
|
|
|
|
2024-01-25 20:40:15 +00:00
|
|
|
class CheckNameFormat(RuleBase):
|
2024-01-27 18:56:35 +00:00
|
|
|
rid = "ANS107"
|
2021-01-30 15:52:48 +00:00
|
|
|
description = "Name of tasks and handlers must be formatted"
|
2024-01-25 20:40:15 +00:00
|
|
|
helptext = "name `{name}` should start with uppercase"
|
2021-01-30 15:52:48 +00:00
|
|
|
types = ["playbook", "task", "handler"]
|
|
|
|
|
|
|
|
def check(self, candidate, settings):
|
|
|
|
tasks, errors = self.get_normalized_tasks(candidate, settings)
|
|
|
|
namelines = defaultdict(list)
|
|
|
|
|
|
|
|
if not errors:
|
|
|
|
for task in tasks:
|
|
|
|
if "name" in task:
|
|
|
|
namelines[task["name"]].append(task["__line__"])
|
2023-11-10 13:50:48 +00:00
|
|
|
for name, lines in namelines.items():
|
2021-01-30 15:52:48 +00:00
|
|
|
if name and not name[0].isupper():
|
|
|
|
errors.append(self.Error(lines[-1], self.helptext.format(name=name)))
|
|
|
|
|
|
|
|
return self.Result(candidate.path, errors)
|