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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Format all encountered modules recursively, including those defined in external files.
calebcartwright marked this conversation as resolved.
Show resolved Hide resolved

- **Default value**: `false`
- **Possible values**: `true`, `false`
- **Stable**: Yes

## `remove_nested_parens`

Remove nested parens.
Expand Down
20 changes: 19 additions & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ fn make_opts() -> Options {
"Don't reformat child modules (unstable).",
);
}

opts.optflag(
"r",
"recursive",
"Format all encountered modules recursively, including those defined in external files.",
);
opts.optflag("v", "verbose", "Print verbose output");
opts.optflag("q", "quiet", "Print less output");
opts.optflag("V", "version", "Show version information");
Expand Down Expand Up @@ -500,6 +504,7 @@ const STABLE_EMIT_MODES: [EmitMode; 3] = [EmitMode::Files, EmitMode::Stdout, Emi
#[derive(Clone, Debug, Default)]
struct GetOptsOptions {
skip_children: Option<bool>,
recursive: Option<bool>,
quiet: bool,
verbose: bool,
config_path: Option<PathBuf>,
Expand Down Expand Up @@ -568,6 +573,16 @@ impl GetOptsOptions {
}
}

if matches.opt_present("recursive") {
if let Some(true) = options.skip_children {
return Err(format_err!(
"Conflicting options `skip_children` and `recursive` were specified. \
`skip_children` has been deprecated and should no longer be used. ",
));
}
options.recursive = Some(true);
}

options.config_path = matches.opt_str("config-path").map(PathBuf::from);

options.inline_config = matches
Expand Down Expand Up @@ -658,6 +673,9 @@ impl CliOptions for GetOptsOptions {
if let Some(skip_children) = self.skip_children {
config.set().skip_children(skip_children);
}
if let Some(recursive) = self.recursive {
config.set().recursive(recursive);
}
if let Some(error_on_unformatted) = self.error_on_unformatted {
config.set().error_on_unformatted(error_on_unformatted);
}
Expand Down
Loading