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

improve the --file-lines help #5846

Merged

Conversation

richardmon
Copy link
Contributor

@richardmon richardmon commented Jul 19, 2023

This is something incredibly small but as someone new to using rustfmt I found the --file-lines example quite frustrating

rustfmt --file-lines '[
    {"file":"src/lib.rs","range":[7,13]},
    {"file":"src/lib.rs","range":[21,29]},
    {"file":"src/foo.rs","range":[10,11]},
    {"file":"src/foo.rs","range":[15,15]}]' 

This leads me to believe that the file is going to be taken based on the json I passed as an argument but that is not the case, it also need to the files that are going to be modified as extra parameters, so since this --help=file-lines represents a complete example the message should be something like this:

rustfmt --file-lines '[
    {"file":"src/lib.rs","range":[7,13]},
    {"file":"src/lib.rs","range":[21,29]},
    {"file":"src/foo.rs","range":[10,11]},
    {"file":"src/foo.rs","range":[15,15]}]' src/lib.rs src/foo.rs

@ytmimi
Copy link
Contributor

ytmimi commented Aug 3, 2023

@richardmon thanks for your first contribution to rustfmt 🎉

When you have a chance, can you rewrite the example like:

rustfmt src/lib.rs src/foo.rs --file-lines '[
    {"file":"src/lib.rs","range":[7,13]},
    {"file":"src/lib.rs","range":[21,29]},
    {"file":"src/foo.rs","range":[10,11]},
    {"file":"src/foo.rs","range":[15,15]}]'

I think it's a little cleaner if the file names come first. Besides that I'm happy to make this change. You also need to add the --unstable-features flag in order to use --file-lines, right?

@richardmon
Copy link
Contributor Author

Done!, thanks.

Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

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

IIRC it may not be necessary to explicitly provide src/foo.rs as an input file, provided the example src/lib.rs imports foo, but regardless I agree that while minor this is a helpful change

@calebcartwright calebcartwright merged commit 36af403 into rust-lang:master Aug 12, 2023
27 checks passed
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.

3 participants