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:
parent
9989171401
commit
0e329816bd
|
@ -28,10 +28,27 @@ else
|
||||||
FIND_FILES="find . "
|
FIND_FILES="find . "
|
||||||
fi
|
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() {
|
test_for_final_newline() {
|
||||||
while read filename; do
|
while read filename; do
|
||||||
# Only check non-executable regular files
|
# Only check regular files and script executables
|
||||||
if [ -f "$filename" ] && [ ! -x "$filename" ]; then
|
if [ -f "$filename" ] && { [ ! -x "$filename" ] || \
|
||||||
|
is_eligible_executable "$filename"; };
|
||||||
|
then
|
||||||
|
|
||||||
# Verify that there is a newline at the end
|
# Verify that there is a newline at the end
|
||||||
# $() strips trailing newlines
|
# $() strips trailing newlines
|
||||||
|
|
Loading…
Reference in New Issue