-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement jinja[spacing] to avoid use of regex (#2306)
This change rewrites jinja2 rule to make it use jinaja lex parser and avoid use of regexes for parsing, as they cause too many false positives. Fixes: #2301 #2285 #2241 #2209 #2208 #2120
- Loading branch information
Showing
7 changed files
with
513 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
## jinja | ||
|
||
This rule can report problems related to jinja2 string templates. The current | ||
version can report `jinja[spacing]` when there are no spaces between variables | ||
and operators, including filters, like `{{ var_name | filter }}`. This | ||
improves readability and makes it less likely to introduce typos. | ||
version can report: | ||
|
||
- `jinja[spacing]` when there are no spaces between variables | ||
and operators, including filters, like `{{ var_name | filter }}`. This | ||
improves readability and makes it less likely to introduce typos. | ||
- `jinja[invalid]` when the jinja2 template is invalid | ||
|
||
As jinja2 syntax is closely following Python one we aim to follow | ||
[black](https://black.readthedocs.io/en/stable/) formatting rules. If you are | ||
curious how black would reformat a small sniped feel free to visit | ||
[online black formatter](https://black.vercel.app/) site. Keep in mind to not | ||
include the entire jinja2 template, so instead of `{{ 1+2==3 }}`, do paste | ||
only `1+2==3`. | ||
|
||
### Problematic code | ||
|
||
```yaml | ||
--- | ||
foo: "{{some|dict2items}}" | ||
foo: "{{some|dict2items}}" # <-- jinja[spacing] | ||
bar: "{{ & }}" # <-- jinja[invalid] | ||
``` | ||
### Correct code | ||
```yaml | ||
--- | ||
foo: "{{ some | dict2items }}" | ||
bar: "{{ '&' }}" | ||
``` |
Oops, something went wrong.