WebUI: Hook up ESLint to web_dev_style PRESUBMIT.
Using a trivial .eslintrc.js config for now, just so that the checks
can be enabled. More lint rules will be added in follow up CLs.
BUG=720034
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation
Review-Url: https://codereview.chromium.org/2872703003
Cr-Commit-Position: refs/heads/master@{#474720}
diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 0000000..9b4b1037
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,16 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+module.exports = {
+ 'root': true,
+ 'env': {
+ 'browser': true,
+ 'es6': true
+ },
+ 'rules': {
+ // Enabled checks.
+ 'no-extra-semi': 'error',
+ // TODO(dpapad): Add more checks according to our styleguide.
+ },
+};
diff --git a/OWNERS b/OWNERS
index cfcc6f7e..e3d4359 100644
--- a/OWNERS
+++ b/OWNERS
@@ -3,6 +3,7 @@
# Eng reviewer. Please reach out before adding new top-level directories.
file://ENG_REVIEW_OWNERS
+per-file .eslintrc.js=file://tools/web_dev_style/OWNERS
per-file .gitattributes=*
per-file .gitignore=*
per-file .git-blame-ignore-revs=mgiuca@chromium.org
diff --git a/tools/web_dev_style/OWNERS b/tools/web_dev_style/OWNERS
index f8dba18..8ece9c55 100644
--- a/tools/web_dev_style/OWNERS
+++ b/tools/web_dev_style/OWNERS
@@ -1,2 +1,3 @@
dbeam@chromium.org
+dpapad@chromium.org
tbreisacher@chromium.org
diff --git a/tools/web_dev_style/js_checker.py b/tools/web_dev_style/js_checker.py
index a42a1a22..46cb6fc1 100644
--- a/tools/web_dev_style/js_checker.py
+++ b/tools/web_dev_style/js_checker.py
@@ -68,6 +68,38 @@
return self.RegexCheck(i, line, r"(?<!this)(\.\$)[\[\.]",
"Please only use this.$.localId, not element.$.localId")
+ def RunEsLintChecks(self, affected_js_files):
+ """Runs lint checks using ESLint. The ESLint rules being applied are defined
+ in the .eslintrc.js configuration file.
+ """
+ os_path = self.input_api.os_path
+
+ try:
+ # Import ESLint.
+ _HERE_PATH = os_path.dirname(os_path.realpath(__file__))
+ _SRC_PATH = os_path.normpath(os_path.join(_HERE_PATH, '..', '..'))
+ import sys
+ old_sys_path = sys.path[:]
+ sys.path.append(os_path.join(_SRC_PATH, 'third_party', 'node'))
+ import node, node_modules
+ finally:
+ sys.path = old_sys_path
+
+ # Extract paths to be passed to ESLint.
+ affected_js_files_paths = []
+ presubmit_path = self.input_api.PresubmitLocalPath()
+ for f in affected_js_files:
+ affected_js_files_paths.append(
+ os_path.relpath(f.AbsoluteLocalPath(), presubmit_path))
+
+ output = node.RunNode([
+ node_modules.PathToEsLint(),
+ '--color',
+ '--ignore-pattern \'!.eslintrc.js\'',
+ ' '.join(affected_js_files_paths)])
+
+ return [self.output_api.PresubmitError(output)] if output else []
+
def WrapperTypeCheck(self, i, line):
"""Check for wrappers (new String()) instead of builtins (string)."""
return self.RegexCheck(i, line,
@@ -97,6 +129,10 @@
include_deletes=False)
affected_js_files = filter(lambda f: f.LocalPath().endswith('.js'),
affected_files)
+
+ if affected_js_files:
+ results += self.RunEsLintChecks(affected_js_files)
+
for f in affected_js_files:
error_lines = []