From 0feb84a83fca92789d2a154b33b959ef6ffbff11 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 10 Nov 2021 11:44:15 +0900 Subject: [PATCH] Check indents on comment lines The check makes sense for comment lines as well. An example: if :; then # comment echo hello fi Change-Id: I3baff60fe272440bbcbe5dd809f264bca1092b78 --- bashate/bashate.py | 2 ++ bashate/tests/samples/comments.sh | 6 +++++- bashate/tests/test_bashate.py | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bashate/bashate.py b/bashate/bashate.py index 76a04ef..d980cd5 100755 --- a/bashate/bashate.py +++ b/bashate/bashate.py @@ -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: diff --git a/bashate/tests/samples/comments.sh b/bashate/tests/samples/comments.sh index a9fa643..e4386b6 100644 --- a/bashate/tests/samples/comments.sh +++ b/bashate/tests/samples/comments.sh @@ -21,6 +21,10 @@ fi # ``RST style comment`` - # ``indented comment`` + # ``indented comment`` (E003) + + # ``indented comment`` (4 spaces, ok) + + # ``indented comment`` (tab, E002) # tab comment diff --git a/bashate/tests/test_bashate.py b/bashate/tests/test_bashate.py index 5212f41..27e4943 100644 --- a/bashate/tests/test_bashate.py +++ b/bashate/tests/test_bashate.py @@ -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']