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 8640269 commit 6964ab8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 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,7 @@ 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
11 changes: 7 additions & 4 deletions tools/cross/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 @@ -95,9 +95,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 @@ -143,10 +147,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),
# TODO: lint bazel files
]

Expand Down

0 comments on commit 6964ab8

Please sign in to comment.