Merge "Exclude hashbangs check for .bashrc, .bash_profile, etc"

This commit is contained in:
Jenkins 2016-07-15 04:31:46 +00:00 committed by Gerrit Code Review
commit 83611280ed
3 changed files with 13 additions and 2 deletions

5
bashate/bashate.py Normal file → Executable file
View File

@ -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):

View File

@ -0,0 +1,4 @@
# this profile/hidden file doesn't start with #!
# and doesn't have a .sh extension
echo hi

View File

@ -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')