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..82a69da78f714e7d09e75e7ee5ce9da706fb7549 100644 |
--- a/tools/web_dev_style/js_checker.py |
+++ b/tools/web_dev_style/js_checker.py |
@@ -68,6 +68,39 @@ 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. |
+ """ |
+ # Import ESLint. |
+ try: |
+ import os |
Dan Beam
2017/05/24 22:57:53
use self.input_api.os_path instead of `import os`
dpapad
2017/05/24 23:46:02
Done.
|
+ _HERE_PATH = os.path.dirname(os.path.realpath(__file__)) |
Dan Beam
2017/05/24 22:57:53
i'm not totalllly sure how __file__ works here, bu
dpapad
2017/05/24 23:46:02
input_api.PresubmitLocalPath() returns the locatio
Dan Beam
2017/05/25 00:14:51
probably not. if it works for now with `git cl pr
|
+ _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..')) |
+ import sys |
+ _NODE_PATH = os.path.join(_SRC_PATH, 'third_party', 'node') |
+ old_path = sys.path[::] |
Dan Beam
2017/05/24 23:01:34
nit: [::] -> [:]
dpapad
2017/05/24 23:46:02
Done.
|
+ sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'node')) |
+ import node |
+ import node_modules |
Dan Beam
2017/05/24 23:01:34
import node, node_modules
dpapad
2017/05/24 23:46:02
Done.
|
+ finally: |
+ sys.path = old_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 +130,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 = [] |