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-05-09 06:22:27 -04:00
|
|
|
from util import enable_ansi_colors, git_ls_files, git_staged, root_path, run
|
|
|
|
from util import third_party_path, build_mode, print_command
|
2019-09-11 16:47:42 -04:00
|
|
|
from third_party import python_env
|
2018-09-02 17:37:14 -04:00
|
|
|
|
2020-05-09 06:22:27 -04:00
|
|
|
cmd_args = None
|
2018-07-08 01:56:03 -04:00
|
|
|
|
2020-05-09 06:22:27 -04:00
|
|
|
|
|
|
|
def get_cmd_args():
|
|
|
|
global cmd_args
|
|
|
|
|
|
|
|
if cmd_args:
|
|
|
|
return cmd_args
|
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")
|
2020-05-09 06:22:27 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--staged", help="run only on staged files", action="store_true")
|
|
|
|
cmd_args = parser.parse_args()
|
|
|
|
return cmd_args
|
|
|
|
|
|
|
|
|
|
|
|
def get_sources(*args):
|
|
|
|
getter = git_staged if get_cmd_args().staged else git_ls_files
|
|
|
|
return getter(*args)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
enable_ansi_colors()
|
|
|
|
os.chdir(root_path)
|
|
|
|
|
|
|
|
args = get_cmd_args()
|
2020-02-27 14:30:41 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-10-05 07:29:55 -04:00
|
|
|
|
2019-09-14 10:25:49 -04:00
|
|
|
def 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.
|
2020-05-09 06:22:27 -04:00
|
|
|
source_files = get_sources(root_path, [
|
2020-06-09 12:40:08 -04:00
|
|
|
"*.js",
|
|
|
|
"*.ts",
|
|
|
|
":!:cli/tests/swc_syntax_error.ts",
|
|
|
|
":!:std/**/testdata/*",
|
|
|
|
":!:std/**/node_modules/*",
|
|
|
|
":!:cli/compilers/wasm_wrap.js",
|
|
|
|
":!:cli/tests/error_syntax.js",
|
|
|
|
":!:cli/tests/lint/**",
|
2020-08-03 17:39:48 -04:00
|
|
|
":!:cli/tests/encoding/**",
|
2020-07-22 12:03:46 -04:00
|
|
|
":!:cli/dts/**",
|
|
|
|
":!:cli/tsc/*typescript.js",
|
2020-08-28 09:03:50 -04:00
|
|
|
":!:cli/bench/node*.js",
|
2019-11-14 08:31:39 -05:00
|
|
|
])
|
2020-05-09 06:22:27 -04:00
|
|
|
if source_files:
|
2020-07-21 10:47:55 -04:00
|
|
|
max_command_len = 30000
|
|
|
|
pre_command = ["node", script, "--max-warnings=0", "--"]
|
|
|
|
chunks = [[]]
|
|
|
|
cmd_len = len(" ".join(pre_command))
|
|
|
|
for f in source_files:
|
|
|
|
if cmd_len + len(f) > max_command_len:
|
|
|
|
chunks.append([f])
|
|
|
|
cmd_len = len(" ".join(pre_command))
|
|
|
|
else:
|
|
|
|
chunks[-1].append(f)
|
|
|
|
cmd_len = cmd_len + len(f) + 1
|
|
|
|
for c in chunks:
|
|
|
|
print_command("eslint", c)
|
|
|
|
# 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(pre_command + c, shell=False, env=env, quiet=True)
|
2019-09-14 10:25:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
def 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")
|
2020-05-09 06:22:27 -04:00
|
|
|
msg_template = "{path}({line}:{column}) {category}: {msg} ({symbol})"
|
|
|
|
source_files = get_sources(root_path, ["*.py"])
|
|
|
|
if source_files:
|
|
|
|
print_command("pylint", source_files)
|
|
|
|
run([
|
|
|
|
sys.executable, script, "--rcfile=" + rcfile,
|
|
|
|
"--msg-template=" + msg_template, "--"
|
|
|
|
] + source_files,
|
|
|
|
env=python_env(),
|
|
|
|
shell=False,
|
|
|
|
quiet=True)
|
2019-09-14 10:25:49 -04:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2019-09-14 10:25:49 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|