Skip to content

--print-config minimal doesn't work as advertised #2758

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

Closed
tchajed opened this issue Jun 1, 2018 · 4 comments · Fixed by #3687
Closed

--print-config minimal doesn't work as advertised #2758

tchajed opened this issue Jun 1, 2018 · 4 comments · Fixed by #3687
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@tchajed
Copy link

tchajed commented Jun 1, 2018

What I tried:
(1) rustfmt --print-config minimal .rustfmt.toml
(2) rustfmt --print-config minimal .rustfmt.toml src/lib.rs

What I expected:
Invocation (1) should have produced a minimal configuration in .rustfmt.toml based on settings from the current directory, without formatting anything.
Invocation (2) should have done something similar, but only incorporating src/lib.rs.

What actually happened:
The PATH following --print-config minimal is both the path to the minimal config and the file to run rustfmt on. So, the first complains the file doesn't exist; if it exists, it tries to format it and throws a syntax error. The second is the exact same, with an extra ignored argument.

Looking at the code, I think this feature is implemented, but the command line isn't parsed correctly; --print-config minimal needs to consume an additional argument which is just the path to the new config. If it were parsed correctly, the behavior would be surprising, since it would both format the code and print a config (when I would expect --print-config to not modify the source code).

Also, note that there are no tests for either --print-config default or --print-config minimal.

@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Jun 2, 2018
@glmdgrielson
Copy link

I want to add that it seems to work with the default option. (as in, rustfmt --print-config default rustfmt.toml works)

@gurgalex
Copy link

gurgalex commented Feb 22, 2019

To confirm the desired behavior.

Given a default rustfmt.toml generated by rustfmt --print-config default rustfmt.toml

  1. Upon running rustfmt --print-config minimal min_rustfmt.toml it would output
    only the config options used when dry-run formatting (doesn't change input) the current program (from stdin?). It would output the minimal config to min_rustfmt.toml.

  2. Upon running rustfmt --print-config minimal min_rustfmt.toml src/main.rs src/lib.rs only consider formatting config options used with src/main.rs and src/lib.rs. No changes to either file. Output config options to min_rustfmt.toml.

        --print-config [minimal|default] PATH
                        Dumps a default or minimal config to PATH. A minimal
                        config is the subset of the current config file used
                        for formatting the current program.

@gurgalex
Copy link

^ @topecongiro

@scampi
Copy link
Contributor

scampi commented Jul 13, 2019

@gurgalex As of 679c8d5 your first use case wouldn't do what you described: rustfmt just ignores the minimal path if no files to format are given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants