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

Fix generated mod.rs to pass cargo fmt -- --check #622

Merged
merged 3 commits into from
May 6, 2022

Conversation

hanabi1224
Copy link
Contributor

Currently, the generated mod.rs does not pass cargo fmt -- --check, and this becomes a problem when ppl choose to include generated files as part of source code.

This PR tries to make rustfmt happy by adding an empty line after each 'pub mod' import. It also adds This file is generated by line to make mod.rs consistent with other files.

This closes #621

Copy link
Owner

@stepancheg stepancheg left a comment

Choose a reason for hiding this comment

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

Two comments, and also can you split PRs into unrelated issues please?

w.write_line("");
w.comment(&format!(
"This file is generated by {} {}. Do not edit",
env!("CARGO_PKG_NAME"),
Copy link
Owner

Choose a reason for hiding this comment

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

Code generator is not necessarily executed by cargo. See how similar code is inserted in other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION")
));
w.comment("@generated");
Copy link
Owner

Choose a reason for hiding this comment

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

That was

        w.comment(&format!("{}generated", "@"));

intentionally, so the generator is not considered to be generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted

for m in mods {
w.write_line("");
Copy link
Owner

@stepancheg stepancheg May 6, 2022

Choose a reason for hiding this comment

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

Now it writes a line between mods? Doesn't look right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The formatter won't sort mods when they are empty line delimited

Copy link
Owner

Choose a reason for hiding this comment

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

Wouldn't it be better to just sort mods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, if u prefer

@hanabi1224 hanabi1224 requested a review from stepancheg May 6, 2022 04:25
@stepancheg stepancheg merged commit 7131fb2 into stepancheg:master May 6, 2022
@stepancheg
Copy link
Owner

Thanks!

@hanabi1224 hanabi1224 deleted the mod-rs-pass-rustfmt-check branch May 6, 2022 05:57
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.

rustfmt is not skipped for generated mod.rs
2 participants