Skip to content

Commit

Permalink
Jinja2Bear: Disable the need of trailing comment
Browse files Browse the repository at this point in the history
This enables the end of block to not have comment.
However by default it would check for the trailing comment
But the behavior can be changed by the user explicitly.

Closes coala#2659
  • Loading branch information
gutsytechster authored and gitmate-bot committed Aug 13, 2018
1 parent 9ab7878 commit 23d03cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bears/jinja2/Jinja2Bear.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ def check_control_end_tags(self,
filename,
line,
line_number,
control_spacing):
control_spacing,
check_end_labels):
"""
Checks any control end tag in the given line for spacing issues,
missing/wrong labels or missing corresponding opening tag.
Expand Down Expand Up @@ -308,6 +309,9 @@ def check_control_end_tags(self,
yield self.handle_control_spacing_issue(
file, filename, line, line_number, control_spacing, m)

if not check_end_labels:
return

# yield results for incorrect or missing end labels
if label is None and line_number != start_in_line:
diff = generate_label_diff(
Expand Down Expand Up @@ -356,6 +360,7 @@ def run(self,
variable_spacing: int = 1,
statement_spacing: int = 1,
control_spacing: int = 1,
check_end_labels: bool = True,
):
"""
Check `Jinja2 templates <http://jinja.pocoo.org>`_ for syntax,
Expand Down Expand Up @@ -420,7 +425,9 @@ def run(self,
file, filename, line, line_number, control_spacing)

yield from self.check_control_end_tags(
file, filename, line, line_number, control_spacing)
file, filename, line, line_number, control_spacing,
check_end_labels,
)

# We've reached the end of the file.
# Check if all control blocks have been closed
Expand Down
20 changes: 20 additions & 0 deletions tests/jinja2/Jinja2BearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,26 @@ def test_control_spacing(self):
valid_files=(good_file1, good_file2, good_file3),
invalid_files=(bad_file1, bad_file2))

valid_file_without_end_comments = """
foo
{% for x in something %}
render stuff
{% endfor %}
"""

valid_file_with_end_comments = """
foo
{% for x in something %}
render stuff
{% endfor %}{# for x in something #}
"""

Jinja2BearForLoopLabelDisableTest = verify_local_bear(
Jinja2Bear,
valid_files=(valid_file_without_end_comments, valid_file_with_end_comments),
invalid_files=(),
settings={'check_end_labels': 'False'})


class Jinja2BearLabelDiffTest(unittest.TestCase):

Expand Down

0 comments on commit 23d03cd

Please sign in to comment.