Skip to content

Commit

Permalink
update prettier and clang-format cli options in format.py
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 21, 2024
1 parent a95796b commit 57da4c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
alias b := build
alias t := test
alias f := format

default:
@just --list
Expand All @@ -26,3 +27,8 @@ test *args="//...":

test-asan *args="//...":
just test {{args}} --config=asan

format:
clang-format -i src/workerd/**/*.c++ src/workerd/**/*.h
node_modules/.bin/prettier src --write --log-level=warn
ruff format .
11 changes: 7 additions & 4 deletions tools/cross/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def filter_files_by_exts(


def clang_format(files: List[str], check: bool = False) -> bool:
cmd = [CLANG_FORMAT, "--verbose"]
cmd = [CLANG_FORMAT]
if check:
cmd += ["--dry-run", "--Werror"]
else:
Expand All @@ -97,9 +97,13 @@ def clang_format(files: List[str], check: bool = False) -> bool:
def prettier(files: List[str], check: bool = False) -> bool:
cmd = [PRETTIER]
if check:
cmd.append("--check")
# This flag will only print files that require formatting
# and change exit code of the process depending on state.
cmd.append("--list-different")
else:
cmd.append("--write")
# This will only print files that requires formatting.
cmd.append("--log-level=warn")
result = subprocess.run(cmd + files)
return result.returncode == 0

Expand Down Expand Up @@ -164,10 +168,9 @@ class FormatConfig:
),
FormatConfig(
directory="src",
extensions=(".js", ".ts", ".cjs", ".ejs", ".mjs"),
extensions=(".js", ".ts", ".cjs", ".ejs", ".mjs", ".json"),
formatter=prettier,
),
FormatConfig(directory="src", extensions=(".json",), formatter=prettier),
FormatConfig(directory=".", extensions=(".py",), formatter=ruff),
# TODO: lint bazel files
]
Expand Down

0 comments on commit 57da4c0

Please sign in to comment.