Skip to content

[Feature request] Enable sourcing of rustfmt.toml config in sub-directories #49

Description

@beeb

Inside of a large monorepo where dprint is configured and uses dprint-plugin-exec to run rustfmt, we have a bunch of different rustfmt.toml files. One at the root with pretty uncontroversial settings, and then multiple other rustfmt.toml files in various crates and project folders, depending on each team's preference.

Since dprint passes the file's content via stdin and expects the formatter to output to stdout, rustfmt has no idea of where to look for a config, besides the cwd from where it gets invoked. As such, only the top-level rustfmt.toml is used.

I'm looking for a way to have to tell rustfmt to run inside of the file's parent dir, so it's config search algorithm picks up the nearest rustfmt.toml.

Maybe I'm missing something, is there a better way to honor rustfmt.toml the same way cargo fmt would?

At the moment my dirty workaround consists of wrapping rustfmt with a shell script that walks the directory structure upwards from the {{file_path}} until it finds a rustfmt.toml, then invokes rustfmt with the --config-path arg pointing to that file.

One thing that I tried but did not work, is to set rustfmt --emit stdout {{file_path}} as the command and set "stdin": false in the exec config, but since rustfmt outputs the file path before the formatted contents, this clobbers the files.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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