Skip to content

Commit cdbe33a

Browse files
redsun82Copilot
andcommitted
Just: cut format.just's comments back to what the code cannot say
The file had grown 45 lines of comment around 29 of code, most of it restating what is visible or belonging in the README. What is left is the part a reader cannot recover: why the buildifier target is bypassed, why the two exclusion lists must stay in step, and what silently breaks if `[no-cd]` is dropped. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 2ec54c8 commit cdbe33a

1 file changed

Lines changed: 14 additions & 44 deletions

File tree

misc/just/format.just

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,31 @@ _py_formatter := if SEMMLE_CODE != "" { "uv run black" } else { "black" }
66

77
_cpp_formatter := if SEMMLE_CODE != "" { "uv run clang-format" } else { "clang-format" }
88

9-
# The `buildifier` bazel target always covers the whole workspace, so the binary it wraps
10-
# is used instead and given paths. Naming that binary by its external label rather than
11-
# through a local alias keeps it valid from any workspace. bazel is asked from the root of
12-
# this repository, even when it sits inside another, and the files are bounded to that root
13-
# as well: each repository then formats its own bazel files with the buildifier version it
14-
# pins, and a verb aimed at a tree spanning both is answered once by each. This is the
15-
# opposite of building, where a target needs the enclosing workspace to resolve at all,
16-
# hence `_bazel` in build.just going the other way.
9+
# The `buildifier` target formats a whole workspace and so cannot take a path, so its
10+
# binary is driven directly. bazel is asked from this repository's root even when it sits
11+
# inside another, and the files are bounded to it, so each repository formats its own with
12+
# the version it pins. Building needs the enclosing workspace instead, hence `_bazel`.
1713
_bazel_workspace := quote(parent_directory(parent_directory(source_dir())))
1814

19-
# As with the formatters above, an internal repository checkout has its own launcher and
20-
# that is the one to use. Unlike `_bazel` in build.just it is not `cd`ed to: the workspace
21-
# is picked by `--chdir` below, so the launcher only has to be found, not entered.
2215
_bazel_formatter := (if SEMMLE_CODE != "" { '"$SEMMLE_CODE/tools/bazel"' } else { "bazel" }) + " run --noshow_progress --ui_event_filters=,+error,+fail @buildifier_prebuilt//:buildifier --"
2316

24-
# bazel files are named rather than suffixed, and buildifier has no exclude option of its
25-
# own, so the files skipped by the target above are skipped here too. That target formats
26-
# the whole workspace at once and so cannot take the path this recipe is given, which is
27-
# why the two run the same binary through different entry points. Their exclusions are
28-
# therefore stated twice, in two places, in two syntaxes: keep them in step, or `just
29-
# format` rewrites what pre-commit and CI deliberately leave alone.
30-
#
31-
# bazel knows `BUILD` and `WORKSPACE` by those names and everything else by the `.bazel`
32-
# extension, so a file named `BUILD.<anything>` else is a template or a generator's input
33-
# rather than a bazel file, and is none of the formatter's business to parse.
34-
#
35-
# Both lists are comma-separated, so a root defining its own `_root_format` can name
36-
# several patterns in one variable. It has no need to repeat the ones here: the files
37-
# they cover belong to this repository, which formats them itself. Exclusions match the
38-
# path as walked rather than as spelled on the command line, so one naming a directory
39-
# has to cover both the path it is reached by and the path it is walked from.
40-
#
41-
# As with the QL formatter, buildifier only names what it rewrote if it also accounts for
42-
# every file it did not, so that accounting is dropped. It counts the warnings it could
43-
# not fix there, which are left for linting to report rather than raised on every format.
17+
# Keep in step with the `buildifier` target's own exclusions, or `just format` rewrites
18+
# what pre-commit and CI deliberately leave alone. Patterns match the path as walked, so
19+
# one naming a directory has to cover both how it is reached and how it is walked.
4420
_bazel_names := "BUILD,WORKSPACE,*.bazel,*.bzl,*.sky"
4521

4622
_bazel_excluded := ".git/*,*/.git/*,*misc/bazel/3rdparty/*_deps/*"
4723

24+
# buildifier only names what it rewrote if it also accounts for every file it did not.
4825
_bazel_accounting := ': applied fixes, [0-9]+ warnings left$'
4926

50-
# `codeql query format` and `clang-format` take files rather than directories, so the
51-
# files are collected by `run_on_files.py`. Arguments are passed positionally so that
52-
# paths containing spaces survive, of which this repository has many.
53-
#
54-
# The files that were rewritten are worth reporting, but `codeql query format` only
55-
# names those once it also names every file it leaves alone, which buries them under
56-
# thousands of lines. So it is asked for all of it and the lines about files it did not
57-
# touch are dropped. Only those are dropped, so errors still come through, as does
58-
# anything unforeseen.
27+
# These formatters take files rather than directories, so `run_on_files.py` collects them
28+
# and passes them positionally, which is what lets paths contain spaces. `codeql query
29+
# format` likewise only reports what it rewrote if it also names everything it did not, so
30+
# those lines are dropped and nothing else is.
5931
#
60-
# `[no-cd]` is what keeps a relative argument meaning the directory the caller is in.
61-
# The forwarder reaches a recipe above its argument with `--justfile`, which otherwise
62-
# runs it from that justfile's own directory: dropping the attribute would silently turn
63-
# the default `.` into the whole repository, and the only symptom would be slowness.
32+
# `[no-cd]` keeps a relative argument meaning the caller's directory: the forwarder passes
33+
# `--justfile`, so without it the default `.` would silently become the whole repository.
6434

6535
[no-cd]
6636
[no-exit-message]

0 commit comments

Comments
 (0)