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

config printing enhancements #6256

Open
calebcartwright opened this issue Jul 28, 2024 · 2 comments
Open

config printing enhancements #6256

calebcartwright opened this issue Jul 28, 2024 · 2 comments

Comments

@calebcartwright
Copy link
Member

rustfmt currently provides the ability to print configuration details in various forms:

  • default (documented briefly here) which dumps the full set of configuration options with their default values, regardless any existing detected or specified configuration inputs
  • current - dumps the configuration incorporating specified and detected values (e.g. any additionally included command line flags, detected configuration files, etc.)
  • minimal - the subset of the configurations from current that are actively utilized when formatting some specified input code/file (the primary use case for this is to help users locate unused/inoperable options and to be able to remove them from their rustfmt config file)

in #6247 there was some discussion about potential enhancements to this current configuration printing feature, and I'd suggest there's two potential (non mutually exclusive) items we could consider:

  • show the full set of configuration options with the default values based on the specified style edition
  • show the subset of configuration options that changed for a specified style edition
@calebcartwright
Copy link
Member Author

show the full set of configuration options with the default values based on the specified style edition

This could technically be obtained via the existing current variant in some situations (but not always). I think there's value in being able to do this explicitly in all situations, so I'd support a future enhancement that enabled this use case/capability.

However, I would be firmly opposed to modifying the existing behavior of the default variant for a few reasons:

  • it would break the existing behavior and drop support of "just give me rustfmt's defaults regardless of any other input"
  • it would create confusing behavior

One example of the confusing behavior relates to RFC 3338 which dictates that:

By default, rustfmt and cargo fmt will use the same edition for style as the Rust edition used for parsing

which means that, unless a style edition is otherwise explicitly specified, rustfmt will use the same edition of the style guide that it does for parsing, i.e. rustfmt foo.rs --edition 2024 ... is analogous to rustfmt foo.rs --style-edition 2024 ...

today the output of rustfmt --edition 2024 --print-config default will include edition = "2015" (remember that default is explicitly outputting defaults, independent of inputs).

however, the inclusion of RFC 3338 meaning that the --edition 2024 flag is the same as --style-edition 2024 which means that the output of this command would (a) change from what it's always printed (as the 2024 style edition has different defaults) and (b) would either require additional changes or the output would be confusing, e.g. what should the edition = ? value be?)

in my opinion, the best path forward to support this would be a new variant on the --print-config behavior, one that just directly adds the ability to display the config defaults for a specified style edition

@calebcartwright
Copy link
Member Author

show the subset of configuration options that changed for a specified style edition

This seems useful as well, though it's also something I'd prefer to see as a net new variant/feature instead of trying to mash it into one of the existing ones

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

No branches or pull requests

1 participant