mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-22 21:00:44 +00:00
include only jinja2 strings if candidate is a template
This commit is contained in:
parent
842b6b96c8
commit
7e924af87b
@ -179,9 +179,21 @@ def check_empty_string_compare(candidate, settings):
|
|||||||
description = "use `when: var` rather than `when: var != ""` (or " \
|
description = "use `when: var` rather than `when: var != ""` (or " \
|
||||||
"conversely `when: not var` rather than `when: var == ""`)"
|
"conversely `when: not var` rather than `when: var == ""`)"
|
||||||
|
|
||||||
|
if not errors:
|
||||||
|
if isinstance(candidate, Template):
|
||||||
|
matches = []
|
||||||
|
jinja_string = re.compile("({{|{%)(.*?)(}}|%})")
|
||||||
|
|
||||||
|
for i, line in yamllines:
|
||||||
|
match = jinja_string.findall(line)
|
||||||
|
if match:
|
||||||
|
for item in match:
|
||||||
|
matches.append((i, item[1]))
|
||||||
|
|
||||||
|
yamllines = matches
|
||||||
|
|
||||||
empty_string_compare = re.compile("[=!]= ?[\"'][\"']")
|
empty_string_compare = re.compile("[=!]= ?[\"'][\"']")
|
||||||
|
|
||||||
if not errors:
|
|
||||||
for i, line in yamllines:
|
for i, line in yamllines:
|
||||||
if empty_string_compare.findall(line):
|
if empty_string_compare.findall(line):
|
||||||
errors.append(Error(i, description))
|
errors.append(Error(i, description))
|
||||||
@ -194,12 +206,13 @@ def check_compare_to_literal_bool(candidate, settings):
|
|||||||
description = "use `when: var` rather than `when: var == True` " \
|
description = "use `when: var` rather than `when: var == True` " \
|
||||||
"(or conversely `when: not var`)"
|
"(or conversely `when: not var`)"
|
||||||
|
|
||||||
|
if not errors:
|
||||||
if isinstance(candidate, Template):
|
if isinstance(candidate, Template):
|
||||||
matches = []
|
matches = []
|
||||||
braces = re.compile("({{|{%)(.*?)(}}|%})")
|
jinja_string = re.compile("({{|{%)(.*?)(}}|%})")
|
||||||
|
|
||||||
for i, line in yamllines:
|
for i, line in yamllines:
|
||||||
match = braces.findall(line)
|
match = jinja_string.findall(line)
|
||||||
if match:
|
if match:
|
||||||
for item in match:
|
for item in match:
|
||||||
matches.append((i, item[1]))
|
matches.append((i, item[1]))
|
||||||
@ -208,7 +221,6 @@ def check_compare_to_literal_bool(candidate, settings):
|
|||||||
|
|
||||||
literal_bool_compare = re.compile("[=!]= ?(True|true|False|false)")
|
literal_bool_compare = re.compile("[=!]= ?(True|true|False|false)")
|
||||||
|
|
||||||
if not errors:
|
|
||||||
for i, line in yamllines:
|
for i, line in yamllines:
|
||||||
if literal_bool_compare.findall(line):
|
if literal_bool_compare.findall(line):
|
||||||
errors.append(Error(i, description))
|
errors.append(Error(i, description))
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
pydocstyle<4.0.0
|
||||||
flake8
|
flake8
|
||||||
flake8-colors
|
flake8-colors
|
||||||
flake8-blind-except
|
flake8-blind-except
|
||||||
|
Loading…
Reference in New Issue
Block a user