New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Jinja2 whitespace control chars in vars #500
Allow Jinja2 whitespace control chars in vars #500
Conversation
75f8302
to
31e4d4a
Compare
Fixes #499 |
Signed-off-by: Sebastian Meyer <meyer@b1-systems.de>
31e4d4a
to
d5fb463
Compare
Signed-off-by: Sebastian Meyer <meyer@b1-systems.de>
Signed-off-by: Sebastian Meyer <meyer@b1-systems.de>
@webknjaz Can you have a look at this? |
@@ -13,7 +13,7 @@ class VariableHasSpacesRule(AnsibleLintRule): | |||
tags = ['formatting'] | |||
version_added = 'v4.0.0' | |||
|
|||
bracket_regex = re.compile("{{[^{' ]|[^ '}]}}") | |||
bracket_regex = re.compile("{{[^{' -]|[^ '}-]}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use raw-string literals for regexps
bracket_regex = re.compile("{{[^{' -]|[^ '}-]}}") | |
bracket_regex = re.compile(r"{{[^{' -]|[^ '}-]}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this regexp does this check. Can anyone explain it to me? It seems wrong (even the original one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand we want to match everything that's starting with {{
not followed by space or hyphen. Also we want to allow {{ '{{' }}
so we need to allow single quotes after {{
aswell. Same thing for }}
. I'm not sure why we wouldn't want to match {{{
or }}}
though.
Maybe @awcrosby can tell us why it's needed?
Problem is, this actually allows doing {{'asdas'}}
as {{'
and '}}
are not matched. Same for {{-asassa-}}
. But the regex to capture that would be something like: ({{-(?! ))|({{'(?! ))|({{[^ '-])|([^' -]}})|((?<=[^ ])-}})|((?<=[^ ])'}})
and I'm not positive we want to do that.
I'm not sure if python does allow the regex to be split into multiple lines? Then we probably could introduce it with (# comment)
to explain it. Basically like:
({{-(?! ))|(# match everything with {{- not followed by a space OR)
({{'(?! ))|(# match everything with {{' not followed by a space OR)
({{[^ '-])|(# match everything with {{ not followed by a space, single quotation mark or hyphen OR)
([^' -]}})|(# match everything with }} not preceded by a space, single quotation mark or hyphen OR)
((?<=[^ ])-}})|(# match everything with -}} not preceded by a space OR)
((?<=[^ ])'}})(# match everything with '}} not preceded by a space)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does work with \
at EOL, though I'm still not sure, we want to do that.
Signed-off-by: Sebastian Meyer <meyer@b1-systems.de>
c74f5fd
to
ab15b5a
Compare
The allowing of Thanks for pointing out this rule allows The PR looks good, I will merge this in - thanks for the contribution! |
No description provided.