| 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..d0fcb1f19182d463e94580c7d94ba848e53153f0
|
| --- /dev/null
|
| +++ b/common/eslint/eslint/__init__.py
|
| @@ -0,0 +1,62 @@
|
| +# 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'),
|
| + '--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 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
|
|
|