Skip to content

Tidy up your go.mod files by merging the require blocks

License

Notifications You must be signed in to change notification settings

abhijit-hota/modfmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

modfmt

This tool merges require blocks in go.mod files since go mod tidy doesn't do it. It also separates the direct and indirect dependencies and sorts them alphabetically.

Before After

Installation

go install go.abhijithota.me/modfmt@latest

Usage

The binary outputs the formatted go.mod to standard output. In your Go project root, run:

modfmt > go.mod

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.

About

Tidy up your go.mod files by merging the require blocks

Topics

Resources

License

Stars

Watchers

Forks

Languages