Skip to content

Commit 0fbed98

Browse files
committed
[script] lint-whitespace: improve print linenumber
Before this PR, the linenumber infomaition is output if trailing-space or tab code was found, but the output occurence is only per a file. This PR separates the output timing of file name and line number. As a result, users will find where they need to fix more easily.
1 parent 9e2ed25 commit 0fbed98

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

contrib/devtools/lint-whitespace.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,26 @@ if showdiff | grep -E -q '^\+.*\s+$'; then
3737
echo "The following changes were suspected:"
3838
FILENAME=""
3939
SEEN=0
40+
SEENLN=0
4041
while read -r line; do
4142
if [[ "$line" =~ ^diff ]]; then
4243
FILENAME="$line"
4344
SEEN=0
4445
elif [[ "$line" =~ ^@@ ]]; then
4546
LINENUMBER="$line"
47+
SEENLN=0
4648
else
4749
if [ "$SEEN" -eq 0 ]; then
4850
# The first time a file is seen with trailing whitespace, we print the
4951
# filename (preceded by a newline).
5052
echo
5153
echo "$FILENAME"
52-
echo "$LINENUMBER"
5354
SEEN=1
5455
fi
56+
if [ "$SEENLN" -eq 0 ]; then
57+
echo "$LINENUMBER"
58+
SEENLN=1
59+
fi
5560
echo "$line"
5661
fi
5762
done < <(showdiff | grep -E '^(diff --git |@@|\+.*\s+$)')
@@ -64,21 +69,26 @@ if showcodediff | grep -P -q '^\+.*\t'; then
6469
echo "The following changes were suspected:"
6570
FILENAME=""
6671
SEEN=0
72+
SEENLN=0
6773
while read -r line; do
6874
if [[ "$line" =~ ^diff ]]; then
6975
FILENAME="$line"
7076
SEEN=0
7177
elif [[ "$line" =~ ^@@ ]]; then
7278
LINENUMBER="$line"
79+
SEENLN=0
7380
else
7481
if [ "$SEEN" -eq 0 ]; then
7582
# The first time a file is seen with a tab character, we print the
7683
# filename (preceded by a newline).
7784
echo
7885
echo "$FILENAME"
79-
echo "$LINENUMBER"
8086
SEEN=1
8187
fi
88+
if [ "$SEENLN" -eq 0 ]; then
89+
echo "$LINENUMBER"
90+
SEENLN=1
91+
fi
8292
echo "$line"
8393
fi
8494
done < <(showcodediff | grep -P '^(diff --git |@@|\+.*\t)')

0 commit comments

Comments
 (0)