-
Notifications
You must be signed in to change notification settings - Fork 910
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
feat: add ignore_missing_submod option #5611
base: master
Are you sure you want to change the base?
feat: add ignore_missing_submod option #5611
Conversation
Thanks for your first contribution to rustfmt 🎉. Always great to see new contributors. I won't have a chance to review this today, but I'll be sure to give feedback once I take a look! |
tests/source/issue-5609.rs
Outdated
// rustfmt-config: issue-5609.toml | ||
// rustfmt-ignore_missing_submod: true | ||
|
||
mod missing_submod; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source
file actually isn't necessary either. Since we're not doing any formatting to the file the target
file is enough for this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, on second thought, I think keeping the source
test is good to demonstrate that formatting is still happening. Can we explicitly set skip_children=false
. skip_children=false
is the current default, and when this is set we'll try to resolve sub modules. Again, this is the current default, but formatting would work just as well if skip_children=true
, since we then wouldn't try to recursively resolve children, and therefore the ignore_missing_submod
option wouldn't have any affect.
In case we change the default behavior of skip_children
to be true
in the future explicitly setting false
will ensure this test keeps working as intended.
src/config/mod.rs
Outdated
@@ -173,6 +173,7 @@ create_config! { | |||
or they are left with trailing whitespaces"; | |||
ignore: IgnoreList, IgnoreList::default(), false, | |||
"Skip formatting the specified files and directories"; | |||
ignore_missing_submod: bool, false, true, "Ignore missing submodule error"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All new options are unstable by default. Can you please change this to:
ignore_missing_submod: bool, false, true, "Ignore missing submodule error"; | |
ignore_missing_submod: bool, false, false, "Ignore missing submodule error"; |
Can we also add the following tests to #[test]
fn ignore_missing_sub_mod_false() {
// Ensure that missing submodules cause module not found errors when trying to
// resolve submodules with `skip_children=false` and `ignore_missing_submod=false`
let args = [
"--config=skip_children=false,ignore_missing_submod=false",
"tests/source/issue-5609.rs"
];
let (_stdout, stderr) = rustfmt(&args);
// Module resolution fails because we're unable to find `missing_submod.rs`
assert!(stderr.contains("missing_submod.rs does not exist"))
}
#[test]
fn ignore_missing_sub_mod_true() {
// Ensure that missing submodules don't cause module not found errors when trying to
// resolve submodules with `skip_children=false` and `ignore_missing_submod=true`.
let args = [
"--emit=stdout",
"--config=skip_children=false,ignore_missing_submod=true",
"tests/source/issue-5609.rs"
];
let (stdout, _stderr) = rustfmt(&args);
let target = read_to_string(PathBuf::from("tests/target/issue-5609.rs")).unwrap();
assert!(stdout.ends_with(&target));
} The more important of the two is |
Configurations.md
Outdated
@@ -1288,6 +1288,14 @@ If you want to ignore every file under the directory where you put your rustfmt. | |||
ignore = ["/"] | |||
``` | |||
|
|||
## `ignore_missing_submod` | |||
|
|||
Ignore missing submodule error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to elaborate on this description. I think we should explain that normally missing modules will lead to module not found errors and rustfmt won't format anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Most of the messages you wrote are used, but I added "By default" at the beginning of the sentence to clarify the behavior by default.
Configurations.md
Outdated
|
||
- **Default value**: `false` | ||
- **Possible values**: `true`, `false` | ||
- **Stable**: Yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All new options are unstable by default, so we'll need to update this. We don't need to create a tracking issue for the option just yet, but we'll need to mark this as unstable.
Thank you for your review. All fixed. |
@tanzaku I know this one has been left on the backlog for a little while. I wanted to check back in and see if you were still interested in working on it. |
Yes, I am still interested in working on it. |
Awesome! I wanted to confirm that before jumping back in. When you have a chance, can you rebase on the latest master and fix any merge conflicts. |
03a5767
to
50e7197
Compare
@ytmimi Sorry, I forgot to post earlier. I've rebased and resolved the conflicts. |
Thank you, I'll give this one another review later today! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, I wanted to say thank you for your patience. I know this was left on the backlog for quite a while, and I'm glad that you're still interested in helping out with this one.
Overall, I think the implementation that you've put together would work if we went with a boolean option, however the team has had some discussions about shifting our error reporting towards an Error
, Warn
, and Ignore
model. Given that we're likely heading in this direction for our other error reporting I'd really like to apply those variants to this new configuration option.
Configurations.md
Outdated
- **Default value**: `false` | ||
- **Possible values**: `true`, `false` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On thing the team has discussed is moving away from a binary error model. I think if we land this, I'd like to change from true
and false
to something like Warn
, Error
, Ignore
. With that in mind I think it a more appropriate name would be something like report_missing_submod
. Let me know if you can come up with anything better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update Configuration.md on this commit. 4bb0453
src/modules.rs
Outdated
.or_else(|err| match err.kind { | ||
ModuleResolutionErrorKind::NotFound { file: _ } | ||
if self.ignore_missing_submod => | ||
{ | ||
Ok(None) | ||
} | ||
_ => Err(err), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to rework this with Error
, Warn
, and Ignore
variants in mind. I think the only difference is that if Warn
is set we'll emit an error message, but still continue with Ok(None)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review! When emitting a message for a 'warn', is it sufficient to simply use eprintln!
to output to stderr? Or is there a more appropriate method you could suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. f678369
For now, I implemented direct output with eprintln.
(However, I think I might be better off using FormatReport.)
@@ -200,3 +200,30 @@ fn rustfmt_emits_error_when_control_brace_style_is_always_next_line() { | |||
let (_stdout, stderr) = rustfmt(&args); | |||
assert!(!stderr.contains("error[internal]: left behind trailing whitespace")) | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will likely need to rework the tests slightly to accommodate Error
, Warn
, and Ignore
variants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed test on this commit. fcc06f9
Thanks for pushing those changes. Just wanted to follow up and say that I'm planning to look at this one again later this week! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had a chance to look this over again and test out these changes locally. Things are working great! Thank you again for your help here. Marking this one as ready-to-merge, but will hold off on merging this one right away to give @calebcartwright a chance to look it over.
Resolve #5609
Made the changes suggested by ytmimi in issue #5609.
This is my first contribution, so I may have made some mistakes. I would be happy to fix them if you point them out.