curlylint
curlylint copied to clipboard
add new rule django_block_translate_trimmed
- the rule will enforce the usage of
trimmed
when blocktranslate or blocktrans is in use - resolves the specific use case behind #131 - I think a generic rule would probably be way more complex and it is better to start with a specific one and add abstractions later
I had trouble running black
, not sure if it is a config issue but no matter what I would put into Python files, black would not do anything so I just copy/pasted from the Black playground and back into the editor.
Additional items
- [x] test case for when
trimmed
is not the first argument to the blocktranslate tag when using multiple arguments - [x] test case for when there are linebreaks between the open/close tags
Updated with a few more tests, not sure if I need to test malformed (e.g. unclosed) block tags.
Loic - good call about the trimmed
position - I'll try to resolve this soon. I'll update the description checklist to include this and the other item.
@loicteixeira @zerolab is there anything else blocking this PR?
Nothing from me. Nice work @lb-!
Tests updated to include scenarios listed above, just need someone to trigger the workflow.
I was getting this error locally but it does not not seem to be related to the changes I have made.
self = <curlylint.cli_test.TestCLI testMethod=test_template_tags_cli_unconfigured_fails>
def test_template_tags_cli_unconfigured_fails(self):
runner = self.invoke_curlylint(
1,
["--template-tags", "[]", "-"],
input="<p>{% of a %}c{% elseof %}test{% endof %}</p>",
)
> self.assertIn(
"Parse error: expected one of 'autoescape', 'block', 'blocktrans', 'comment', 'filter', 'for', 'if', 'ifchanged', 'ifequal', 'ifnotequal', 'not an intermediate Jinja tag name', 'spaceless', 'verbatim', 'with' at 0:17\tparse_error",
runner.stdout_bytes.decode(),
)
E AssertionError: "Parse error: expected one of 'autoescape', 'block', 'blocktrans', 'comment', 'filter', 'for', 'if', 'ifchanged', 'ifequal', 'ifnotequal', 'not an intermediate Jinja tag name', 'spaceless', 'verbatim', 'with' at 0:17\tparse_error" not found in "\x1b[4m-\x1b[0m\n\x1b[2m0:17\x1b[0m\tParse error: expected one of 'autoescape', 'block', 'blocktrans', 'blocktranslate', 'comment', 'filter', 'for', 'if', 'ifchanged', 'ifequal', 'ifnotequal', 'not an intermediate Jinja tag name', 'spaceless', 'verbatim', 'with' at 0:17\tparse_error\n\n"
curlylint/cli_test.py:97: AssertionError
=============================================================== short test summary info ===============================================================
FAILED curlylint/cli_test.py::TestCLI::test_template_tags_cli_unconfigured_fails - AssertionError: "Parse error: expected one of 'autoescape', 'bloc...
======================================================= 1 failed, 91 passed, 1 skipped in 6.97s =======================================================
make: *** [Makefile:22: test] Error 1