Skip to content

Commit d8d9162

Browse files
author
MarcoFalke
committed
Merge #12572: [script] lint-whitespace: find errors more easily
0fbed98 [script] lint-whitespace: improve print linenumber (Akio Nakamura) Pull request description: 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. example: 0) git diff ``` diff --git a/dummy.txt b/dummy.txt index c0ce4d776..aebbdb88d 100644 --- a/dummy.txt +++ b/dummy.txt @@ -1,2 +1,2 @@ -1 -2 +1 + 2 @@ -8,2 +8,2 @@ -8 -9 + 8 +9 ``` 1) before this PR - Is there "9 " in second line? It may lead to be misunderstood. ``` This diff appears to have added new lines with trailing whitespace. The following changes were suspected: diff --git a/dummy.txt b/dummy.txt @@ -1,2 +1,2 @@ +1 +9 ``` 2) after this PR ``` This diff appears to have added new lines with trailing whitespace. The following changes were suspected: diff --git a/dummy.txt b/dummy.txt @@ -1,2 +1,2 @@ +1 @@ -8,2 +8,2 @@ +9 ``` Tree-SHA512: 2fd52e3c982786f86cfe10aa2578589bc9c502bcad9b85111467840d726143330c23968cde5483ee0f563893c8381044b80e8c22a7c8eca56fc73c548b9a9496
2 parents bb98aec + 0fbed98 commit d8d9162

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
@@ -51,21 +51,26 @@ if showdiff | grep -E -q '^\+.*\s+$'; then
5151
echo "The following changes were suspected:"
5252
FILENAME=""
5353
SEEN=0
54+
SEENLN=0
5455
while read -r line; do
5556
if [[ "$line" =~ ^diff ]]; then
5657
FILENAME="$line"
5758
SEEN=0
5859
elif [[ "$line" =~ ^@@ ]]; then
5960
LINENUMBER="$line"
61+
SEENLN=0
6062
else
6163
if [ "$SEEN" -eq 0 ]; then
6264
# The first time a file is seen with trailing whitespace, we print the
6365
# filename (preceded by a newline).
6466
echo
6567
echo "$FILENAME"
66-
echo "$LINENUMBER"
6768
SEEN=1
6869
fi
70+
if [ "$SEENLN" -eq 0 ]; then
71+
echo "$LINENUMBER"
72+
SEENLN=1
73+
fi
6974
echo "$line"
7075
fi
7176
done < <(showdiff | grep -E '^(diff --git |@@|\+.*\s+$)')
@@ -78,21 +83,26 @@ if showcodediff | perl -nle '$MATCH++ if m{^\+.*\t}; END{exit 1 unless $MATCH>0}
7883
echo "The following changes were suspected:"
7984
FILENAME=""
8085
SEEN=0
86+
SEENLN=0
8187
while read -r line; do
8288
if [[ "$line" =~ ^diff ]]; then
8389
FILENAME="$line"
8490
SEEN=0
8591
elif [[ "$line" =~ ^@@ ]]; then
8692
LINENUMBER="$line"
93+
SEENLN=0
8794
else
8895
if [ "$SEEN" -eq 0 ]; then
8996
# The first time a file is seen with a tab character, we print the
9097
# filename (preceded by a newline).
9198
echo
9299
echo "$FILENAME"
93-
echo "$LINENUMBER"
94100
SEEN=1
95101
fi
102+
if [ "$SEENLN" -eq 0 ]; then
103+
echo "$LINENUMBER"
104+
SEENLN=1
105+
fi
96106
echo "$line"
97107
fi
98108
done < <(showcodediff | perl -nle 'print if m{^(diff --git |@@|\+.*\t)}')

0 commit comments

Comments
 (0)