summaryrefslogtreecommitdiff
path: root/tools/lint.py
blob: cbef32ad5efcbeeda73b44e61274f864376f6fa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
# Does google-lint on c++ files and ts-lint on typescript files

import os
import sys
from util import enable_ansi_colors, git_ls_files, libdeno_path, root_path, run
from util import third_party_path
from third_party import python_env


def main():
    enable_ansi_colors()
    os.chdir(root_path)
    cpplint()
    eslint()
    pylint()


def cpplint():
    print "cpplint"
    script = os.path.join(third_party_path, "cpplint", "cpplint.py")
    source_files = git_ls_files(libdeno_path, ["*.cc", "*.h"])
    run([
        sys.executable,
        script,
        "--quiet",
        "--filter=-build/include_subdir",
        "--repository=" + libdeno_path,
        "--",
    ] + source_files,
        env=python_env(),
        shell=False,
        quiet=True)


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/prettier/vendor/*", ":!: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]
    run(["node", script, "--max-warnings=0", "--"] + source_globs,
        shell=False,
        quiet=True)


def pylint():
    print "pylint"
    script = os.path.join(third_party_path, "python_packages", "pylint")
    rcfile = os.path.join(third_party_path, "depot_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)


if __name__ == "__main__":
    sys.exit(main())