mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-22 21:00:44 +00:00
configuration options for single rules can be set in config file
This commit is contained in:
parent
392aa9308d
commit
46d1e35ece
@ -10,7 +10,9 @@ from ansiblelater.utils.rulehelper import (get_normalized_tasks,
|
|||||||
|
|
||||||
def check_braces_spaces(candidate, settings):
|
def check_braces_spaces(candidate, settings):
|
||||||
yamllines, errors = get_normalized_yaml(candidate, settings)
|
yamllines, errors = get_normalized_yaml(candidate, settings)
|
||||||
description = "no suitable numbers of spaces (required: 1)"
|
conf = settings["ansible"]["double-braces"]
|
||||||
|
description = "no suitable numbers of spaces (min: {min} max: {max})".format(
|
||||||
|
min=conf["min-spaces-inside"], max=conf["max-spaces-inside"])
|
||||||
|
|
||||||
matches = []
|
matches = []
|
||||||
braces = re.compile("{{(.*?)}}")
|
braces = re.compile("{{(.*?)}}")
|
||||||
@ -23,9 +25,13 @@ def check_braces_spaces(candidate, settings):
|
|||||||
matches.append((i, item))
|
matches.append((i, item))
|
||||||
|
|
||||||
for i, line in matches:
|
for i, line in matches:
|
||||||
leading, trailing = count_spaces(line)
|
[leading, trailing] = count_spaces(line)
|
||||||
|
sum_spaces = leading + trailing
|
||||||
|
|
||||||
if not leading == 1 or not trailing == 1:
|
if (
|
||||||
|
(sum_spaces < conf["min-spaces-inside"] * 2)
|
||||||
|
or (sum_spaces > conf["min-spaces-inside"] * 2)
|
||||||
|
):
|
||||||
errors.append(Error(i, description))
|
errors.append(Error(i, description))
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
|
||||||
|
@ -44,32 +44,36 @@ def check_native_yaml(candidate, settings):
|
|||||||
|
|
||||||
|
|
||||||
def check_yaml_empty_lines(candidate, settings):
|
def check_yaml_empty_lines(candidate, settings):
|
||||||
options = "rules: {empty-lines: {max: 1, max-start: 0, max-end: 1}}"
|
options = "rules: {{empty-lines: {conf}}}".format(
|
||||||
errors = run_yamllint(candidate, settings, options)
|
conf=settings["yamllint"]["empty-lines"])
|
||||||
|
errors = run_yamllint(candidate.path, options)
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
|
||||||
|
|
||||||
def check_yaml_indent(candidate, settings):
|
def check_yaml_indent(candidate, settings):
|
||||||
options = "rules: {indentation: {spaces: 2, check-multi-line-strings: false, indent-sequences: true}}"
|
options = "rules: {{indentation: {conf}}}".format(
|
||||||
errors = run_yamllint(candidate, settings, options)
|
conf=settings["yamllint"]["indentation"])
|
||||||
|
errors = run_yamllint(candidate.path, options)
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
|
||||||
|
|
||||||
def check_yaml_hyphens(candidate, settings):
|
def check_yaml_hyphens(candidate, settings):
|
||||||
options = "rules: {hyphens: {max-spaces-after: 1}}"
|
options = "rules: {{hyphens: {conf}}}".format(
|
||||||
errors = run_yamllint(candidate, settings, options)
|
conf=settings["yamllint"]["hyphens"])
|
||||||
|
errors = run_yamllint(candidate.path, options)
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
|
||||||
|
|
||||||
def check_yaml_document_start(candidate, settings):
|
def check_yaml_document_start(candidate, settings):
|
||||||
options = "rules: {document-start: {present: true}}"
|
options = "rules: {{document-start: {conf}}}".format(
|
||||||
errors = run_yamllint(candidate, settings, options)
|
conf=settings["yamllint"]["document-start"])
|
||||||
|
errors = run_yamllint(candidate.path, options)
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
|
||||||
|
|
||||||
def check_yaml_colons(candidate, settings):
|
def check_yaml_colons(candidate, settings):
|
||||||
options = "rules: {colons: {max-spaces-before: 0, max-spaces-after: 1}}"
|
options = "rules: {{colons: {conf}}}"
|
||||||
errors = run_yamllint(candidate, settings, options)
|
errors = run_yamllint(candidate.path, options)
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,7 +103,33 @@ class Settings(object):
|
|||||||
},
|
},
|
||||||
"ansible": {
|
"ansible": {
|
||||||
"custom_modules": [],
|
"custom_modules": [],
|
||||||
}
|
"double-braces": {
|
||||||
|
"min-spaces-inside": 1,
|
||||||
|
"max-spaces-inside": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"yamllint": {
|
||||||
|
"empty-lines": {
|
||||||
|
"max": 1,
|
||||||
|
"max-start": 0,
|
||||||
|
"max-end": 1,
|
||||||
|
},
|
||||||
|
"indentation": {
|
||||||
|
"spaces": 2,
|
||||||
|
"check-multi-line-strings": False,
|
||||||
|
"indent-sequences": True,
|
||||||
|
},
|
||||||
|
"hyphens": {
|
||||||
|
"max-spaces-after": 1
|
||||||
|
},
|
||||||
|
"document-start": {
|
||||||
|
"present": True
|
||||||
|
},
|
||||||
|
"colons": {
|
||||||
|
"max-spaces-before": 0,
|
||||||
|
"max-spaces-after": 1
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
self.schema = anyconfig.gen_schema(defaults)
|
self.schema = anyconfig.gen_schema(defaults)
|
||||||
|
|
||||||
|
@ -121,10 +121,10 @@ def get_raw_yaml(candidate, settings):
|
|||||||
return content, errors
|
return content, errors
|
||||||
|
|
||||||
|
|
||||||
def run_yamllint(candidate, settings, options="extends: default"):
|
def run_yamllint(path, options="extends: default"):
|
||||||
errors = []
|
errors = []
|
||||||
try:
|
try:
|
||||||
with codecs.open(candidate.path, mode="rb", encoding="utf-8") as f:
|
with codecs.open(path, mode="rb", encoding="utf-8") as f:
|
||||||
for problem in linter.run(f, YamlLintConfig(options)):
|
for problem in linter.run(f, YamlLintConfig(options)):
|
||||||
errors.append(Error(problem.line, problem.desc))
|
errors.append(Error(problem.line, problem.desc))
|
||||||
except LaterError as ex:
|
except LaterError as ex:
|
||||||
|
Loading…
Reference in New Issue
Block a user