Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(818)

Unified Diff: tools/web_dev_style/js_checker.py

Issue 2872703003: WebUI: Hook up ESLint to web_dev_style PRESUBMIT. (Closed)
Patch Set: Address comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/web_dev_style/OWNERS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/web_dev_style/js_checker.py
diff --git a/tools/web_dev_style/js_checker.py b/tools/web_dev_style/js_checker.py
index a42a1a22aeef70d5e538bde352d2f0fac7aaf38a..46cb6fc1498487042af9f6a79f66ccf5b532b8f3 100644
--- a/tools/web_dev_style/js_checker.py
+++ b/tools/web_dev_style/js_checker.py
@@ -68,6 +68,38 @@ class JSChecker(object):
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__))
Dan Beam 2017/05/25 01:01:20 why do you need to call realpath?
dpapad 2017/05/25 01:11:56 I might not need to, not sure if calling realpath(
+ _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 @@ class JSChecker(object):
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 = []
« no previous file with comments | « tools/web_dev_style/OWNERS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698