mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-25 22:30:42 +00:00
init line counter with 1
This commit is contained in:
parent
b6126758a5
commit
e4f305bbff
@ -3,6 +3,7 @@ import os
|
|||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from ansiblelater import Result, Error
|
from ansiblelater import Result, Error
|
||||||
|
from ansiblelater.utils import count_spaces
|
||||||
from ansiblelater.utils.rulehelper import (get_normalized_tasks,
|
from ansiblelater.utils.rulehelper import (get_normalized_tasks,
|
||||||
get_normalized_yaml)
|
get_normalized_yaml)
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ 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)"
|
description = "no suitable numbers of spaces (required: 1)"
|
||||||
|
|
||||||
lineno = 0
|
lineno = 1
|
||||||
matches = []
|
matches = []
|
||||||
braces = re.compile("{{(.*?)}}")
|
braces = re.compile("{{(.*?)}}")
|
||||||
|
|
||||||
@ -24,29 +25,9 @@ def check_braces_spaces(candidate, settings):
|
|||||||
matches.append((item, lineno))
|
matches.append((item, lineno))
|
||||||
|
|
||||||
for item, lineno in matches:
|
for item, lineno in matches:
|
||||||
error_count = 0
|
leading, trailing = count_spaces(item)
|
||||||
string_length = len(item)
|
|
||||||
strip_length = item.rstrip()
|
|
||||||
|
|
||||||
if strip_length == 0 and not string_length == 1:
|
if not leading == 1 or not trailing == 1:
|
||||||
error_count += 1
|
|
||||||
else:
|
|
||||||
x = 0
|
|
||||||
leading_spaces = 0
|
|
||||||
while (x < string_length - 1 and item[x].isspace()):
|
|
||||||
x += 1
|
|
||||||
leading_spaces += 1
|
|
||||||
|
|
||||||
x = string_length - 1
|
|
||||||
trailing_spaces = 0
|
|
||||||
while (x > 0 and item[x].isspace()):
|
|
||||||
x -= 1
|
|
||||||
trailing_spaces += 1
|
|
||||||
|
|
||||||
if not leading_spaces == 1 or not trailing_spaces == 1:
|
|
||||||
error_count += 1
|
|
||||||
|
|
||||||
if not error_count == 0:
|
|
||||||
errors.append(Error(lineno, description))
|
errors.append(Error(lineno, description))
|
||||||
return Result(candidate.path, errors)
|
return Result(candidate.path, errors)
|
||||||
|
|
||||||
|
@ -41,6 +41,23 @@ def info(message, settings, file=sys.stdout):
|
|||||||
print(stringc("INFO: %s" % message, 'green'), file=file)
|
print(stringc("INFO: %s" % message, 'green'), file=file)
|
||||||
|
|
||||||
|
|
||||||
|
def count_spaces(c_string):
|
||||||
|
leading_spaces = 0
|
||||||
|
trailing_spaces = 0
|
||||||
|
|
||||||
|
for i, e in enumerate(c_string):
|
||||||
|
if not e.isspace():
|
||||||
|
break
|
||||||
|
leading_spaces += 1
|
||||||
|
|
||||||
|
for i, e in reversed(list(enumerate(c_string))):
|
||||||
|
if not e.isspace():
|
||||||
|
break
|
||||||
|
trailing_spaces += 1
|
||||||
|
|
||||||
|
return((leading_spaces, trailing_spaces))
|
||||||
|
|
||||||
|
|
||||||
def get_property(prop):
|
def get_property(prop):
|
||||||
currentdir = os.path.dirname(os.path.realpath(__file__))
|
currentdir = os.path.dirname(os.path.realpath(__file__))
|
||||||
parentdir = os.path.dirname(currentdir)
|
parentdir = os.path.dirname(currentdir)
|
||||||
|
Loading…
Reference in New Issue
Block a user