Skip to content

Commit

Permalink
checks: fix spurious indent violations
Browse files Browse the repository at this point in the history
tclint would report a spurious indent violations when a braced word ends
on a line other than its starting line and is followed by a comment or
additional words.
  • Loading branch information
nmoroze committed Jul 4, 2024
1 parent ecc1030 commit 2ffdbdc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/tclint/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ def visit_bare_word(self, word):
def visit_braced_word(self, word):
self._set_level(word)

# Ensure that we don't check indentation of things that come after closing
# brace, if this is closed on a different line than it starts.
end_line = word.end_pos[0]
if end_line not in self.expected_levels:
self.expected_levels[end_line] = None

def visit_quoted_word(self, word):
self._set_level(word)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,12 @@ def test_spacing_multiline_expr():
assert len(violations) == 1
assert violations[0].id == Rule.EXPR_FORMAT
assert violations[0].pos == (3, 9)


def test_no_indent_violation_after_close_brace():
"""Regression test for https://github.com/nmoroze/tclint/issues/48."""
script = r"""puts {
Hello} ;# asdf"""

violations = lint(script, Config(), Path())
assert len(violations) == 0

0 comments on commit 2ffdbdc

Please sign in to comment.