mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-22 12:50:42 +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 " \
|
||||
"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("[=!]= ?[\"'][\"']")
|
||||
|
||||
if not errors:
|
||||
for i, line in yamllines:
|
||||
if empty_string_compare.findall(line):
|
||||
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` " \
|
||||
"(or conversely `when: not var`)"
|
||||
|
||||
if not errors:
|
||||
if isinstance(candidate, Template):
|
||||
matches = []
|
||||
braces = re.compile("({{|{%)(.*?)(}}|%})")
|
||||
jinja_string = re.compile("({{|{%)(.*?)(}}|%})")
|
||||
|
||||
for i, line in yamllines:
|
||||
match = braces.findall(line)
|
||||
match = jinja_string.findall(line)
|
||||
if match:
|
||||
for item in match:
|
||||
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)")
|
||||
|
||||
if not errors:
|
||||
for i, line in yamllines:
|
||||
if literal_bool_compare.findall(line):
|
||||
errors.append(Error(i, description))
|
||||
|
@ -1,3 +1,4 @@
|
||||
pydocstyle<4.0.0
|
||||
flake8
|
||||
flake8-colors
|
||||
flake8-blind-except
|
||||
|
Loading…
Reference in New Issue
Block a user