summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-13 10:32:48 +0300
committerPaul Buetow <paul@buetow.org>2026-05-13 10:32:48 +0300
commit94aa1d0af0fa4d6c7873a4b5de0f55dfcc0aa03c (patch)
tree6ac6194a2271bd0acf3599c0de2c8ce17c81ebb4
parent75fd7c03b1a8018f85e2da779ab59b86ad0efb58 (diff)
enforce gofmt formatting and add Fmt/FmtCheck mage targets
Run gofmt -w on 9 files that had minor alignment/whitespace drift (pair.go, filter.go, ior_mode_registry.go, ior_mode_test.go, runtime.go, engine.go, dashboard/model.go, flamegraph/model.go, flamegraph/renderer.go). Add two new Mage targets to Magefile.go: - `mage fmt` – rewrites all .go files in-place via go/format - `mage fmtCheck` – dry-run check; fails with a list of offending files, suitable as a CI gate Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--Magefile.go57
-rw-r--r--internal/event/pair.go2
-rw-r--r--internal/globalfilter/filter.go1
-rw-r--r--internal/ior_mode_registry.go6
-rw-r--r--internal/ior_mode_test.go12
-rw-r--r--internal/runtime/runtime.go4
-rw-r--r--internal/statsengine/engine.go4
-rw-r--r--internal/tui/dashboard/model.go4
-rw-r--r--internal/tui/flamegraph/model.go2
-rw-r--r--internal/tui/flamegraph/renderer.go8
10 files changed, 77 insertions, 23 deletions
diff --git a/Magefile.go b/Magefile.go
index 6f24e9d..9d4261d 100644
--- a/Magefile.go
+++ b/Magefile.go
@@ -124,6 +124,63 @@ func TestRace() error {
return sh.RunWithV(goEnv(), "go", "test", "./...", "-race", "-failfast", "-timeout=90m")
}
+// Fmt runs gofmt -w on all Go source files to enforce canonical formatting.
+func Fmt() error {
+ return fmtGoFiles(false)
+}
+
+// FmtCheck verifies that all Go source files are gofmt-formatted.
+// It exits with a non-zero status if any file needs reformatting,
+// making it suitable for use as a CI gate (e.g. mage fmtCheck).
+func FmtCheck() error {
+ return fmtGoFiles(true)
+}
+
+// fmtGoFiles walks the repo tree and either formats or checks every .go file.
+// When checkOnly is true, any file that needs reformatting is reported as an
+// error without writing to disk. When false, files are rewritten in place.
+func fmtGoFiles(checkOnly bool) error {
+ var unformatted []string
+ err := filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
+ // Skip vendor and hidden directories (e.g. .git).
+ if d.IsDir() && (d.Name() == "vendor" || strings.HasPrefix(d.Name(), ".")) {
+ return filepath.SkipDir
+ }
+ if d.IsDir() || !strings.HasSuffix(path, ".go") {
+ return nil
+ }
+ src, err := os.ReadFile(path)
+ if err != nil {
+ return fmt.Errorf("read %s: %w", path, err)
+ }
+ formatted, err := format.Source(src)
+ if err != nil {
+ // Syntax errors are reported but don't abort the walk.
+ fmt.Printf("gofmt: syntax error in %s: %v\n", path, err)
+ return nil
+ }
+ if string(src) == string(formatted) {
+ return nil
+ }
+ if checkOnly {
+ unformatted = append(unformatted, path)
+ return nil
+ }
+ return os.WriteFile(path, formatted, d.Type().Perm())
+ })
+ if err != nil {
+ return err
+ }
+ if len(unformatted) > 0 {
+ return fmt.Errorf("gofmt: %d file(s) need formatting:\n %s\nRun `mage fmt` to fix.",
+ len(unformatted), strings.Join(unformatted, "\n "))
+ }
+ return nil
+}
+
// TestWithName runs a specific test by name.
func TestWithName() error {
mg.Deps(BpfBuild)
diff --git a/internal/event/pair.go b/internal/event/pair.go
index c31fd90..1626e88 100644
--- a/internal/event/pair.go
+++ b/internal/event/pair.go
@@ -25,7 +25,7 @@ type Pair struct {
Comm string
Duration uint64
DurationToPrev uint64
- Bytes uint64 // Number of bytes transferred (read/write/transfer syscalls only)
+ Bytes uint64 // Number of bytes transferred (read/write/transfer syscalls only)
}
func NewPair(enterEv Event) *Pair {
diff --git a/internal/globalfilter/filter.go b/internal/globalfilter/filter.go
index 01213aa..689a728 100644
--- a/internal/globalfilter/filter.go
+++ b/internal/globalfilter/filter.go
@@ -242,4 +242,3 @@ func sameFilter[T comparable](left, right *T) bool {
return *left == *right
}
}
-
diff --git a/internal/ior_mode_registry.go b/internal/ior_mode_registry.go
index 3eb59b5..e262784 100644
--- a/internal/ior_mode_registry.go
+++ b/internal/ior_mode_registry.go
@@ -42,9 +42,9 @@ type runnerDeps struct {
// defaultRunnerDeps returns the production function set.
func defaultRunnerDeps() runnerDeps {
return runnerDeps{
- getEUID: os.Geteuid,
- runTrace: runTrace,
- runParquet: runHeadlessParquet,
+ getEUID: os.Geteuid,
+ runTrace: runTrace,
+ runParquet: runHeadlessParquet,
runTraceWithContext: runTraceWithContext,
// TUI runners are nil until SetTUIRunners is called from cmd/ior/main.go.
}
diff --git a/internal/ior_mode_test.go b/internal/ior_mode_test.go
index 5ba2894..81fd314 100644
--- a/internal/ior_mode_test.go
+++ b/internal/ior_mode_test.go
@@ -31,12 +31,12 @@ import (
// updating every test.
func stubDeps() runnerDeps {
return runnerDeps{
- getEUID: func() int { return 0 },
- runTrace: func(flags.Config) error { return nil },
- runParquet: func(flags.Config) error { return nil },
- runTraceWithContext: func(context.Context, flags.Config, chan<- struct{}, func(*eventLoop)) error { return nil },
- runTUI: func(flags.Config, runtime.TraceStarter) error { return nil },
- runTUITestFlames: func(flags.Config, runtime.TraceStarter) error { return nil },
+ getEUID: func() int { return 0 },
+ runTrace: func(flags.Config) error { return nil },
+ runParquet: func(flags.Config) error { return nil },
+ runTraceWithContext: func(context.Context, flags.Config, chan<- struct{}, func(*eventLoop)) error { return nil },
+ runTUI: func(flags.Config, runtime.TraceStarter) error { return nil },
+ runTUITestFlames: func(flags.Config, runtime.TraceStarter) error { return nil },
runTUITestLiveFlames: func(flags.Config, runtime.TraceStarter) error { return nil },
}
}
diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go
index 307c012..d6500d4 100644
--- a/internal/runtime/runtime.go
+++ b/internal/runtime/runtime.go
@@ -199,8 +199,8 @@ func TraceFiltersFromContext(ctx context.Context) (globalfilter.Filter, bool) {
var (
// *flamegraph.LiveTrie must satisfy both the read-only and mutating sides of
// the trie contract as well as the combined LiveTrieSource interface.
- _ Snapshotter = (*flamegraph.LiveTrie)(nil)
- _ Configurator = (*flamegraph.LiveTrie)(nil)
+ _ Snapshotter = (*flamegraph.LiveTrie)(nil)
+ _ Configurator = (*flamegraph.LiveTrie)(nil)
_ LiveTrieSource = (*flamegraph.LiveTrie)(nil)
// *probemanager.Manager must satisfy the probe-control surface exposed to the TUI.
diff --git a/internal/statsengine/engine.go b/internal/statsengine/engine.go
index 78dbe65..02aee37 100644
--- a/internal/statsengine/engine.go
+++ b/internal/statsengine/engine.go
@@ -209,8 +209,8 @@ func (e *Engine) captureSnapshotInputs() snapshotInputs {
// and returns their results bundled together.
func buildSubSnapshots(in snapshotInputs, elapsed time.Duration) subSnapshots {
var (
- ss subSnapshots
- wg sync.WaitGroup
+ ss subSnapshots
+ wg sync.WaitGroup
)
wg.Add(5)
diff --git a/internal/tui/dashboard/model.go b/internal/tui/dashboard/model.go
index 8548481..2535a90 100644
--- a/internal/tui/dashboard/model.go
+++ b/internal/tui/dashboard/model.go
@@ -84,8 +84,8 @@ type Model struct {
// autoResetEvery; autoResetStatus uses this to render the live
// countdown ("12s/30s") in the chrome. Updated on every arm
// (SetAutoResetInterval, focus regain, tick re-arm).
- autoResetArmedAt time.Time
- keys common.KeyMap
+ autoResetArmedAt time.Time
+ keys common.KeyMap
globalFilter globalfilter.Filter
filterStack []string
recordingStatus string
diff --git a/internal/tui/flamegraph/model.go b/internal/tui/flamegraph/model.go
index 73285f9..c188323 100644
--- a/internal/tui/flamegraph/model.go
+++ b/internal/tui/flamegraph/model.go
@@ -1051,7 +1051,6 @@ func (m Model) rootSnapshotPath() string {
return m.ZoomNavigator.rootSnapshotPath(m.snapshot, m.frames)
}
-
// frameIndexAt delegates to the FrameAnimator package-level helper to convert
// terminal coordinates (x, y) to a frame index, accounting for UI chrome.
func (m Model) frameIndexAt(x, y int) int {
@@ -1063,7 +1062,6 @@ func (m Model) frameCoordToTargetRow(dataRow, availableRows int) int {
return frameCoordToTargetRow(m.frames, dataRow, availableRows)
}
-
func (m Model) withZoomLineage(frames []tuiFrame) []tuiFrame {
return applyZoomLineage(frames, m.snapshot, m.zoomPath, m.width)
}
diff --git a/internal/tui/flamegraph/renderer.go b/internal/tui/flamegraph/renderer.go
index 8f0d09b..24b99ed 100644
--- a/internal/tui/flamegraph/renderer.go
+++ b/internal/tui/flamegraph/renderer.go
@@ -209,12 +209,12 @@ func semanticFrameColor(name string) (color.Color, bool) {
// renderViewParams bundles the pre-computed layout parameters used by
// RenderTerminalView helpers to avoid threading many individual arguments.
type renderViewParams struct {
- rowOffset int
- maxRow int
- barHeight int
+ rowOffset int
+ maxRow int
+ barHeight int
availableRows int
visibleFrames int
- truncated bool
+ truncated bool
}
// computeRenderParams derives the row-layout parameters for a given frame set