| #!/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') |
| parser.add_argument('--extra-args', default=None, type=str, |
| help='A string of extra arguments to pass to eslint') |
| |
| 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, extra_args=args.extra_args) |
| else: |
| print eslint.RunEslintOnFiles(args.files, extra_args=args.extra_args) |