Repository: roaldnefs/salt-lint

Issue:
Fix whitespace control in Jinja rules
Currently only the `-` character is accepted by the Jinja whitespace rules but technically `+` should be supported as well, i.e.:

    {%+ ... +%}
    {{+ ... +}}
    {#+ ... +#}

That's mentioned in the [upstream documentation](https://jinja.palletsprojects.com/en/2.10.x/templates/#whitespace-control) as well.

Thanks @myii, for mentioning this is 
https://github.com/roaldnefs/salt-lint/pull/13#issuecomment-538547711!

Discussion:

Patch:
diff --git a/lib/saltlint/rules/JinjaCommentHasSpacesRule.py b/lib/saltlint/rules/JinjaCommentHasSpacesRule.py
index 7b7c468..2253cdb 100644
--- a/lib/saltlint/rules/JinjaCommentHasSpacesRule.py
+++ b/lib/saltlint/rules/JinjaCommentHasSpacesRule.py
@@ -14,7 +14,7 @@ class JinjaCommentHasSpacesRule(SaltLintRule):
     tags = ['formatting']
     version_added = 'v0.0.5'
 
-    bracket_regex = re.compile(r"{#[^ -]|{#-[^ ]|[^ -]#}|[^ ]-#}")
+    bracket_regex = re.compile(r"{#[^ \-\+]|{#[\-\+][^ ]|[^ \-\+]#}|[^ ][\-\+]#}")
 
     def match(self, file, line):
         return self.bracket_regex.search(line)
diff --git a/lib/saltlint/rules/JinjaStatementHasSpacesRule.py b/lib/saltlint/rules/JinjaStatementHasSpacesRule.py
index 327cca7..80fa45f 100644
--- a/lib/saltlint/rules/JinjaStatementHasSpacesRule.py
+++ b/lib/saltlint/rules/JinjaStatementHasSpacesRule.py
@@ -14,7 +14,7 @@ class JinjaStatementHasSpacesRule(SaltLintRule):
     tags = ['formatting']
     version_added = 'v0.0.2'
 
-    bracket_regex = re.compile(r"{%[^ -]|{%-[^ ]|[^ -]%}|[^ ]-%}")
+    bracket_regex = re.compile(r"{%[^ \-\+]|{%[\-\+][^ ]|[^ \-\+]%}|[^ ][\-\+]%}")
 
     def match(self, file, line):
         return self.bracket_regex.search(line)
diff --git a/lib/saltlint/rules/JinjaVariableHasSpacesRule.py b/lib/saltlint/rules/JinjaVariableHasSpacesRule.py
index fe808f8..67da64d 100644
--- a/lib/saltlint/rules/JinjaVariableHasSpacesRule.py
+++ b/lib/saltlint/rules/JinjaVariableHasSpacesRule.py
@@ -14,7 +14,7 @@ class JinjaVariableHasSpacesRule(SaltLintRule):
     tags = ['formatting']
     version_added = 'v0.0.1'
 
-    bracket_regex = re.compile(r"{{[^ -]|{{-[^ ]|[^ -]}}|[^ ]-}}")
+    bracket_regex = re.compile(r"{{[^ \-\+]|{{[-\+][^ ]|[^ \-\+]}}|[^ ][-\+]}}")
 
     def match(self, file, line):
         return self.bracket_regex.search(line)


Test patch:
diff --git a/tests/unit/TestJinjaCommentHasSpaces.py b/tests/unit/TestJinjaCommentHasSpaces.py
index 16ddb2f..6e2ae54 100644
--- a/tests/unit/TestJinjaCommentHasSpaces.py
+++ b/tests/unit/TestJinjaCommentHasSpaces.py
@@ -10,11 +10,11 @@ from tests import RunFromText
 
 
 GOOD_COMMENT_LINE = '''
-{#- set example='good' -#}
+{#- set example='good' +#}
 '''
 
 BAD_COMMENT_LINE = '''
-{#-set example='bad'-#}
+{#-set example='bad'+#}
 '''
 
 class TestLineTooLongRule(unittest.TestCase):
diff --git a/tests/unit/TestJinjaStatementHasSpaces.py b/tests/unit/TestJinjaStatementHasSpaces.py
index 56f59c8..cf81c2e 100644
--- a/tests/unit/TestJinjaStatementHasSpaces.py
+++ b/tests/unit/TestJinjaStatementHasSpaces.py
@@ -10,11 +10,11 @@ from tests import RunFromText
 
 
 GOOD_STATEMENT_LINE = '''
-{%- set example='good' -%}
+{%- set example='good' +%}
 '''
 
 BAD_STATEMENT_LINE = '''
-{%-set example='bad'-%}
+{%-set example='bad'+%}
 '''
 
 class TestLineTooLongRule(unittest.TestCase):
diff --git a/tests/unit/TestJinjaVariableHasSpaces.py b/tests/unit/TestJinjaVariableHasSpaces.py
index 9c537e0..5e27b09 100644
--- a/tests/unit/TestJinjaVariableHasSpaces.py
+++ b/tests/unit/TestJinjaVariableHasSpaces.py
@@ -10,11 +10,11 @@ from tests import RunFromText
 
 
 GOOD_VARIABLE_LINE = '''
-{{- variable -}}
+{{- variable +}}
 '''
 
 BAD_VARIABLE_LINE = '''
-{{-variable-}}
+{{-variable+}}
 '''
 
 class TestLineTooLongRule(unittest.TestCase):