Skip to content

refactor: use format_multirun on CI#5227

Open
alexeagle wants to merge 12 commits into
mainfrom
alexeagle/rules_lint
Open

refactor: use format_multirun on CI#5227
alexeagle wants to merge 12 commits into
mainfrom
alexeagle/rules_lint

Conversation

@alexeagle

@alexeagle alexeagle commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator

Change the CI script lint.yml to run bazel run format.

It is more correct, finding files that apparently were missed by the format.py setup.

@anonrig yes the .zed and .vscode settings are unchanged, the labels we refer to are the same (still runs /path/to/workerd/bazel-bin/build/deps/formatters/clang-format --help for example)

After this lands, next steps will be:

  • switch the pre-commit hook to the new approach
  • remove tools/cross/format.py which leaks a "you have to install python3" instruction, because it's not hermetic
  • ensure developers are still having a good time

@anonrig anonrig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make sure .zed settings are correct?

@alexeagle

Copy link
Copy Markdown
Collaborator Author

I don't know how to tell what settings are correct, if CI is green that's all I can go on. How many editors are officially supported here?

@anonrig

anonrig commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

I don't know how to tell what settings are correct, if CI is green that's all I can go on. How many editors are officially supported here?

zed settings json contains formatter code for every language since we don't want to run bazel run format on a single file. can you make sure the bazel run commands are updated as well? we support vscode and zed.

alexeagle added a commit that referenced this pull request Oct 3, 2025
This provides a shorter and more standard way to invoke formatters for all languages.
rules_lint is widely adopted and has many companies contributing.

Subset of #5227 to rollout in smaller steps
@alexeagle

Copy link
Copy Markdown
Collaborator Author

#5235 picks out the first part of this that can land independently

fhanau pushed a commit that referenced this pull request Oct 24, 2025
This provides a shorter and more standard way to invoke formatters for all languages.
rules_lint is widely adopted and has many companies contributing.

Subset of #5227 to rollout in smaller steps

code review feedback

add prettier
fhanau pushed a commit that referenced this pull request Oct 24, 2025
This provides a shorter and more standard way to invoke formatters for all languages.
rules_lint is widely adopted and has many companies contributing.

Subset of #5227 to rollout in smaller steps

code review feedback

add prettier
fhanau pushed a commit that referenced this pull request Oct 24, 2025
This provides a shorter and more standard way to invoke formatters for all languages.
rules_lint is widely adopted and has many companies contributing.

Subset of #5227 to rollout in smaller steps

code review feedback

add prettier
fhanau pushed a commit that referenced this pull request Oct 24, 2025
This provides a shorter and more standard way to invoke formatters for all languages.
rules_lint is widely adopted and has many companies contributing.

Subset of #5227 to rollout in smaller steps

code review feedback

add prettier
@alexeagle alexeagle force-pushed the alexeagle/rules_lint branch 2 times, most recently from c969d5d to 7abe0b1 Compare October 27, 2025 02:00
@alexeagle alexeagle changed the title feat: use rules_lint to provide formatters refactor: use format_multirun on CI Oct 27, 2025
@alexeagle alexeagle marked this pull request as ready for review October 27, 2025 02:01
@alexeagle alexeagle requested review from a team as code owners October 27, 2025 02:01
@alexeagle alexeagle force-pushed the alexeagle/rules_lint branch 2 times, most recently from a467ddf to f8fc3f8 Compare October 27, 2025 02:02
Comment thread samples/durable-objects-chat/chat.js Fixed
Comment thread types/src/transforms/import-resolve.ts Fixed
@github-actions

github-actions Bot commented Oct 27, 2025

Copy link
Copy Markdown

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@alexeagle alexeagle force-pushed the alexeagle/rules_lint branch from f1f1a10 to 09992a8 Compare October 27, 2025 16:37
@codspeed-hq

codspeed-hq Bot commented Oct 27, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #5227 will improve performances by 12.34%

Comparing alexeagle/rules_lint (f23f953) with main (df1cafa)

Summary

⚡ 1 improvement
✅ 33 untouched
⏩ 9 skipped1

Benchmarks breakdown

Benchmark BASE HEAD Change
simpleStringBody[Response] 22.4 µs 20 µs +12.34%

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@fhanau

fhanau commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

I'm pretty swamped atm, but will try to get to this PR later this week. It seems pretty big though – maybe we can factor out the changes that result in significantly expand reformatting to another PR so that the reviewers can focus on the more interesting changes of moving formatting to bazel?

@fhanau

fhanau commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

Changes mostly LGTM.
- Where do we opt in to formatting json? It is not in //build/deps/formatters:format.check, I think it's important for developers to understand for which languages linting is enabled.
- Why is there a difference in the JS/TS formatting compared to what we had before? Looks like most of it is replace double quotes with single quotes, that's the main reason the diff is so large here.

@alexeagle

Copy link
Copy Markdown
Collaborator Author

Where do we opt in to formatting json?

https://registry.bazel.build/docs/aspect_rules_lint/1.10.2#rule-languages
"Some languages have dialects:

  • javascript includes TypeScript, TSX, and JSON."

I dunno why you weren't formatting those files before, I suspect it's not a good use of my consulting hours to study the legacy formatting script. I can exclude them from this PR if you prefer.

@npaun

npaun commented Nov 4, 2025

Copy link
Copy Markdown
Member

Yeah, I'd personally make sure that this change isn't modifying any formatting, just keeping the existing behaviour. We can fix any inconsistencies in what's included in a follow-up PR.

Another question: Can we create a target that lets us format just one language at a time? e.g. if I want to format only C++ files?

@alexeagle

Copy link
Copy Markdown
Collaborator Author

@npaun okay - looks like the reason so many files in the repo aren't formatted is you only applied https://github.com/cloudflare/workerd/pull/3054/files to the src/ directory. Do you recall what was the reasoning for that? Perhaps we should pre-factor to have the existing formatters apply to the whole repo, then switch to Bazel running them.

Alternatively I can figure a way for Bazel to also ignore clang-format and prettier outside the src/ folder if there's a reason it needs to be this way.

@anonrig

anonrig commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

I think we can just format the whole repository. I don't think there is a particular reason why we didn't do the whole repo...

@alexeagle

Copy link
Copy Markdown
Collaborator Author

I added a .gitattributes file so we can note the ones which aren't enforced yet. Then in a post-factoring we can burn this down one chunk at a time.

@fhanau

fhanau commented Nov 4, 2025

Copy link
Copy Markdown
Contributor
  • justfile and githooks need to be updated to the new format to avoid breaking developer workflows

@npaun

npaun commented Nov 4, 2025

Copy link
Copy Markdown
Member

Can we create a target that lets us format just one language at a time? e.g. if I want to format only C++ files?

@fhanau

fhanau commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Can we create a target that lets us format just one language at a time? e.g. if I want to format only C++ files?

I believe we get this for free – there are targets like //build/deps/formatters:format_C++_with_clang-format being configured based on running bazel cquery. For usability, we just need to add aliases to e.g. //build/deps/formatters:run_clang_format and document those.

@fhanau fhanau force-pushed the alexeagle/rules_lint branch from bd1a9fb to 075ba8e Compare November 4, 2025 17:43
@alexeagle

Copy link
Copy Markdown
Collaborator Author

Added

alias(
    name = "run_clang_format",
    actual = ":format_C++_with_clang-format",
)

@fhanau I intentionally changed only the GHA flow in this PR, my hope is to vet it before we change justfile or githooks. Those run the exact same tooling with the same configuration so nothing should be broken.

If you want though I can add that to this PR.

Remove custom install of buildifier, which comes more easily from BCR
@npaun

npaun commented Nov 4, 2025

Copy link
Copy Markdown
Member

I'm not Felix, but I'd do the justfile and githooks now in this PR.

ketanhwr pushed a commit that referenced this pull request Nov 13, 2025
This provides a shorter and more standard way to invoke formatters for all languages.
rules_lint is widely adopted and has many companies contributing.

Subset of #5227 to rollout in smaller steps

code review feedback

add prettier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants