Skip to content

Commit 8506c49

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

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

.github/workflows/nitpicks.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
fetch-depth: 0
15+
- name: Checking out relevant branches
16+
run: |
17+
git checkout $GITHUB_BASE_REF || { echo "There's a Git issue"; exit 1; }
18+
git checkout $GITHUB_HEAD_REF || { echo "There's a Git issue"; exit 1; }
19+
- name: Checking for trailing characters
20+
run: |
21+
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')
22+
if [[ -n "$trail" ]]; then
23+
echo "This pull request introduces trailing spaces (•)/tabs (→)/protected spaces (⋄) on the following lines:"
24+
echo -e "\n$trail"
25+
exit 1
26+
else
27+
echo "This looks aight."
28+
exit 0
29+
fi
30+
31+
- name: Checking for long lines
32+
# We exclude screens, there are legitimate reasons for them to be long.
33+
run: |
34+
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')
35+
len=$(echo -e "$potential" | wc -l)
36+
long=''
37+
for n in $(seq 1 "$len"); do
38+
line=$(echo -e "$potential" | sed -n "$n p")
39+
if [[ $(echo "$line" | wc -c) -gt 91 ]]; then
40+
long+="\n$line"
41+
fi
42+
done
43+
if [[ -n "$long" ]]; then
44+
echo "This pull request introduces long lines (80+ characters) in at least the following spots:"
45+
echo -e "\n$long"
46+
exit 1
47+
else
48+
echo "This looks aight."
49+
exit 0
50+
fi
51+
52+
- name: Checking for tabs
53+
run: |
54+
tab=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\t/ p' | sed -r -e 's/\t/→/g')
55+
if [[ -n "$tab" ]]; then
56+
echo "This pull request introduces tabs (→) on the following lines:"
57+
echo -e "\n$tab"
58+
exit 1
59+
else
60+
echo "This looks aight."
61+
exit 0
62+
fi
63+
64+
- name: Checking for Windows/Mac line ends
65+
run: |
66+
lineends=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\r/ p' | sed -r -e 's/\r/↲/g')
67+
if [[ -n "$lineends" ]]; then
68+
echo "This pull request introduces Windows/Mac line ends (↲) on the following lines:"
69+
echo -e "\n$lineends"
70+
exit 1
71+
else
72+
echo "This looks aight."
73+
exit 0
74+
fi

0 commit comments

Comments
 (0)