gomop

module
v0.0.0-...-a8a9ef0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: MIT

README

gomop

⚠️ Early Development: Expect bugs, missing features, and breaking changes. Not recommended for production use yet.

A high-performance, unified Go formatter that combines gofumpt, golines, and goimports into a single tool.

Features

  • Import fixing - Adds missing imports and removes unused ones
  • Import grouping - Strict 3-block grouping: stdlib, third-party, local
  • Line shortening - Splits long lines based on configurable width
    • Function calls and composite literals
    • String literals (word-aware splitting)
    • Method chains (dot-first style)
  • gofumpt rules - Stricter formatting for consistent style
    • Short case clauses collapsed to single line
    • No empty lines around function bodies
    • Empty interfaces/structs on single line
  • Single pass - All transformations in one AST walk for speed
  • Fast - Sub-10ms formatting for typical files

Installation

go install github.com/nijaru/gomop/cmd/gomop@latest

Usage

# Format files (prints to stdout)
gomop file.go

# Write changes in-place
gomop -w file.go

# List files that need formatting
gomop -l ./...

# Show diffs
gomop -d file.go

# Use glob patterns
gomop '**/*.go'

Options

Flag Default Description
-w, --write false Write result to source file
-l, --list false List files whose formatting differs
-d, --diff false Display diffs
-m, --line-length 100 Maximum line length
-t, --tab-width 4 Tab width
--go go1.24 Go version for formatting
--modpath Module path for import grouping
--local Comma-separated local import prefixes
--extra false Enable gofumpt extra rules
--fast false Skip type loading (faster, less accurate)
--version Print version and exit

Performance

gomop uses a tiered import resolution strategy to avoid the ~40ms overhead of packages.Load:

  1. AST-only pass - Fast, always runs
  2. Sibling files - Parse other files in directory
  3. Stdlib lookup - O(1) in-memory index
  4. Full type info - Only as last resort

Result: ~6.6ms for a 30K file (8.3x faster than baseline).

License

MIT

Directories

Path Synopsis
cmd
gomop command
internal
format
Package format provides unified Go formatting in a single pass.
Package format provides unified Go formatting in a single pass.
stdlib
Package stdlib provides a table of all exported symbols in the standard library, along with the version at which they first appeared.
Package stdlib provides a table of all exported symbols in the standard library, along with the version at which they first appeared.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL