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

Provide mechanism to opt out of cargo fmt #60

Open
cottsay opened this issue Feb 24, 2025 · 1 comment
Open

Provide mechanism to opt out of cargo fmt #60

cottsay opened this issue Feb 24, 2025 · 1 comment
Labels
question Further information is requested

Comments

@cottsay
Copy link
Member

cottsay commented Feb 24, 2025

It isn't currently possible to pass colcon test on a cargo package which doesn't conform to cargo fmt. Although I certainly think that declaring and aligning with a standard code formatter is probably a good idea, I don't think it should be something we should force package developers to do.

In other colcon packages we optionally add extra functionality during the test job by looking at the dependencies the package has declared. For example, if a package has a dependency on pytest-cov, we automatically enable code coverage. Unfortunately I don't see a way to do that here. I thought that maybe we could add rustfmt to the dev-dependencies if we wanted to enable the format check, but as I understand it, the crate dependencies are exclusively for libraries so it isn't appropriate (or possible?) to use dev-dependencies for this.

The best I can come up with is that we should only implicitly run cargo fmt if we find a rustfmt.toml or .rustfmt.toml in any directories up the tree, following the behavior of rustfmt itself for configuration discovery. If a developer wants to implicitly enable cargo fmt for all packages in their workspace, they can place an empty rustfmt config file in their workspace.

Hoping for feedback from rust developers on this.

@cottsay cottsay added the question Further information is requested label Feb 24, 2025
@mxgrey
Copy link
Contributor

mxgrey commented Feb 25, 2025

One option could be to take advantage of the [package.metadata] section of Cargo.toml.

E.g. we could have

[package.metadata.colcon]
rustfmt = true

to tell colcon that this package wants its format to be tested.

I think there are probably a substantial number of packages that would want their format tested but don't contain a .rustfmt.toml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

2 participants