Skip to content

Instantly share code, notes, and snippets.

@openjck
Last active Jul 27, 2020
Embed
What would you like to do?
Bash script which exits with an error if there are too many ESLint problems. Use this gradually reduce the number of problems to zero. https://medium.com/reflections-on-building-software/gradually-reduce-the-number-of-eslint-problems-in-your-codebase-fe503d4f2716
#!/usr/bin/env bash
# Fail if there are too many ESLint problems. The definition of "too many" is
# hardcoded. The number can be manually lowered over time as problems are fixed
# to prevent regressions.
#
# This is a copy of the following Gist:
# https://gist.github.com/openjck/ab1a435e249580861afbc5b93465e611
#
# More information:
# https://medium.com/reflections-on-building-software/gradually-reduce-the-number-of-eslint-problems-in-your-codebase-fe503d4f2716
echo "Running..."
echo
MAX_ESLINT_PROBLEMS=50 # Lower this number over time as problems are fixed
NUM_ESLINT_PROBLEMS=$(npm run lint 2>&1 | grep -E "[0-9]+ problems \(" | cut -f 2 -d ' ')
echo "Max ESLint problems: $MAX_ESLINT_PROBLEMS"
echo "Num ESLint problems: $NUM_ESLINT_PROBLEMS"
echo
if [[ $NUM_ESLINT_PROBLEMS -eq 0 ]]; then
echo "PASS: No ESLint problems!"
echo "NOTE: Congratulations! You don't need this script any more. Consider"
echo " removing it and running \"npm run lint\" instead."
elif [[ $NUM_ESLINT_PROBLEMS -le $MAX_ESLINT_PROBLEMS ]]; then
echo "PASS: Number of ESLint problems <= max"
if [[ $NUM_ESLINT_PROBLEMS -lt $MAX_ESLINT_PROBLEMS ]]; then
echo "NOTE: Considering lowering MAX_ESLINT_PROBLEMS to $NUM_ESLINT_PROBLEMS"
echo " in the eslint-health script to prevent regressions"
fi
else
>&2 echo "FAIL: Number of ESLint problems > max"
>&2 echo "NOTE: Recent changes may have introduced new ESLint problems"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment