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 " \
|
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 == ""`)"
|
||||||
|
|
||||||
empty_string_compare = re.compile("[=!]= ?[\"'][\"']")
|
|
||||||
|
|
||||||
if not errors:
|
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("[=!]= ?[\"'][\"']")
|
||||||
|
|
||||||
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,21 +206,21 @@ 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 isinstance(candidate, Template):
|
|
||||||
matches = []
|
|
||||||
braces = re.compile("({{|{%)(.*?)(}}|%})")
|
|
||||||
|
|
||||||
for i, line in yamllines:
|
|
||||||
match = braces.findall(line)
|
|
||||||
if match:
|
|
||||||
for item in match:
|
|
||||||
matches.append((i, item[1]))
|
|
||||||
|
|
||||||
yamllines = matches
|
|
||||||
|
|
||||||
literal_bool_compare = re.compile("[=!]= ?(True|true|False|false)")
|
|
||||||
|
|
||||||
if not errors:
|
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
|
||||||
|
|
||||||
|
literal_bool_compare = re.compile("[=!]= ?(True|true|False|false)")
|
||||||
|
|
||||||
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