1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/tools/lint.py

84 lines
2.5 KiB
Python
Raw Normal View History

2018-07-08 01:56:03 -04:00
#!/usr/bin/env python
2020-01-02 15:13:47 -05:00
# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2018-07-08 01:56:03 -04:00
# Does google-lint on c++ files and ts-lint on typescript files
import os
2018-11-30 03:27:41 -05:00
import sys
2020-02-27 14:30:41 -05:00
import argparse
2020-01-05 09:19:29 -05:00
from util import enable_ansi_colors, git_ls_files, root_path, run
2020-02-27 14:30:41 -05:00
from util import third_party_path, build_mode
from third_party import python_env
2018-07-08 01:56:03 -04:00
def main():
enable_ansi_colors()
os.chdir(root_path)
2020-02-27 14:30:41 -05:00
parser = argparse.ArgumentParser()
parser.add_argument("--js", help="run eslint", action="store_true")
parser.add_argument("--py", help="run pylint", action="store_true")
parser.add_argument("--rs", help="run clippy", action="store_true")
args = parser.parse_args()
did_fmt = False
if args.js:
eslint()
did_fmt = True
if args.py:
pylint()
did_fmt = True
if args.rs:
clippy()
did_fmt = True
if not did_fmt:
eslint()
pylint()
clippy()
2018-07-08 01:56:03 -04:00
def eslint():
print "eslint"
script = os.path.join(third_party_path, "node_modules", "eslint", "bin",
"eslint")
# Find all *directories* in the main repo that contain .ts/.js files.
source_files = git_ls_files(root_path, [
"*.js", "*.ts", ":!:std/**/testdata/*", ":!:std/**/node_modules/*",
":!:cli/compilers/*"
])
source_dirs = set([os.path.dirname(f) for f in source_files])
# Within the source dirs, eslint does its own globbing, taking into account
# the exclusion rules listed in '.eslintignore'.
source_globs = ["%s/*.{js,ts}" % d for d in source_dirs]
2020-02-25 15:33:19 -05:00
# Set NODE_PATH so we don't have to maintain a symlink in root_path.
env = os.environ.copy()
env["NODE_PATH"] = os.path.join(root_path, "third_party", "node_modules")
run(["node", script, "--max-warnings=0", "--"] + source_globs,
shell=False,
2020-02-25 15:33:19 -05:00
env=env,
quiet=True)
def pylint():
print "pylint"
script = os.path.join(third_party_path, "python_packages", "pylint")
2020-01-05 09:19:29 -05:00
rcfile = os.path.join(root_path, "tools", "pylintrc")
source_files = git_ls_files(root_path, ["*.py"])
run([sys.executable, script, "--rcfile=" + rcfile, "--"] + source_files,
env=python_env(),
shell=False,
quiet=True)
2020-02-27 14:30:41 -05:00
def clippy():
print "clippy"
current_build_mode = build_mode()
args = ["cargo", "clippy", "--all-targets", "--locked"]
if current_build_mode != "debug":
args += ["--release"]
run(args + ["--", "-D", "clippy::all"], shell=False, quiet=True)
if __name__ == "__main__":
sys.exit(main())