From 3b798e0729571f40e61d8996ab57570862877507 Mon Sep 17 00:00:00 2001 From: Tin Lam Date: Fri, 11 Mar 2016 23:56:11 -0600 Subject: [PATCH] Exclude hashbangs check for .bashrc, .bash_profile, etc Remove E005 errors for hidden configuration files that do not end with .sh, e.g., .profile, .bashrc, .bash_profile, etc. Change-Id: I57d5b556cbc8843b744d3276a1dfdd7467d74fde Closes-Bug: #1554653 --- bashate/bashate.py | 5 +++-- bashate/tests/samples/.E005_excluded | 4 ++++ bashate/tests/test_bashate.py | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) mode change 100644 => 100755 bashate/bashate.py create mode 100644 bashate/tests/samples/.E005_excluded diff --git a/bashate/bashate.py b/bashate/bashate.py old mode 100644 new mode 100755 index b1180ca..4512238 --- a/bashate/bashate.py +++ b/bashate/bashate.py @@ -148,8 +148,9 @@ def check_local_subshell(line, report): def check_hashbang(line, filename, report): # this check only runs on the first line # maybe this should check for shell? - if not line.startswith("#!") and not filename.endswith(".sh"): - report.print_error(MESSAGES['E005'].msg, line) + if (not filename.endswith(".sh") and not line.startswith("#!") and + not os.path.basename(filename).startswith('.')): + report.print_error(MESSAGES['E005'].msg, line) def check_syntax(filename, report): diff --git a/bashate/tests/samples/.E005_excluded b/bashate/tests/samples/.E005_excluded new file mode 100644 index 0000000..f3971db --- /dev/null +++ b/bashate/tests/samples/.E005_excluded @@ -0,0 +1,4 @@ +# this profile/hidden file doesn't start with #! +# and doesn't have a .sh extension + +echo hi diff --git a/bashate/tests/test_bashate.py b/bashate/tests/test_bashate.py index 3039b1e..103db9a 100644 --- a/bashate/tests/test_bashate.py +++ b/bashate/tests/test_bashate.py @@ -257,6 +257,12 @@ class TestBashateSamples(base.TestCase): self.assert_error_found('E005', 1) + def test_sample_E005_excluded(self): + test_files = ['bashate/tests/samples/.E005_excluded'] + self.run.check_files(test_files, False) + + self.assertEqual(0, self.run.error_count) + def test_sample_E040(self): test_files = ['bashate/tests/samples/E040_syntax_error.sh'] self.run.register_errors('E040')