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

Unified Diff: tools/web_dev_style/js_checker.py

Issue 2917473002: js_checker.py: Restore smoke tests for linting violations. (Closed)
Patch Set: 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 | « no previous file | tools/web_dev_style/js_checker_eslint_test.py » ('j') | 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 7d48c3f853bacc7a347a74a378355139f50f4133..0df748921d7cfb3cae1063235c1180937e656685 100644
--- a/tools/web_dev_style/js_checker.py
+++ b/tools/web_dev_style/js_checker.py
@@ -62,14 +62,13 @@ class JSChecker(object):
return self.RegexCheck(i, line, r"(?<!this)(\.\$)[\[\.]",
"Please only use this.$.localId, not element.$.localId")
- def RunEsLintChecks(self, affected_js_files):
+ def RunEsLintChecks(self, affected_js_files_paths, format='stylish'):
"""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.
+ os_path = self.input_api.os_path
_HERE_PATH = os_path.dirname(os_path.realpath(__file__))
_SRC_PATH = os_path.normpath(os_path.join(_HERE_PATH, '..', '..'))
import sys
@@ -79,16 +78,10 @@ class JSChecker(object):
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',
+ '--format', format,
'--ignore-pattern \'!.eslintrc.js\'',
' '.join(affected_js_files_paths)])
@@ -124,8 +117,14 @@ class JSChecker(object):
affected_js_files = filter(lambda f: f.LocalPath().endswith('.js'),
affected_files)
+ # Extract paths to be passed to ESLint.
+ def get_path(f):
+ return os_path.relpath(
+ f.AbsoluteLocalPath(), self.input_api.PresubmitLocalPath())
+
if affected_js_files:
- results += self.RunEsLintChecks(affected_js_files)
+ affected_js_files_paths = map(get_path, affected_js_files)
+ results += self.RunEsLintChecks(affected_js_files_paths)
dpapad 2017/05/30 22:11:30 I had to change the signature of RunEsLintChecks,
Dan Beam 2017/05/30 23:11:08 wait, why doesn't this work? https://cs.chromium.o
dpapad 2017/05/31 01:30:06 Updated the code to use a MockFile().
for f in affected_js_files:
error_lines = []
« no previous file with comments | « no previous file | tools/web_dev_style/js_checker_eslint_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698