diff --git a/justfile b/justfile index 0e280b45fdb..ee80fd7ff7c 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,6 @@ alias b := build alias t := test +alias f := format default: @just --list @@ -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 . diff --git a/tools/cross/format.py b/tools/cross/format.py index 5825a06e190..38299c7da0a 100644 --- a/tools/cross/format.py +++ b/tools/cross/format.py @@ -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: @@ -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 @@ -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 ]