Add lint_test.sh and corresponding bazel test
ESLint can now be run from Bazel using...
> bazel test //polygerrit-ui/app:lint_test
...or the maybe more user-friendly...
> bazel test //polygerrit-ui/app:lint_test --test_output errors
This script has several limitations, and is meant mostly as an MVP while
the PG codebase itself still doesn't meet the linter's standards.
- It is not hermetic (it cannot download and run the necessary binaries
in a sandboxed environment)
- The user cannot specify which files they want to test
- The user cannot specify whether they want to fix any errors
automatically
- The user cannot pass any other arbitrary flags to ESLint
- CI does not run this test when applying the Verified label
These issues will all be fixed in later changes.
Bug: Issue 6163
Change-Id: I14b8d165600d6c3f9394c2bb6ec520e29e40b308
diff --git a/polygerrit-ui/.eslintrc.json b/polygerrit-ui/app/.eslintrc.json
similarity index 100%
rename from polygerrit-ui/.eslintrc.json
rename to polygerrit-ui/app/.eslintrc.json
diff --git a/polygerrit-ui/app/BUILD b/polygerrit-ui/app/BUILD
index 7c12fa2..4947058 100644
--- a/polygerrit-ui/app/BUILD
+++ b/polygerrit-ui/app/BUILD
@@ -157,3 +157,18 @@
"manual",
],
)
+
+sh_test(
+ name = "lint_test",
+ size = "large",
+ srcs = ["lint_test.sh"],
+ data = [
+ ":pg_code",
+ ".eslintrc.json",
+ ],
+ # Should not run sandboxed.
+ tags = [
+ "local",
+ "manual",
+ ],
+)
diff --git a/polygerrit-ui/app/lint_test.sh b/polygerrit-ui/app/lint_test.sh
new file mode 100755
index 0000000..7ee74d8
--- /dev/null
+++ b/polygerrit-ui/app/lint_test.sh
@@ -0,0 +1,22 @@
+#!/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} --ignore-pattern 'bower_components/' --ignore-pattern 'gr-linked-text' --ignore-pattern 'scripts/vendor' --ext .html,.js .