Turn on polymer templates checker and remove old polylint checker

The Code-Style is failed because some templates have issues.

Change-Id: Ic97b7e9bd62f490cc3e19a4c1187d36744ed5077
diff --git a/package.json b/package.json
index 8859ede..8a25abc 100644
--- a/package.json
+++ b/package.json
@@ -32,11 +32,10 @@
     "safe_bazelisk": "if which bazelisk >/dev/null; then bazel_bin=bazelisk; else bazel_bin=bazel; fi && $bazel_bin",
     "eslint": "npm run safe_bazelisk test polygerrit-ui/app:lint_test",
     "eslintfix": "npm run safe_bazelisk run polygerrit-ui/app:lint_bin -- -- --fix $(pwd)/polygerrit-ui/app",
-    "polylint": "npm run safe_bazelisk test polygerrit-ui/app:polylint_test",
     "test:debug": "npm run compile:local && npm run safe_bazelisk run //polygerrit-ui:karma_bin -- -- start $(pwd)/polygerrit-ui/karma.conf.js --root '.ts-out/polygerrit-ui/app/' --browsers ChromeDev --no-single-run --test-files",
     "test:single": "npm run compile:local && npm run safe_bazelisk run //polygerrit-ui:karma_bin -- -- start $(pwd)/polygerrit-ui/karma.conf.js --root '.ts-out/polygerrit-ui/app/' --test-files",
-    "polytest": "npm run safe_bazelisk test //polygerrit-ui/app:validate_polymer_templates",
-    "polytest:dev": "rm -rf ./polygerrit-ui/app/tmpl_out && npm run safe_bazelisk build //polygerrit-ui/app:template_test_tar && mkdir ./polygerrit-ui/app/tmpl_out && tar -xf bazel-bin/polygerrit-ui/app/template_test_tar.tar -C ./polygerrit-ui/app/tmpl_out"
+    "polylint": "npm run safe_bazelisk test //polygerrit-ui/app:polylint_test",
+    "polylint:dev": "rm -rf ./polygerrit-ui/app/tmpl_out && npm run safe_bazelisk build //polygerrit-ui/app:template_test_tar && mkdir ./polygerrit-ui/app/tmpl_out && tar -xf bazel-bin/polygerrit-ui/app/template_test_tar.tar -C ./polygerrit-ui/app/tmpl_out"
   },
   "repository": {
     "type": "git",
diff --git a/polygerrit-ui/app/BUILD b/polygerrit-ui/app/BUILD
index 613efd6..85e948f 100644
--- a/polygerrit-ui/app/BUILD
+++ b/polygerrit-ui/app/BUILD
@@ -45,8 +45,6 @@
     ),
     allow_js = True,
     incremental = True,
-    # The same outdir also appears in the following files:
-    # polylint_test.sh
     out_dir = "_pg_ts_out",
     tsc = "//tools/node_tools:tsc-bin",
     tsconfig = ":ts_config_bazel",
@@ -145,17 +143,19 @@
     "elements/shared/gr-list-view/gr-list-view_html.ts",
 ]
 
+sources_for_template_checking = glob(
+    [src_dir + "/**/*" + ext for src_dir in src_dirs for ext in [
+        ".ts",
+    ]],
+    exclude = [
+        "**/*_test.ts",
+    ] + ignore_templates_list,
+)
+
 # Transform templates into a .ts files.
 templates_srcs = transform_polymer_templates(
     name = "template_test",
-    srcs = glob(
-        [src_dir + "/**/*" + ext for src_dir in src_dirs for ext in [
-            ".ts",
-        ]],
-        exclude = [
-            "**/*_test.ts",
-        ] + ignore_templates_list,
-    ),
+    srcs = sources_for_template_checking,
     out_tsconfig = "tsconfig_template_test.json",
     tsconfig = "tsconfig_bazel.json",
     deps = [
@@ -165,50 +165,34 @@
     ],
 )
 
-# Compile transformed templates together with the polygerrit source. If
-# templates don't have problem, then the compilation ends without error.
-# Otherwise, the typescript compiler reports the error.
-# Note, that the compile_ts macro creates build rules. If the build succeed,
-# the macro creates the file compile_template_test.success. The
-# 'validate_polymer_templates' rule tests existence of the file.
-#
-# TODO: Re-instantiate this rule. It broke when switching to ts_project with
-# ERROR: //polygerrit-ui/app:compile_template_test srcs cannot be a mix of
-#        generated files and source files since this would prevent giving a
-#        single rootDir to the TypeScript compiler
-# Also, the emitJS feature of compile_ts has to be re-created in some form.
-#ts_project(
-#    name = "compile_template_test",
-#    srcs = templates_srcs + glob(
-#        [src_dir + "/**/*" + ext for src_dir in src_dirs for ext in [
-#            ".ts",
-#        ]],
-#        exclude = [
-#            "**/*_test.ts",
-#        ] + ignore_templates_list,
-#    ),
-#    allow_js = True,
-#    out_dir = "_pg_template_test_out",
-#    # Should not run sandboxed.
-#    tags = [
-#        "local",
-#        "manual",
-#    ],
-#    tsc = "//tools/node_tools:tsc-bin",
-#    tsconfig = "tsconfig_template_test.json",
-#)
-#
-# This rule allows to run polymer template checker with bazel test command.
-# For details - see compile_template_test rule.
-#
-# TODO: Re-instantiate this test. It broke when switching
-#       'compile_template_test'to ts_project, see above. ts_project does not
-#       create '.success' files.
-#sh_test(
-#    name = "validate_polymer_templates",
-#    srcs = [":empty_test.sh"],
-#    data = ["compile_template_test.success"],
-#)
+# After templates are converted into a typescript code, the TS compiler should check that the
+# converted code doesn't have the error (i.e. templates don't have problems).
+# The input to the compiler is: the converted (i.e. autogenerated) code + original polygerrit code;
+# the output (i.e. js code) is not needed (we only care wheather the code has error or not).
+# The existing ts_project rule can't compile a mix of a generated and a non-generated code, so it
+# can't be used for the purpose of template checking.
+# Because the output of TS compiler is not needed, the simplest workaround is to run typescript
+# compiler from command line using the sh_test rule. The compiler exits with non-zero return code if
+# errors found and sh_test fails.
+sh_test(
+    name = "polylint_test",
+    srcs = [":compile_generated_templates.sh"],
+    args = [
+        "$(location //tools/node_tools:tsc-bin)",
+        "$(location tsconfig_template_test.json)",
+    ],
+    data = [
+        "tsconfig_template_test.json",
+        "tsconfig_bazel.json",
+        "tsconfig.json",
+        "//tools/node_tools:tsc-bin",
+        "@ui_npm//:node_modules",
+    ] + templates_srcs + sources_for_template_checking,
+    tags = [
+        "local",
+        "manual",
+    ],
+)
 
 polygerrit_bundle(
     name = "polygerrit_ui",
@@ -290,33 +274,3 @@
         "@npm//gts",
     ],
 )
-
-filegroup(
-    name = "polylint-fg",
-    srcs = [
-        # Workaround for https://github.com/bazelbuild/bazel/issues/1305
-        "@ui_npm//:node_modules",
-        # Polylinter can't check .ts files, run it on compiled srcs
-        ":compile_pg",
-    ],
-)
-
-sh_test(
-    name = "polylint_test",
-    size = "large",
-    srcs = ["polylint_test.sh"],
-    args = [
-        "$(location @tools_npm//polymer-cli/bin:polymer)",
-        "$(location polymer.json)",
-    ],
-    data = [
-        "polymer.json",
-        ":polylint-fg",
-        "@tools_npm//polymer-cli/bin:polymer",
-    ],
-    # Should not run sandboxed.
-    tags = [
-        "local",
-        "manual",
-    ],
-)
diff --git a/polygerrit-ui/app/compile_generated_templates.sh b/polygerrit-ui/app/compile_generated_templates.sh
new file mode 100755
index 0000000..68bf485
--- /dev/null
+++ b/polygerrit-ui/app/compile_generated_templates.sh
@@ -0,0 +1 @@
+$1 --project $2 --baseUrl ./external/ui_npm/node_modules/ --rootDir null
diff --git a/polygerrit-ui/app/empty_test.sh b/polygerrit-ui/app/empty_test.sh
deleted file mode 100755
index e69de29..0000000
--- a/polygerrit-ui/app/empty_test.sh
+++ /dev/null