Skip to content

Commit b2294c9

Browse files
author
Stefan Knorr
committed
GHA: Introduce new workflow to nitpick on trailing spaces and long lines
1 parent 88b4164 commit b2294c9

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

.github/workflows/nitpicks.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
name: Nitpicks
3+
4+
on: pull_request
5+
6+
jobs:
7+
trailing-space:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
ref: ${{ env.GITHUB_BASE_REF }}
15+
- uses: actions/checkout@v2
16+
with:
17+
ref: ${{ env.GITHUB_HEAD_REF }}
18+
- name: Checking for trailing characters
19+
run: |
20+
trail=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/[  \t]$/ p' | sed -r -e 's/ /•/g' -e 's/\t/→/g' -e 's/ /⋄/g')
21+
if [[ -n "$trail" ]]; then
22+
echo "This pull request introduces trailing spaces (•)/tabs (→)/protected spaces (⋄) on the following lines:"
23+
echo -e "\n$trail"
24+
exit 1
25+
else
26+
echo "This looks aight."
27+
exit 0
28+
fi
29+
30+
unwanted-character:
31+
runs-on: ubuntu-latest
32+
strategy:
33+
fail-fast: false
34+
steps:
35+
- uses: actions/checkout@v2
36+
with:
37+
ref: ${{ env.GITHUB_BASE_REF }}
38+
- uses: actions/checkout@v2
39+
with:
40+
ref: ${{ env.GITHUB_HEAD_REF }}
41+
- name: Checking for tabs
42+
run: |
43+
tab=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\t/ p' | sed -r -e 's/\t/→/g')
44+
if [[ -n "$tab" ]]; then
45+
echo "This pull request introduces tabs (→) on the following lines:"
46+
echo -e "\n$tab"
47+
exit 1
48+
else
49+
echo "This looks aight."
50+
exit 0
51+
fi
52+
- name: Checking for Windows/Mac line ends
53+
run: |
54+
lineends=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\r/ p' | sed -r -e 's/\r/↲/g')
55+
if [[ -n "$lineends" ]]; then
56+
echo "This pull request introduces Windows/Mac line ends (↲) on the following lines:"
57+
echo -e "\n$lineends"
58+
exit 1
59+
else
60+
echo "This looks aight."
61+
exit 0
62+
fi
63+
64+
long-line:
65+
runs-on: ubuntu-latest
66+
strategy:
67+
fail-fast: false
68+
steps:
69+
- uses: actions/checkout@v2
70+
with:
71+
ref: ${{ env.GITHUB_BASE_REF }}
72+
- uses: actions/checkout@v2
73+
with:
74+
ref: ${{ env.GITHUB_HEAD_REF }}
75+
- name: Checking for long lines
76+
# We exclude screen, as there are legitimate reasons for them to be long.
77+
run: |
78+
potential=$(git diff -U1000 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | tr '\n' '\r' | sed -r -e 's,<screen[^>]*/>,,g' -e 's,</screen[^>]*>,⋘,g' -e 's,<screen[^/>]*>[^⋘]*⋘,,g' | tr '\r' '\n' | sed -n '/^+/ p')
79+
len=$(echo -e "$potential" | wc -l)
80+
long=''
81+
for n in $(seq 1 "$len"); do
82+
line=$(echo -e "$potential" | sed -n "$n p")
83+
if [[ $(echo "$line" | wc -c) -gt 91 ]]; then
84+
long+="\n$line"
85+
fi
86+
done
87+
if [[ -n "$long" ]]; then
88+
echo "This pull request introduces long lines (80+ characters) in at least the following spots:"
89+
echo -e "\n$long"
90+
exit 1
91+
else
92+
echo "This looks aight."
93+
exit 0
94+
fi

0 commit comments

Comments
 (0)