add new check check_yaml_document_end

This commit is contained in:
Robert Kaussow 2019-10-16 00:31:25 +02:00
parent 5651c9fa8a
commit 36bc78d1fd
3 changed files with 20 additions and 0 deletions

View File

@ -24,6 +24,7 @@ from ansiblelater.rules.yamlfiles import check_yaml_file
from ansiblelater.rules.yamlfiles import check_yaml_has_content from ansiblelater.rules.yamlfiles import check_yaml_has_content
from ansiblelater.rules.yamlfiles import check_yaml_hyphens from ansiblelater.rules.yamlfiles import check_yaml_hyphens
from ansiblelater.rules.yamlfiles import check_yaml_indent from ansiblelater.rules.yamlfiles import check_yaml_indent
from ansiblelater.rules.yamlfiles import check_yaml_document_end
from ansiblelater.standard import Standard from ansiblelater.standard import Standard
tasks_should_be_separated = Standard(dict( tasks_should_be_separated = Standard(dict(
@ -224,6 +225,14 @@ use_yaml_rather_than_key_value = Standard(dict(
types=["playbook", "task", "handler"] types=["playbook", "task", "handler"]
)) ))
files_should_contain_document_end_marker = Standard(dict(
id="LINT0009",
name="YAML should contain document end marker",
check=check_yaml_document_end,
version="0.1",
types=["playbook", "task", "handler", "rolevars",
"hostvars", "groupvars", "meta"]
))
ansible_min_version = "2.5" ansible_min_version = "2.5"
ansible_later_min_version = "0.2.0" ansible_later_min_version = "0.2.0"
@ -256,4 +265,5 @@ standards = [
rolesfile_should_be_in_yaml, rolesfile_should_be_in_yaml,
files_should_not_be_purposeless, files_should_not_be_purposeless,
use_yaml_rather_than_key_value, use_yaml_rather_than_key_value,
files_should_contain_document_end_marker,
] ]

View File

@ -75,6 +75,13 @@ def check_yaml_document_start(candidate, settings):
return Result(candidate.path, errors) return Result(candidate.path, errors)
def check_yaml_document_end(candidate, settings):
options = "rules: {{document-end: {conf}}}".format(
conf=settings["yamllint"]["document-end"])
errors = run_yamllint(candidate.path, options)
return Result(candidate.path, errors)
def check_yaml_colons(candidate, settings): def check_yaml_colons(candidate, settings):
options = "rules: {{colons: {conf}}}".format( options = "rules: {{colons: {conf}}}".format(
conf=settings["yamllint"]["colons"]) conf=settings["yamllint"]["colons"])

View File

@ -127,6 +127,9 @@ class Settings(object):
"document-start": { "document-start": {
"present": True "present": True
}, },
"document-end": {
"present": True
},
"colons": { "colons": {
"max-spaces-before": 0, "max-spaces-before": 0,
"max-spaces-after": 1 "max-spaces-after": 1