Skip to content

Commit 8f8f31e

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

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

.github/workflows/nitpicks.yml

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

0 commit comments

Comments
 (0)