xref: /aosp_15_r20/external/coreboot/util/lint/lint-stable-003-whitespace (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1#!/usr/bin/env sh
2#
3# SPDX-License-Identifier: GPL-2.0-only
4
5# DESCR: Check for superfluous whitespace in the tree
6
7LINTDIR="$(
8  cd -- "$(dirname "$0")" > /dev/null 2>&1 || return
9  pwd -P
10)"
11# shellcheck source=helper_functions.sh
12. "${LINTDIR}/helper_functions.sh"
13
14EXCLUDELIST='^src/vendorcode/|^util/kconfig/|^util/nvidia/cbootimage|^util/goswid|__pycache__|COPYING|LICENSE|README|_shipped$|\.patch$|\.bin$|\.hex$|\.jpg$|\.gif$|\.ttf$|\.woff$|\.png$|\.eot$|\.vbt$|\.ico$|\.md$|\.apcb$|\.dtb$'
15INCLUDELIST="src util payloads Makefile* toolchain.mk tests"
16
17# shellcheck disable=SC2086,SC2046
18if uname | grep -qi "linux"; then
19	grep -n -H "[[:space:]][[:space:]]*$" \
20		$(${FIND_FILES} ${INCLUDELIST} ${FINDOPTS} | \
21			grep -Ev "($EXCLUDELIST)" ) | \
22		sed -e "s,^.*$,File & has lines ending with whitespace.,"
23else
24	# The above form is much (100x) faster, but doesn't work
25	# on all systems. A for loop also works but takes 30% longer
26	${FIND_FILES} ${INCLUDELIST} ${FINDOPTS}| \
27		grep -Ev "($EXCLUDELIST)" | \
28		xargs -I % \
29			grep -l "[[:space:]][[:space:]]*$" % | \
30			sed -e "s,^.*$,File & has lines ending with whitespace.,"
31fi
32