summaryrefslogtreecommitdiff
path: root/tools/format.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/format.py')
-rwxr-xr-xtools/format.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/tools/format.py b/tools/format.py
index cb3b15a7e..b994535f7 100755
--- a/tools/format.py
+++ b/tools/format.py
@@ -1,8 +1,6 @@
#!/usr/bin/env python
-
import os
-from glob import glob
-from util import run
+from util import run, find_exts
root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
third_party_path = os.path.join(root_path, "third_party")
@@ -12,15 +10,19 @@ tools_path = os.path.join(root_path, "tools")
rustfmt_config = os.path.join(tools_path, "rustfmt.toml")
os.chdir(root_path)
-# TODO(ry) Install clang-format in third_party.
-run(["clang-format", "-i", "-style", "Google"] + glob("src/*.cc") +
- glob("src/*.h"))
-for fn in ["BUILD.gn", ".gn"] + glob("build_extra/**/*.gn*"):
- run(["gn", "format", fn])
+
+# TODO(ry) Use third_party/depot_tools/clang-format.
+run(["clang-format", "-i", "-style", "Google"] + find_exts("src", ".cc", ".h"))
+
+for fn in ["BUILD.gn", ".gn"] + find_exts("build_extra", ".gn", ".gni"):
+ run(["third_party/depot_tools/gn", "format", fn])
+
# TODO(ry) Install yapf in third_party.
-run(["yapf", "-i"] + glob("tools/*.py") + glob("build_extra/**/*.py"))
-run(["node", prettier, "--write"] + glob("js/*.js") + glob("js/*.ts") +
- ["tsconfig.json"] + ["tslint.json"])
+run(["yapf", "-i"] + find_exts("tools/", ".py") +
+ find_exts("build_extra", ".py"))
+
+run(["node", prettier, "--write"] + find_exts("js/", ".js", ".ts") +
+ ["tsconfig.json", "tslint.json"])
# Set RUSTFMT_FLAGS for extra flags.
rustfmt_extra_args = []
@@ -29,4 +31,4 @@ if 'RUSTFMT_FLAGS' in os.environ:
run([
"rustfmt", "--config-path", rustfmt_config, "--error-on-unformatted",
"--write-mode", "overwrite"
-] + rustfmt_extra_args + glob("src/*.rs"))
+] + rustfmt_extra_args + find_exts("src/", ".rs"))