summaryrefslogtreecommitdiff
path: root/util/lint/lint-extended-015-final-newlines
diff options
context:
space:
mode:
authorAlex Thiessen <alex.thiessen.de+coreboot@gmail.com>2018-01-18 22:55:07 +0000
committerMartin Roth <martinroth@google.com>2018-01-26 17:28:16 +0000
commit0e329816bd74187c46ceb21c79a497b4886a7da9 (patch)
tree5f281748676b78f5e4a3099e363c19c5c7925595 /util/lint/lint-extended-015-final-newlines
parent9989171401175e9a701782bd08858b87c99183bc (diff)
util/lint: Apply `final newlines` check to scripts
The `lint-extended-015-final-newlines` script skips over executable files and thus leaves script files unchecked. Use `file` to find scripts and include them in the `final newlines` checks. Whitelisting is used including bash, perl, python and sh scripts. Change-Id: I8649b261b7e2cbbac7f9b90a9ace3f1c7b0eedeb Signed-off-by: Alex Thiessen <alex.thiessen.de+coreboot@gmail.com> Reviewed-on: https://review.coreboot.org/23325 Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Martin Roth <martinroth@google.com>
Diffstat (limited to 'util/lint/lint-extended-015-final-newlines')
-rwxr-xr-xutil/lint/lint-extended-015-final-newlines21
1 files changed, 19 insertions, 2 deletions
diff --git a/util/lint/lint-extended-015-final-newlines b/util/lint/lint-extended-015-final-newlines
index 1315dbdee5..5c60ddf54d 100755
--- a/util/lint/lint-extended-015-final-newlines
+++ b/util/lint/lint-extended-015-final-newlines
@@ -28,10 +28,27 @@ else
FIND_FILES="find . "
fi
+HAVE_FILE=$(command -v file 1>/dev/null 2>&1; echo $?)
+
+is_eligible_executable() {
+ if [ "$HAVE_FILE" -ne 0 ]; then
+ return 1
+ fi
+ if { LC_ALL=C; file --brief "$filename" | grep -Eqw \
+ "^(Bourne shell|POSIX shell|Perl|Python) script"; };
+ then
+ return 0
+ else
+ return 1
+ fi
+}
+
test_for_final_newline() {
while read filename; do
- # Only check non-executable regular files
- if [ -f "$filename" ] && [ ! -x "$filename" ]; then
+ # Only check regular files and script executables
+ if [ -f "$filename" ] && { [ ! -x "$filename" ] || \
+ is_eligible_executable "$filename"; };
+ then
# Verify that there is a newline at the end
# $() strips trailing newlines