Closed bradzacher closed 4 months ago
Yeah that's a pretty bad design flaw for this plugin. The config is provided by the cli to the plugin because there could be a single running plugin and many configs. An issue is configs could be extended from other configs. I think maybe we need to introduce something like ${configDir}
in TypeScript and have this handled by the CLI. I opened https://github.com/dprint/dprint/issues/867
We work around this at canva with a little global executable called ensure-repo-root
:
#!/usr/bin/env bash
repo_root=$(git rev-parse --show-toplevel)
cd "$repo_root"
"$@"
Which we then add to the config eg:
{
"command": "ensure-repo-root rustfmt --edition 2021 --config-path rustfmt.toml --emit stdout",
"associations": ["**/*.rs"]
}
But it would be good to have a variable to do this for us and save the git invocation!
I opened https://github.com/dprint/dprint/pull/870 -- will merge and release it this weekend.
For things like
rustfmt
it's common to have arustfmt.toml
in the root of the repo. This can be passed via the--config-path
CLI flag.Unfortunately the plugin executes the command from the CWD. https://github.com/dprint/dprint-plugin-exec/blob/160b28c8ec08317b2c52e8f2c2fba6e60597a50f/src/handler.rs#L153-L154
This means that you cannot reference that root config file at all!
It'd be great if one could use the
dprint.json
as a marker of the repo root and use that folder to orient ones self in the repo - irrespective of the CWD.