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>
This commit is contained in:
Alex Thiessen 2018-01-18 22:55:07 +00:00 committed by Martin Roth
parent 9989171401
commit 0e329816bd
1 changed files with 19 additions and 2 deletions

View File

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