Index: common/eslint/bin/run_eslint |
diff --git a/common/eslint/bin/run_eslint b/common/eslint/bin/run_eslint |
new file mode 100755 |
index 0000000000000000000000000000000000000000..044787cf5a8bb6179e0ebef35926527f22d3a5df |
--- /dev/null |
+++ b/common/eslint/bin/run_eslint |
@@ -0,0 +1,52 @@ |
+#!/usr/bin/env python |
+# 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 argparse |
+import os |
+import sys |
+ |
+ |
+_CATAPULT_PATH = os.path.abspath( |
+ os.path.join(os.path.dirname(__file__), |
+ os.path.pardir, os.path.pardir, os.path.pardir)) |
+ |
+ |
+_ESLINT_PATH = os.path.abspath( |
+ os.path.join(os.path.dirname(__file__), os.path.pardir)) |
+ |
+ |
+DIRECTORIES_TO_LINT = [ |
+ os.path.join(_CATAPULT_PATH, 'dashboard', 'dashboard'), |
+ os.path.join(_CATAPULT_PATH, 'tracing', 'tracing') |
+] |
+ |
+ |
+def _AddToPathIfNeeded(path): |
+ if path not in sys.path: |
+ sys.path.insert(0, path) |
+ |
+ |
+if __name__ == '__main__': |
+ _AddToPathIfNeeded(_ESLINT_PATH) |
+ import eslint |
+ |
+ parser = argparse.ArgumentParser( |
+ description='Wrapper script to run eslint on Catapult code') |
+ parser.add_argument('--files', '-f', default=None, nargs='+', metavar='FILE', |
+ help='List of files to lint') |
+ parser.add_argument('--all', default=None, action='store_true', |
+ help='Runs eslint on all applicable Catapult code') |
+ |
+ args = parser.parse_args(sys.argv[1:]) |
+ if ((args.files is not None and args.all is not None) or |
+ (args.files is None and args.all is None)): |
+ print 'Either --files or --all must be used, but not both.\n' |
+ parser.print_help() |
+ sys.exit(1) |
+ |
+ if args.all: |
+ print eslint.RunEslintOnDirs(DIRECTORIES_TO_LINT) |
+ else: |
+ print eslint.RunEslintOnFiles(args.files) |