{"id":31379763,"url":"https://github.com/joshdk/modfmt","last_synced_at":"2025-09-28T08:56:24.963Z","repository":{"id":313447222,"uuid":"1044973523","full_name":"joshdk/modfmt","owner":"joshdk","description":"🗂️ Formatter for go.mod and go.work files","archived":false,"fork":false,"pushed_at":"2025-09-19T01:43:33.000Z","size":49,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-19T03:38:18.359Z","etag":null,"topics":["formatter","go","go-mod","go-module","go-work","go-workspace","golang","linter"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshdk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-26T13:24:57.000Z","updated_at":"2025-09-19T01:40:23.000Z","dependencies_parsed_at":"2025-09-06T06:14:47.343Z","dependency_job_id":"729bb1a5-0855-4a99-a4ef-cdebca5eee37","html_url":"https://github.com/joshdk/modfmt","commit_stats":null,"previous_names":["joshdk/modfmt"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/joshdk/modfmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fmodfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fmodfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fmodfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fmodfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshdk","download_url":"https://codeload.github.com/joshdk/modfmt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshdk%2Fmodfmt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277346345,"owners_count":25802835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-28T02:00:08.834Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatter","go","go-mod","go-module","go-work","go-workspace","golang","linter"],"created_at":"2025-09-28T08:56:22.636Z","updated_at":"2025-09-28T08:56:24.951Z","avatar_url":"https://github.com/joshdk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License][license-badge]][license-link]\n[![Actions][github-actions-badge]][github-actions-link]\n[![GoDoc][godoc-badge]][godoc-link]\n[![Releases][github-release-badge]][github-release-link]\n\n# modfmt\n\n🗂️ Formatter for go.mod and go.work files\n\n## What is this?\n\nThis repository provides `modfmt`, a super simple formatter for `go.mod` and `go.work` files.\n\nAdditionally, it implements some specific features:\n\n- Consistent ordering of sections and directives.\n- Supports formatting of **both** `go.mod` and `go.work` files.\n- Supports **all** of the current `go.mod` and `go.work` directives.\n  - See https://go.dev/ref/mod#go-mod-file.\n  - See https://go.dev/ref/mod#go-work-file.\n- Preserves both file header comments and directive comments.\n- Can be used in a CI pipeline to verify that files are formatted.\n- Can be used as a library with minimal dependencies.\n- Can be used as an `analysis.Analyzer`. (planned)\n\n## Formatting\n\nEach of the various `go.mod` and `go.work` directives are combined into a unified block, consistently sorted, and rendered along with any associated comments. The ordering of directive blocks was based off of ecosystem conventions.\n\n### Ordering of `go.mod` directives\n\n| Section              | Explanation                                                                                              |\n|----------------------|----------------------------------------------------------------------------------------------------------|\n| `// Header comments` | All header or unattached comments.                                                                       |\n| `module …`           | The [module](https://go.dev/ref/mod#go-mod-file-module) directive.                                       |\n| `go …`               | The [go](https://go.dev/ref/mod#go-mod-file-go) directive.                                               |\n| `toolchain …`        | The [toolchain](https://go.dev/ref/mod#go-mod-file-toolchain) directive.                                 |\n| `godebug (…)`        | A block of [godebug](https://go.dev/ref/mod#go-mod-file-godebug) directives.                             |\n| `retract (…)`        | A block of [retract](https://go.dev/ref/mod#go-mod-file-retract) directives.                             |\n| `require (…)`        | A block of [require](https://go.dev/ref/mod#go-mod-file-require) directives.                             |\n| `require (…)`        | A block of [require](https://go.dev/ref/mod#go-mod-file-require) directives. (for indirect dependencies) |\n| `ignore (…)`         | A block of [ignore](https://go.dev/ref/mod#go-mod-file-ignore) directives.                               |\n| `exclude (…)`        | A block of [exclude](https://go.dev/ref/mod#go-mod-file-exclude) directives.                             |\n| `replace (…)`        | A block of [replace](https://go.dev/ref/mod#go-mod-file-replace) directives.                             |\n| `replace (…)`        | A block of [replace](https://go.dev/ref/mod#go-mod-file-replace) directives. (for local replacements)    |\n| `tool (…)`           | A block of [tool](https://go.dev/ref/mod#go-mod-file-tool) directives.                                   |\n\n### Ordering of `go.work` directives\n\n| Section              | Explanation                                                                                            |\n|----------------------|--------------------------------------------------------------------------------------------------------|\n| `// Header comments` | All header or unattached comments.                                                                     |\n| `go …`               | The [go](https://go.dev/ref/mod#go-work-file-go) directive.                                            |\n| `toolchain …`        | The [toolchain](https://go.dev/ref/mod#go-work-file-toolchain) directive.                              |\n| `godebug (…)`        | A block of [godebug](https://go.dev/ref/mod#go-work-file-godebug) directives.                          |\n| `use (…)`            | A block of [use](https://go.dev/ref/mod#go-work-file-use) directives.                                  |\n| `replace (…)`        | A block of [replace](https://go.dev/ref/mod#go-work-file-replace) directives.                          |\n| `replace (…)`        | A block of [replace](https://go.dev/ref/mod#go-work-file-replace) directives. (for local replacements) |\n\n## Installation\n\n### Release artifact\n\nBinaries for various architectures are published on the [releases][github-release-link] page.\n\nThe latest release can be installed by running:\n\n```shell\nOS=$(uname | tr '[:upper:]' '[:lower:]')\nARCH=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/')\nwget -O modfmt.tar.gz https://github.com/joshdk/modfmt/releases/latest/download/modfmt-${OS}-${ARCH}.tar.gz\ntar -xf modfmt.tar.gz\nsudo install modfmt /usr/local/bin/modfmt\n```\n\n### Brew\n\nRelease binaries are also available via [Brew](https://brew.sh).\n\nThe latest release can be installed by running:\n\n```shell\nbrew tap joshdk/tap\nbrew install joshdk/tap/modfmt\n```\n\n### Go install\n\nInstallation can also be done directly from this repository.\n\nThe latest commit can be installed by running:\n\n```shell\ngo install github.com/joshdk/modfmt@master\n```\n\n## Usage\n\n### Showing unformatted files\n\nShow unformatted `go.mod` or `go.work` files in the current directory:\n\n```shell\nmodfmt\n```\n\nShow unformatted files anywhere under the directory `pkg`:\n\n```shell\nmodfmt pkg/...\n```\n\nList unformatted filenames anywhere under the directory `pkg`:\n\n```shell\nmodfmt -l pkg/...\n```\n\n### Fixing unformatted files\n\nFormat and update all files under the current directory:\n\n```shell\nmodfmt -w ./...\n```\n\n\u003e [!IMPORTANT]  \n\u003e You should always run `go mod tidy` prior to `modfmt`.\n\nExit with an error if any files were unformatted.\n\n### Verifying that files are formatted\n\n```shell\nmodfmt -c ./...\n```\n\n\u003e [!TIP]\n\u003e This command should be run in CI during a linting pass.\n\n## License\n\nThis code is distributed under the [MIT License][license-link], see [LICENSE.txt][license-file] for more information.\n\n---\n\n\u003cp align=\"center\"\u003e\n  Created by \u003ca href=\"https://github.com/joshdk\"\u003eJosh Komoroske\u003c/a\u003e ☕\n\u003c/p\u003e\n\n[github-actions-badge]:  https://github.com/joshdk/modfmt/actions/workflows/build.yaml/badge.svg\n[github-actions-link]:   https://github.com/joshdk/modfmt/actions/workflows/build.yaml\n[github-release-badge]:  https://img.shields.io/github/release/joshdk/modfmt/all.svg\n[github-release-link]:   https://github.com/joshdk/modfmt/releases\n[godoc-badge]:           https://pkg.go.dev/badge/github.com/joshdk/modfmt/pkg/modfmt\n[godoc-link]:            https://pkg.go.dev/github.com/joshdk/modfmt/pkg/modfmt\n[license-badge]:         https://img.shields.io/badge/license-MIT-green.svg\n[license-file]:          https://github.com/joshdk/modfmt/blob/master/LICENSE.txt\n[license-link]:          https://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdk%2Fmodfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshdk%2Fmodfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdk%2Fmodfmt/lists"}