Repository: warpnet/salt-lint (python)

Issue:
Error 206 triggered with nested literal brace
**Describe the bug**
Error 206 is erroneously reported for the following construction

**To Reproduce**
```
[206] [LOW] Jinja variables should have spaces before and after: '{{ var_name }}'
test.sls:3
    - name: '{${{ key }}}'
```


**Expected behavior**
No issue on this line.


**Desktop (please complete the following information):**

- OS: Windows 10
- Version 0.6.1



Pull request description:
Fix false positive for spaces in Jinja variable
Fix false positive when detecting missing spaces in the Jinja variable when the Jinja statement is nested in literal braces.

Closes #257

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8336c91..6630714 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@ All notable changes in **salt-lint** are documented below.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Fixed
+- False positive when detecting missing spaces in Jinja variables when the Jinja statement is nested in literal braces ([#272](https://github.com/warpnet/salt-lint/pull/272)).
 
 ## [0.7.0] (2021-11-01)
 ### Added
diff --git a/saltlint/rules/JinjaVariableHasSpacesRule.py b/saltlint/rules/JinjaVariableHasSpacesRule.py
index 03433b6..52cff83 100644
--- a/saltlint/rules/JinjaVariableHasSpacesRule.py
+++ b/saltlint/rules/JinjaVariableHasSpacesRule.py
@@ -14,7 +14,9 @@ class JinjaVariableHasSpacesRule(JinjaRule):
     severity = 'LOW'
     version_added = 'v0.0.1'
 
-    bracket_regex = re.compile(r"{{[^ \-\+\d]|{{[-\+][^ ]|[^ \-\+\d]}}|[^ {][-\+\d]}}")
+    bracket_regex = re.compile(
+        r"{{[^ {}\-\+\d]|{{[-\+][^ {}]|[^ {}\-\+\d]}}|[^ {}][-\+\d]}}"
+    )
 
     def match(self, file, line):
         return self.bracket_regex.search(line)


Test patch:
diff --git a/tests/unit/TestJinjaVariableHasSpaces.py b/tests/unit/TestJinjaVariableHasSpaces.py
index 4e53f33..80c9906 100644
--- a/tests/unit/TestJinjaVariableHasSpaces.py
+++ b/tests/unit/TestJinjaVariableHasSpaces.py
@@ -51,6 +51,10 @@ DOUBLE_QUOTED_INTEGER_LEADING_SPACE_IS_INVALID = '''
 {{"{{0}}" }}
 '''
 
+NESTED_LITERAL_BRACES = '''
+    - name: '{${{ key }}}'
+'''
+
 class TestJinjaVariableHasSpaces(unittest.TestCase):
     collection = RulesCollection()
 
@@ -98,3 +102,12 @@ class TestJinjaVariableHasSpaces(unittest.TestCase):
     def test_variable_bad_ends_with_integer_right(self):
         results = self.runner.run_state(BAD_VARIABLE_ENDING_IN_INTEGER_RIGHT)
         self.assertEqual(1, len(results))
+
+    def test_nested_literal_braces(self):
+        """
+        Check if Jinja variables inside nested literal braces are identified
+        correctly. See related GitHub issue:
+        https://github.com/warpnet/salt-lint/issues/257
+        """
+        results = self.runner.run_state(NESTED_LITERAL_BRACES)
+        self.assertEqual(0, len(results))