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

switch to non-recursive mode by default #3938

Merged
merged 4 commits into from
Dec 9, 2019

Conversation

calebcartwright
Copy link
Member

@calebcartwright calebcartwright commented Nov 22, 2019

Resolves #3587 and refs #3887

This PR updates the default mode of rustfmt to not format submods in external files, with an accompanying new CLI arg (--recursive)/config option to enable recursive submod formatting mode (which was the default behavior of rustfmt 1.x).

cargo fmt behavior remains unchanged, as cargo fmt will automatically pass the --recursive flag to rustfmt.

I went ahead and marked the new recursive config option as stable because it is relatively simple. Also because it would be pretty weird IMO if both recursive and skip_children were only available on nightly, especially with skip_children now deprecated (that would make it impossible to format sub mods on stable).

Lastly, I did a bit of refactoring in cargo fmt to consolidate/simplify the adding of args to rustfmt (for example the transformation of --message-format to --emit .. for rustfmt, --check, etc.) which had been discussed on some earlier threads.

Configurations.md Outdated Show resolved Hide resolved
src/bin/main.rs Outdated Show resolved Hide resolved
src/cargo-fmt/main.rs Outdated Show resolved Hide resolved
src/bin/main.rs Outdated Show resolved Hide resolved
@calebcartwright
Copy link
Member Author

Thanks for the feedback @scampi!

Copy link
Contributor

@topecongiro topecongiro left a 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 PR!

@@ -1720,6 +1720,14 @@ fn example() {
}
```

## `recursive`
Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider recursive as one of the internal options. We do not want users to add this to the configuration by themselves.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do 👍, though out of curiosity, why should this be a CLI only flag for users?

One downside I see with exposing recursive as a config option is that recursive = false in the config file would functionally be ignored when using cargo fmt since cargo fmt will always pass --recursive flag to rustfmt which will always take precedence over the config file value (which could be confusing for users).

Copy link
Contributor

Choose a reason for hiding this comment

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

The options in the configuration file are meant to be persistent, whereas recursive is more of a one-shot configuration, which best suits as a CLI flag.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense to me! It wouldn't surprise me if there is a future request to support recursive as a config option since skip_children was available, but there's clearly several good reasons why recursive should be internal/cli-only.

Side note, while making recursive internal I noticed that internal options added to the config file seem to just be silently ignored. Do I have that correct?

If they are silently ignored:

Is that the desired behavior or would it beneficial to emit a warning ("Warning: Unknown configuration option ..)? Would that potential change be tackled (perhaps it already is) as part of #3873 or should I open a new issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

Side note, while making recursive internal I noticed that internal options added to the config file seem to just be silently ignored. Do I have that correct?

Yes.

Is that the desired behavior or would it beneficial to emit a warning ("Warning: Unknown configuration option ..)?

We should make it to a hard error rather than silently ignoring it.

Would that potential change be tackled (perhaps it already is) as part of #3873 or should I open a new issue?

This should be fixed by #3873.

Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

My apologies for the late review. LGTM, thank you for the update!

@topecongiro topecongiro merged commit 0a6a7d6 into rust-lang:master Dec 9, 2019
@calebcartwright calebcartwright deleted the non-recursive-default branch December 11, 2019 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Change the default behavior of rustfmt to not to format sub-modules
4 participants