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

Unified Diff: common/eslint/eslint/__init__.py

Issue 2361623007: Add a run_eslint wrapper script (Closed)
Patch Set: Created 4 years, 2 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
Index: common/eslint/eslint/__init__.py
diff --git a/common/eslint/eslint/__init__.py b/common/eslint/eslint/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..28860deb6a090942294a57ddfa1886767443b64e
--- /dev/null
+++ b/common/eslint/eslint/__init__.py
@@ -0,0 +1,61 @@
+# Copyright 2016 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.
+
+import os
+import subprocess
+import sys
+
+
+_CATAPULT_PATH = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ os.path.pardir, os.path.pardir, os.path.pardir)
+
+
+def _AddToPathIfNeeded(path):
+ if path not in sys.path:
+ sys.path.insert(0, path)
+
+
+def _UpdateSysPathIfNeeded():
+ _AddToPathIfNeeded(os.path.join(_CATAPULT_PATH, 'common', 'node_runner'))
+ _AddToPathIfNeeded(os.path.join(_CATAPULT_PATH, 'common', 'py_utils'))
+
+
+_UpdateSysPathIfNeeded()
+
+
+import py_utils
+from node_runner import node_util
+
+
+ESLINT_CMD = [
+ node_util.GetNodePath(),
+ os.path.join(node_util.GetNodeModulesPath(), 'eslint', 'bin', 'eslint.js'),
+ '--color',
+ '--config',
+ os.path.join(py_utils.GetCatapultDir(), 'common', 'eslint', '.eslintrc'),
nednguyen 2016/10/05 16:13:33 I would make the "config" path & rules configurabl
charliea (OOO until 10-5) 2016/10/05 17:24:43 Done.
+ '--rulesdir',
+ os.path.join(py_utils.GetCatapultDir(), 'common', 'eslint', 'rules'),
+]
+
+
+def RunEslintOnDirs(dirs):
+ try:
+ find_cmd = ['find'] + dirs + ['-name', '*.html']
+ p1 = subprocess.Popen(find_cmd, stdout=subprocess.PIPE)
+ output = subprocess.check_output(['xargs'] + ESLINT_CMD, stdin=p1.stdout)
+ p1.wait()
+ return output
+ except subprocess.CalledProcessError as e:
+ return e.output
+
+
+def RunEslintOnFiles(filenames=None):
nednguyen 2016/10/05 16:13:33 Why bother having a default value for filenames as
charliea (OOO until 10-5) 2016/10/05 17:24:43 Good point. I started raising an error when filena
+ if filenames is None:
+ filenames = []
+ try:
+ return subprocess.check_output(ESLINT_CMD + filenames,
+ stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError as e:
+ return e.output

Powered by Google App Engine
This is Rietveld 408576698