mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-22 21:00:44 +00:00
reactor lin number handling for yaml files
This commit is contained in:
parent
0c88cfb7c2
commit
51c5f43e5c
@ -21,6 +21,7 @@ from ansiblelater.rules.ansiblefiles import check_shell_instead_command
|
|||||||
from ansiblelater.rules.ansiblefiles import check_command_has_changes
|
from ansiblelater.rules.ansiblefiles import check_command_has_changes
|
||||||
from ansiblelater.rules.ansiblefiles import check_empty_string_compare
|
from ansiblelater.rules.ansiblefiles import check_empty_string_compare
|
||||||
from ansiblelater.rules.ansiblefiles import check_compare_to_literal_bool
|
from ansiblelater.rules.ansiblefiles import check_compare_to_literal_bool
|
||||||
|
from ansiblelater.rules.ansiblefiles import check_uppercase_literal_bool
|
||||||
|
|
||||||
|
|
||||||
tasks_should_be_separated = Standard(dict(
|
tasks_should_be_separated = Standard(dict(
|
||||||
@ -195,6 +196,14 @@ use_yaml_rather_than_key_value = Standard(dict(
|
|||||||
types=["playbook", "task", "handler"]
|
types=["playbook", "task", "handler"]
|
||||||
))
|
))
|
||||||
|
|
||||||
|
literal_bool_should_start_with_uppercase = Standard(dict(
|
||||||
|
id="LINT0008",
|
||||||
|
name="Literal bools should start with a capital letter",
|
||||||
|
check=check_uppercase_literal_bool,
|
||||||
|
version="0.1",
|
||||||
|
types=["playbook", "task", "handler"]
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
ansible_min_version = '2.1'
|
ansible_min_version = '2.1'
|
||||||
ansible_review_min_version = '0.1.0'
|
ansible_review_min_version = '0.1.0'
|
||||||
@ -215,6 +224,7 @@ standards = [
|
|||||||
commands_should_be_idempotent,
|
commands_should_be_idempotent,
|
||||||
dont_compare_to_empty_string,
|
dont_compare_to_empty_string,
|
||||||
dont_compare_to_literal_bool,
|
dont_compare_to_literal_bool,
|
||||||
|
literal_bool_should_start_with_uppercase,
|
||||||
# Lint
|
# Lint
|
||||||
files_should_not_contain_unnecessarily_empty_lines,
|
files_should_not_contain_unnecessarily_empty_lines,
|
||||||
files_should_be_indented,
|
files_should_be_indented,
|
||||||
|
@ -209,3 +209,19 @@ def check_delegate_to_localhost(candidate, settings):
|
|||||||
errors.append(Error(task["__line__"], description))
|
errors.append(Error(task["__line__"], description))
|
||||||
|
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
|
||||||
|
|
||||||
|
def check_uppercase_literal_bool(candidate, settings):
|
||||||
|
yamllines, errors = get_normalized_yaml(candidate, settings)
|
||||||
|
description = "literal bools should be written as 'True|False' instead of 'true|false'"
|
||||||
|
|
||||||
|
lineno = 1
|
||||||
|
uppercase_bool = re.compile(r"([=!]=|:)\s*(true|false)")
|
||||||
|
|
||||||
|
if not errors:
|
||||||
|
for line in yamllines:
|
||||||
|
lineno += 1
|
||||||
|
if uppercase_bool.findall(line):
|
||||||
|
errors.append(Error(lineno, description))
|
||||||
|
|
||||||
|
return Result(candidate.path, errors)
|
||||||
|
@ -486,23 +486,25 @@ def parse_yaml_linenumbers(data, filename):
|
|||||||
|
|
||||||
|
|
||||||
def normalized_yaml(file, options):
|
def normalized_yaml(file, options):
|
||||||
lines = []
|
# lines = []
|
||||||
removes = []
|
removes = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with codecs.open(file, mode='rb', encoding='utf-8') as f:
|
with codecs.open(file, mode='rb', encoding='utf-8') as f:
|
||||||
lines = f.readlines()
|
lines = enumerate(f.readlines())
|
||||||
for line in lines:
|
print(lines)
|
||||||
if line.strip().startswith("#"):
|
for i, line in lines:
|
||||||
removes.append(line)
|
if line.strip().startswith("#"):
|
||||||
# remove document starter also
|
removes.append(line)
|
||||||
if options.get("remove_markers") and line.strip() == "---":
|
# remove document starter also
|
||||||
removes.append(line)
|
if options.get("remove_markers") and line.strip() == "---":
|
||||||
# remove empty lines
|
removes.append(line)
|
||||||
if options.get("remove_empty") and not line.strip():
|
# remove empty lines
|
||||||
removes.append(line)
|
if options.get("remove_empty") and not line.strip():
|
||||||
for line in removes:
|
removes.append(line)
|
||||||
lines.remove(line)
|
|
||||||
|
# for line in removes:
|
||||||
|
# lines.remove(line)
|
||||||
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as e:
|
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as e:
|
||||||
raise LaterError("syntax error", e)
|
raise LaterError("syntax error", e)
|
||||||
return lines
|
return lines
|
||||||
|
Loading…
Reference in New Issue
Block a user