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
Add a new rule for detecting nested jinja mustache syntax #686
Conversation
This comment has been minimized.
This comment has been minimized.
46967ad
to
25d8f95
Compare
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.
Overall looks okay but it's better to also add tests before merging.
recheck |
recheck |
@europ could you please also submit tests for this feature? It'd be hard to keep it working/healthy/supported without any CI checks in place. |
Good evening @webknjaz, Thank you for your added patches. I am sorry that I did not add the tests yet. I am struggling with other current tasks. I will add it soon. Best regards. |
📌 TODO: add tests |
✔️ tests added |
Hi @webknjaz, I have added the tests as soon as I could. I am sorry for the delay. |
@europ it's alright. No need to rush. Could you please check the failing CI jobs? Looks like the tests are failing. |
There is some warning
I tried some of the shared advice I found but I didn't succeed.
I am not very familiar with jekyll / sphinx, do you have any idea how to fix this warning? It might be needed to rewrite some parts of the documentation to fix this. |
I think those sphinx errors are not related to your change. But there's failures in other jobs that might be. |
Just to be on the safe side, rebase your branch on top of the fresh master |
Oh, it looks like you need to regenerate
|
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.
You used Czech diacritics/letters w/ accents. They are subset of Unicode and Python 2 doesn't know what to do with them and fails expecting plain ASCII.
If you want to use Unicode in modules under Python 2, you must specify the encoding at the top so that the parser would know what to do.
==================================== ERRORS ====================================
_________________ ERROR collecting test/TestNestedJinjaRule.py _________________
.tox/ansible27/lib/python2.7/site-packages/py/_path/local.py:701: in pyimport
__import__(modname)
E File "/home/runner/work/ansible-lint/ansible-lint/test/TestNestedJinjaRule.py", line 1
E SyntaxError: Non-ASCII character '\xc3' in file /home/runner/work/ansible-lint/ansible-lint/test/TestNestedJinjaRule.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
BTW, should I squash the commits into one? |
@europ looks like |
Oh, wait... You didn't touch Also, please mark your PR as "Ready for review" once the CI checks are green. |
Hmm... |
def matchtask(self, file, task): | ||
|
||
command = "".join([ | ||
value |
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.
This could be
value | |
str(value) |
but also for some types it may be misleading. Like b'something'
may be turned into "b'something'"
. So you may want to be careful here — bytes should be converted differently.
* pattern matching logic * rule was added to docs * unit test modification * related docs fix
str(value) | ||
# task properties are stored in the 'action' key | ||
for key, value in task['action'].items() | ||
# exclude useless values of '__file__', '__ansible_module__', '__*__', etc. |
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.
This shouldn't explain how the code works. Reading it is pretty obvious. Code comments must be used to explain why this code is here.
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 guess this is not very important atm so I won't wait for the rephrase.
I didn't take into account that we have a custom dynamic rule importer and the class won't match. Reverting that. |
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.
Great job, @europ!
@webknjaz thanks for the help & review! |
A new rule for ansible lint was added that provides nested jinja bracket pattern detection. Nesting jinja patterns can lead to failures and other problems.
\cc @amarza-rh