Check indents on comment lines

The check makes sense for comment lines as well.

An example:

    if :; then
    <tab># comment
    <spaces>echo hello
    fi

Change-Id: I3baff60fe272440bbcbe5dd809f264bca1092b78
This commit is contained in:
YAMAMOTO Takashi 2021-11-10 11:44:15 +09:00
parent cbd46caeb8
commit 0feb84a83f
3 changed files with 11 additions and 2 deletions

View File

@ -334,6 +334,8 @@ class BashateRun(object):
# inside a heredoc this might be part of the syntax of
# an embedded script, just ignore that)
if line.lstrip().startswith('#') and not in_heredoc:
logical_line = [line]
check_indents(logical_line, report)
continue
# Strip trailing comments. From bash:

View File

@ -21,6 +21,10 @@ fi
# ``RST style comment``
# ``indented comment``
# ``indented comment`` (E003)
# ``indented comment`` (4 spaces, ok)
# ``indented comment`` (tab, E002)
# tab comment

View File

@ -260,7 +260,10 @@ class TestBashateSamples(base.TestCase):
test_files = ['bashate/tests/samples/comments.sh']
self.run.check_files(test_files, False)
self.assertEqual(0, self.run.error_count)
self.assert_error_found('E003', 24)
self.assert_error_found('E002', 28)
self.assert_error_found('E003', 28)
self.assertEqual(3, self.run.error_count)
def test_sample_E005(self):
test_files = ['bashate/tests/samples/E005_bad']