diff --git a/.github/workflows/nitpicks.yml b/.github/workflows/nitpicks.yml new file mode 100644 index 0000000000..3144d485f2 --- /dev/null +++ b/.github/workflows/nitpicks.yml @@ -0,0 +1,94 @@ +--- +name: Nitpicks + +on: pull_request + +jobs: + trailing-space: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v2 + with: + ref: $GITHUB_BASE_REF + - uses: actions/checkout@v2 + with: + ref: $GITHUB_HEAD_REF + - name: Checking for trailing characters + run: | + 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') + if [[ -n "$trail" ]]; then + echo "This pull request introduces trailing spaces (•)/tabs (→)/protected spaces (⋄) on the following lines:" + echo -e "\n$trail" + exit 1 + else + echo "This looks aight." + exit 0 + fi + + unwanted-character: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v2 + with: + ref: $GITHUB_BASE_REF + - uses: actions/checkout@v2 + with: + ref: $GITHUB_HEAD_REF + - name: Checking for tabs + run: | + tab=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\t/ p' | sed -r -e 's/\t/→/g') + if [[ -n "$tab" ]]; then + echo "This pull request introduces tabs (→) on the following lines:" + echo -e "\n$tab" + exit 1 + else + echo "This looks aight." + exit 0 + fi + - name: Checking for Windows/Mac line ends + run: | + lineends=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\r/ p' | sed -r -e 's/\r/↲/g') + if [[ -n "$lineends" ]]; then + echo "This pull request introduces Windows/Mac line ends (↲) on the following lines:" + echo -e "\n$lineends" + exit 1 + else + echo "This looks aight." + exit 0 + fi + + long-line: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v2 + with: + ref: $GITHUB_BASE_REF + - uses: actions/checkout@v2 + with: + ref: $GITHUB_HEAD_REF + - name: Checking for long lines + # We exclude screen, as there are legitimate reasons for them to be long. + run: | + potential=$(git diff -U1000 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | tr '\n' '\r' | sed -r -e 's,]*/>,,g' -e 's,]*>,⋘,g' -e 's,]*>[^⋘]*⋘,,g' | tr '\r' '\n' | sed -n '/^+/ p') + len=$(echo -e "$potential" | wc -l) + long='' + for n in $(seq 1 "$len"); do + line=$(echo -e "$potential" | sed -n "$n p") + if [[ $(echo "$line" | wc -c) -gt 91 ]]; then + long+="\n$line" + fi + done + if [[ -n "$long" ]]; then + echo "This pull request introduces long lines (80+ characters) in at least the following spots:" + echo -e "\n$long" + exit 1 + else + echo "This looks aight." + exit 0 + fi