From 744045d542ad573637195e2dd09676af4a94d873 Mon Sep 17 00:00:00 2001 From: Wyatt Allen Date: Wed, 17 May 2017 17:45:17 -0700 Subject: [PATCH] Add PolyLint Bazel rule To install the linter: npm install -g polylint To run the linter: bazel test //polygerrit-ui/app:polylint_test Change-Id: I552f6eedce0e4e90d394acfc516940a8c26e948f --- polygerrit-ui/README.md | 14 ++++++++++++++ polygerrit-ui/app/BUILD | 25 +++++++++++++++++++++++++ polygerrit-ui/app/polylint_test.sh | 18 ++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100755 polygerrit-ui/app/polylint_test.sh diff --git a/polygerrit-ui/README.md b/polygerrit-ui/README.md index 1c97114b01..01f61d93ee 100644 --- a/polygerrit-ui/README.md +++ b/polygerrit-ui/README.md @@ -148,3 +148,17 @@ Some useful commands: `eslint --ext .html,.js polygerrit-ui/app/$YOUR_DIR_HERE` * To run the linter on all of your local changes: `git diff --name-only master | xargs eslint --ext .html,.js` + +We also use the polylint tool to lint use of Polymer. To install polylint, +execute the following command. + +```sh +npm install -g polylint +``` + +To run polylint, execute the following command. + +```sh +bazel test //polygerrit-ui/app:polylint_test +``` + diff --git a/polygerrit-ui/app/BUILD b/polygerrit-ui/app/BUILD index 4e99272485..b2ce8f05c3 100644 --- a/polygerrit-ui/app/BUILD +++ b/polygerrit-ui/app/BUILD @@ -129,6 +129,16 @@ filegroup( ), ) +filegroup( + name = "bower_components", + srcs = glob( + [ + "bower_components/**/*.html", + "bower_components/**/*.js", + ] + ), +) + genrule2( name = "pg_code_zip", srcs = [":pg_code"], @@ -172,3 +182,18 @@ sh_test( "manual", ], ) + +sh_test( + name = "polylint_test", + size = "large", + srcs = ["polylint_test.sh"], + data = [ + ":pg_code", + ":bower_components", + ], + # Should not run sandboxed. + tags = [ + "local", + "manual", + ], +) diff --git a/polygerrit-ui/app/polylint_test.sh b/polygerrit-ui/app/polylint_test.sh new file mode 100755 index 0000000000..9f136a6655 --- /dev/null +++ b/polygerrit-ui/app/polylint_test.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -ex + +npm_bin=$(which npm) +if [[ -z "$npm_bin" ]]; then + echo "NPM must be on the path." + exit 1 +fi + +polylint_bin=$(which polylint) +if [[ -z "$polylint_bin" ]]; then + echo "You must install polylint and its dependencies from NPM." + echo "> npm install -g polylint" + exit 1 +fi + +${polylint_bin} --root polygerrit-ui/app --input elements/gr-app.html