Files
gerrit/polygerrit-ui/app/lint_test.sh
Tao Zhou 22302f03ed Add a shared pre-commit to run eslintfix for frontend code changes
This pre-commit hook will fail the commit when you have linter errors.
It will also only run on changed staged files.

Also cleaned up linter config in package and lint_test.

Change-Id: I312b16d8ad2245b2cd848cb03b2a50e56372aa72
2019-12-11 15:25:26 +01:00

23 lines
688 B
Bash
Executable File

#!/bin/sh
set -ex
eslint_bin=$(which npm)
if [ -z "$eslint_bin" ]; then
echo "NPM must be on the path."
exit 1
fi
eslint_bin=$(which eslint)
eslint_config=$(npm list -g | grep -c eslint-config-google)
eslint_plugin=$(npm list -g | grep -c eslint-plugin-html)
if [ -z "$eslint_bin" ] || [ "$eslint_config" -eq "0" ] || [ "$eslint_plugin" -eq "0" ]; then
echo "You must install ESLint and its dependencies from NPM."
echo "> npm install -g eslint eslint-config-google eslint-plugin-html"
echo "For more information, view the README:"
echo "https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/#Style-guide"
exit 1
fi
${eslint_bin} --ext .html,.js .