Skip to content

Combine rustfmt's stdin based mode of operation with cargo-fmt's ability to infer the rust edition #5602

Closed as not planned
@joebb97

Description

@joebb97

This is probably asking too much but it'd be nice if cargo-fmt could support reading a file from stdin and putting formatted output on stdout like rustfmt does. With this there'd be no real need to specify rustfmt --edition <edition>.

The use case is a linting tool like ale which runs rustfmt as
/bin/sh -c rustfmt < ${path_to_file_in_tmpdir} . It then takes this output and copies into the vim buffer. As far as I know ale doesn't support linters that modify files in place.

This currently doesn't work for files that use syntax from editions greater than 2015 (the default for rustfmt). It'd be nice not to have to hardcode a rust edition in my vim configuration and instead be able to point the config to cargo-fmt running in a "stdin mode", i.e:

/bin/sh -c cargo-fmt --stdin < ${path_to_file_in_tmpdir} . That way I can always adhere the project's edition specified in Cargo.toml as well as other configuration options specified in rustfmt.toml (assuming cargo-fmt adheres to the project's rustfmt.toml, I could be wrong about that).

I'd love to try to implement something like this if you all think it'd be valuable, but I understand if not. I can always see what I can do on the ale side of things to get this working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions