Add checks for whitespace consistency (#405)

* Add checks for whitespace consistency

* Fix name of check_whitespace job

* Fix paths
This commit is contained in:
Michael Lynch
2021-01-13 18:22:46 -05:00
committed by GitHub
parent c106e760f2
commit bf07bfe729
9 changed files with 74 additions and 6 deletions

View File

@@ -1,5 +1,16 @@
version: 2.1
jobs:
check_whitespace:
docker:
- image: cimg/base:2020.01
steps:
- checkout
- run:
name: Check for trailing whitespace
command: ./dev-scripts/check-trailing-whitespace
- run:
name: Check that all text files end in a trailing newline
command: ./dev-scripts/check-trailing-newline
build_python:
docker:
- image: circleci/python:3.7.3
@@ -37,6 +48,7 @@ jobs:
workflows:
test:
jobs:
- check_whitespace
- build_python
- format_frontend
- e2e

View File

@@ -7,4 +7,4 @@ update_configs:
- match:
# We need to use a specific pylint version that's compatible with
# DocStringChecker.
dependency_name: "pylint"
dependency_name: "pylint"

View File

@@ -18,4 +18,4 @@ def index_get():
def stream_get():
if flask.current_app.debug:
return flask.send_file('tests/data/test-remote-screen.jpg')
return flask.abort(404)
return flask.abort(404)

View File

@@ -9,5 +9,7 @@ set -x
# Exit on unset variable.
set -u
./dev-scripts/check-trailing-whitespace
./dev-scripts/check-trailing-newline
./dev-scripts/build-python
./dev-scripts/check-frontend-format
./dev-scripts/check-frontend-format

View File

@@ -9,4 +9,4 @@ set -x
# Exit on unset variable.
set -u
./node_modules/.bin/prettier --check app/static
./node_modules/.bin/prettier --check app/static

View File

@@ -0,0 +1,33 @@
#!/bin/bash
# Verify that all text files end in a trailing newline.
# Exit on first failing command.
set -e
# Exit on unset variable.
set -u
FILES=$(find . \
-type f \
-not -path "./.git/*" \
-not -path "./venv/*" \
-not -path "./node_modules/*" \
-not -path "*/third_party/*" \
-not -path "*/third-party/*" \
-not -path "*.svg" \
-exec grep \
--binary-files=without-match \
--quiet \
. {} \; -print)
SUCCESS=0
for F in ${FILES[*]}
do
if ! [[ -s "$F" && -z "$(tail -c 1 "$F")" ]]; then
printf "File must end in a trailing newline: $F\n"
SUCCESS=-1
fi
done
exit "$SUCCESS"

View File

@@ -0,0 +1,21 @@
#!/bin/bash
# Check for trailing whitespace
# Echo commands to console.
set -x
# Exit on first failing command.
set -e
# Exit on unset variable.
set -u
if egrep \
"\s$" \
--line-number \
--binary-files=without-match \
--dereference-recursive \
--exclude-dir={.git,venv,node_modules} \
./ ; then
echo "ERROR: Found trailing whitespace";
exit 1;
fi

View File

@@ -17,4 +17,4 @@ then
rm -rf .git/hooks
fi
ln -s -f ../hooks .git/hooks
ln -s -f ../hooks .git/hooks

View File

@@ -9,4 +9,4 @@ set -x
# Exit on unset variable.
set -u
./dev-scripts/build
./dev-scripts/build