feat(forc-fmt): enhance `forc-fmt` `--path` behaviour flexibility
- Dominant language
- Rust
- Stars
- 61.4k
- Forks
- 5.4k
- Avg merge
- 3h 33m
- Merged PRs (30d)
- 4
Description
In this [PR](https://github.com/FuelLabs/sway/pull/4129#issuecomment-1437902838) I discovered that there was some bug introduced with a previous PR i made refactoring `forc-fmt`. We should enhance the flexibility of forc-fmt to allow different behavior based on the `--path` input:
1) If --path points to a sway file, it only formats that file.
2) If --path points to a directory, it walks the directory and formats all sway files within.
3) If --path points to a package manifest, it only formats the source of that package.
4) If --path points to a workspace manifest, if formats all the member packages.
Currently `forc-fmt` only works on point 2. A PR should be opened to address 3 and 4.
As for 1, Further conversations with @mitchmindtree has also led to some insights regarding the desired behaviour of `forc-fmt`, which was emulated after `cargo fmt`:
`cargo fmt` is meant to work on workspaces/manifests and `rustfmt` is more primitive in the sense that it accepts only a file/list of files to format. In our case, we do not distribute `swayfmt` + `forc-fmt`. A previous PR i made introduced single file formatting file `forc fmt `. This is to emulate `rustfmt`.
I was thinking if we should keep this behavior, but I think for consistency's sake, we should also include `--path` for single file formatting.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the existing forc-fmt --path handling and its current directory-walking behavior; the issue also references cargo fmt and rustfmt as behavioral models. Done means --path consistently handles Sway files, directories, package manifests, and workspace manifests as described, with coverage for the new cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100