You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to have an option that would allow me to only format a subset of a project. Typically this comes into play when making changes to a larger project which may either: 1. never have had formatting applied, or 2. was formatted using a different version of rustfmt with different rules, or 3. has components that do not format deterministically.
In these cases, a small change + a format can end up touching nearly every file (or large parts of a single file) in the project, which is not great for maintainers, as it makes it difficult to review changes.
Ideally, I would like to do something like this:
# check out the `master` branch of a project
git checkout <SOME PROJECT># make some changes
nano src/main.rs
# This part could be optional (if diffing against the working directory)
git checkout -b some-patch
git add .
git commit -m "This is a helpful patch!"# Now the magic
cargo fmt --only-changes-since-git-revision="master"
This would apply formatting changes ONLY to some subset of the code, probably one of the following:
Only the changed lines
Only the nearest block containing changed lines (e.g. function, closure, struct definition)
I am not familiar with the inner workings of rustfmt, and I saw the --file-lines option, however I couldn't find any docs regarding that, and I wasn't sure if it was possible (within rustfmt) to figure out how far a block stretches when a line number is specified.
If this sounds feasible, I would be interested in trying to work on this, if there is a mentor I can ask some spinning-up questions to.
Let me know what you think!
The text was updated successfully, but these errors were encountered:
Hey all,
It would be nice to have an option that would allow me to only format a subset of a project. Typically this comes into play when making changes to a larger project which may either: 1. never have had formatting applied, or 2. was formatted using a different version of rustfmt with different rules, or 3. has components that do not format deterministically.
In these cases, a small change + a format can end up touching nearly every file (or large parts of a single file) in the project, which is not great for maintainers, as it makes it difficult to review changes.
Ideally, I would like to do something like this:
This would apply formatting changes ONLY to some subset of the code, probably one of the following:
I am not familiar with the inner workings of
rustfmt
, and I saw the--file-lines
option, however I couldn't find any docs regarding that, and I wasn't sure if it was possible (within rustfmt) to figure out how far a block stretches when a line number is specified.If this sounds feasible, I would be interested in trying to work on this, if there is a mentor I can ask some spinning-up questions to.
Let me know what you think!
The text was updated successfully, but these errors were encountered: