Chromium Code Reviews| 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 |