Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust_fmt #634

Closed
tschuett opened this issue Mar 16, 2021 · 4 comments · Fixed by #722
Closed

rust_fmt #634

tschuett opened this issue Mar 16, 2021 · 4 comments · Fixed by #722

Comments

@tschuett
Copy link

Are there any plans to add a rust_fmt rule?

rust_fmt(
  name = "format_library",
  deps = [
    ":bar",
    ":foo",
    ],
)

There is a basic example:
https://github.com/bazelbuild/rules_rust/tree/main/test/rustfmt

@UebelAndre
Copy link
Collaborator

#87 sounds relevant to this request

@tschuett
Copy link
Author

tschuett commented Mar 17, 2021

After reading the other issues, I like the idea of modelling it as test:

rust_test_fmt(
  name = "test_format",
  deps = [
    ":bar",
    ":foo",
   ]
)
bazel test :test_format

@hlopko
Copy link
Member

hlopko commented Mar 18, 2021

I haven't looked into other issues (is it just #87 or others as well?), and I only skimmed through the implementation, but my knee jerk proposal would be to implement the rust_fmt as an aspect and then it would be used by for example running bazel build --aspects @rules_rust//rust:defs.bzl%rust_fmt_aspect //foo/bar (there will need to be --experimental_run_validations also but that's only until Bazel stabilizes that feature).

If the source file is not formatted correctly, the build would fail. Advantage over deps approach in my perspective is that you don't have to specify which libraries to cover (which people can forget to do), you just enable the aspect on the CI for the regular test suite run (which usually has //... so it automatically covers everything).

Pardon my ignorance, but does rust-analyzer use rustfmt, or it implements formatting by itself? If it has its own implementation then there will be differences, and that will cause trouble. In that case I'd vote for using rust-analyzer for formatting (if it can be done), not rustfmt (I'm a big fan of rust-analyzer as you can tell :).

@tschuett
Copy link
Author

There was also: #388.

I use the following to assert that nothing changed

git diff --exit-code --summary --stat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants