https://github.com/abhijit-hota/modfmt
Tidy up your go.mod files by merging the require blocks
https://github.com/abhijit-hota/modfmt
go golang
Last synced: 4 months ago
JSON representation
Tidy up your go.mod files by merging the require blocks
- Host: GitHub
- URL: https://github.com/abhijit-hota/modfmt
- Owner: abhijit-hota
- License: mit
- Created: 2024-06-07T15:27:04.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2026-01-05T11:38:45.000Z (6 months ago)
- Last Synced: 2026-03-06T17:55:20.514Z (4 months ago)
- Topics: go, golang
- Language: Go
- Homepage: https://github.com/abhijit-hota/modfmt
- Size: 317 KB
- Stars: 16
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `modfmt`
This tool merges require blocks in `go.mod` files since [`go mod tidy` doesn't do it](https://github.com/golang/go/issues/56471).
It also separates the direct and indirect dependencies and sorts them alphabetically.
| Before | After |
|------------------------------|-----------------------------|
|
|
|
## Installation
```sh
go install github.com/abhijit-hota/modfmt@latest
```
## Usage
The binary outputs the formatted `go.mod` to standard output.
Alternatively, you can use the `--in-place` flag to replace the contents of the `go.mod` file in place.
In your Go project root, run:
```sh
modfmt --in-place
```
The `--check` command will override other flags, and will instead return a non-zero exit code if the `go.mod` file is
not formatted, or zero if it is already formatted. This is useful for validating `go.mod` files in CI pipelines.
```sh
modfmt --check
```
## Limitations
I hacked this tool together using the official parser in less than 2 hours and unsurprisingly there are a few drawbacks with this:
- `require` blocks come last after using this. Can be fixed with little effort I think?
- Comments in `require` blocks are not preserved.