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.
Inside of a large monorepo where
dprintis configured and usesdprint-plugin-execto runrustfmt, we have a bunch of differentrustfmt.tomlfiles. One at the root with pretty uncontroversial settings, and then multiple otherrustfmt.tomlfiles in various crates and project folders, depending on each team's preference.Since
dprintpasses the file's content viastdinand expects the formatter to output tostdout,rustfmthas no idea of where to look for a config, besides thecwdfrom where it gets invoked. As such, only the top-levelrustfmt.tomlis used.I'm looking for a way to have to tell
rustfmtto run inside of the file's parent dir, so it's config search algorithm picks up the nearestrustfmt.toml.Maybe I'm missing something, is there a better way to honor
rustfmt.tomlthe same waycargo fmtwould?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 arustfmt.toml, then invokesrustfmtwith the--config-patharg 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": falsein theexecconfig, but sincerustfmtoutputs the file path before the formatted contents, this clobbers the files.