| #!/usr/bin/env python3 |
| # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Lint our source files.""" |
| |
| import glob |
| import os |
| import sys |
| |
| import nassh |
| import libdot |
| |
| |
| JS_DIR = nassh.DIR / 'js' |
| |
| # Path to generated deps file that terminal uses for libdot/hterm/etc... |
| DEPS_FILE = os.path.join(JS_DIR, 'nassh_deps.concat.js') |
| |
| |
| def _get_default_paths(basedir): |
| """Get list of paths to lint by default.""" |
| most_files = sorted(x for x in libdot.lint.get_known_sources(basedir) |
| if x.suffix not in {'.js'}) |
| |
| # All files in js/*.js excluding generated files. |
| # Use relpath for nicer default output. |
| # Sort to ensure nasftp.js comes before nasftp_cli.js, etc. |
| js_files = sorted(x for x in JS_DIR.glob('*.js') |
| if not x.name.startswith('nassh_deps')) |
| |
| return [os.path.relpath(x) for x in most_files + js_files] |
| |
| |
| def mkdeps(_opts): |
| """Build the deps we might use when linting.""" |
| if not os.path.exists(DEPS_FILE): |
| libdot.run([os.path.join(nassh.DIR, 'bin', 'mkdeps')]) |
| |
| |
| def main(argv): |
| """The main func!""" |
| # We need to use an absolute path with the module root to workaround |
| # https://github.com/google/closure-compiler/issues/3580 |
| for i, arg in enumerate(argv): |
| if arg and arg[0] != '-' and os.path.exists(arg): |
| argv[i] = os.path.relpath(os.path.realpath(arg), nassh.DIR) |
| os.chdir(nassh.DIR) |
| |
| externs = ['--js_module_root', JS_DIR] + [ |
| '--externs=%s' % os.path.relpath(x) for x in |
| sorted(glob.glob(os.path.join(nassh.DIR, 'externs', '*.js')))] |
| closure_args = list(libdot.lint.DEFAULT_CLOSURE_ARGS) + externs + [ |
| # TODO(vapier): We want to turn this on at some point. |
| '--jscomp_off=strictMissingProperties', |
| os.path.relpath(DEPS_FILE)] |
| return libdot.lint.main(argv, basedir=nassh.DIR, |
| get_default_paths=_get_default_paths, mkdeps=mkdeps, |
| closure_args=closure_args) |
| |
| |
| if __name__ == '__main__': |
| sys.exit(main(sys.argv[1:])) |