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

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

Issue 2361623007: Add a run_eslint wrapper script (Closed)
Patch Set: Checkpoint. Created 4 years, 3 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/eslint.py
diff --git a/common/eslint/eslint/eslint.py b/common/eslint/eslint/eslint.py
new file mode 100755
index 0000000000000000000000000000000000000000..47c58319c70da0889dad6de0c813825933c9060a
--- /dev/null
+++ b/common/eslint/eslint/eslint.py
@@ -0,0 +1,49 @@
+# 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.
+
nednguyen 2016/09/23 10:17:49 Move the content of this file to __init__.py inste
charliea (OOO until 10-5) 2016/09/23 13:06:34 Done.
charliea (OOO until 10-5) 2016/09/23 13:06:34 Done.
+import os
+import subprocess
+import sys
+
+import py_utils
+from node_runner import node_util
+
+
+DIRECTORIES_TO_LINT = [
+ os.path.join(py_utils.GetCatapultDir(), 'dashboard', 'dashboard'),
+ os.path.join(py_utils.GetCatapultDir(), 'tracing', 'tracing')
+]
+
+
+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'),
+ '--rulesdir',
+ os.path.join(py_utils.GetCatapultDir(), 'common', 'eslint', 'rules')
+]
+
+
+def RunEslintGlobal():
nednguyen 2016/09/23 10:17:49 Can you merge this to RunEslintOnDir(dir_path), th
charliea (OOO until 10-5) 2016/09/23 13:06:34 Done.
charliea (OOO until 10-5) 2016/09/23 13:06:34 Done.
+ try:
+ find_cmd = ['find'] + DIRECTORIES_TO_LINT + ['-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 RunEslint(filenames=None):
+ 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