Skip to content
quality-gatesPublic

About

Static analysis for Go that turns assumptions into assertions — a Go port of php-assumptions

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

84 Commits

Folders and files

Repository files navigation

assumpgo

Catch weak assumptions in Go boolean checks before they calcify: negative comparisons and bare variables used as conditions where a positive assertion would pin the intent.

assumpgo is a local CLI. It walks Go source, never builds or runs your project, and needs no project dependencies installed. Go 1.26+. Port of php-assumptions, inspired by From assumptions to assertions.

Quick start

go install github.com/quality-gates/assumpgo/cmd/assumpgo@latest
assumpgo ./...

That scans the tree and prints assumption findings plus the assumption ratio. Exit 0 is clean, 110 means assumptions found, 100 means usage error. The pretty table renders control characters in file paths and source lines as visible escapes such as \x1b for ESC; tabs remain spaces. This keeps scanned text from changing terminal state and preserves table alignment.

Common next steps:

assumpgo -format xml ./...
assumpgo -exclude vendor,testdata ./mypackage
assumpgo -output report.xml -format xml ./...

Full usage, patterns, and PHP mapping notes: docs/usage.md.

Install

go install github.com/quality-gates/assumpgo/cmd/assumpgo@latest
assumpgo -version

From a local checkout:

go build -o assumpgo ./cmd/assumpgo

Tune the gate

Point at one or more packages or files. Exclude noisy paths with -exclude. Prefer checkstyle XML when a CI system needs a machine report (-format xml; the only other accepted value is lowercase pretty, the default):

assumpgo -format xml -exclude vendor,generated ./...

Directory symlinks are followed for targets and exclusions, including links found inside a walked tree; cyclic links are visited only once. Symlinks and hard links to individual files are supported too, and aliases of the same file are deduplicated so each underlying file is analysed once. Only regular files are analysed; non-regular entries such as named pipes are skipped, even when their names end in .go. Files whose names begin with . or _, or that are excluded by Go build constraints (such as *_windows.go on other systems or //go:build ignore), are skipped during directory walks, matching Go's toolchain behavior; naming such a file directly still analyses it. The same constraints apply when resolving package-level constants: a const in a file the current build excludes does not hide a bare-variable assumption.

There is no ruleset file: the analyzer’s pattern set is fixed. See docs/usage.md for what counts as an assumption.

Suppress one intentional exception

assumpgo has no per-line disable comment. Skip paths with -exclude, or fix the check to a positive assertion (type assert / comma-ok / positive ==) so it is no longer an assumption. A comma-ok ok or !ok remains an assertion when combined with another condition, and in any else if branch of the same if statement; a separate negative comparison in that condition is still reported.

Drop it into CI

# GitHub Actions
- uses: actions/setup-go@v6
  with:
    go-version-file: go.mod
- run: go install github.com/quality-gates/assumpgo/cmd/assumpgo@latest
- run: assumpgo ./...
# GitLab / generic XML
script: assumpgo -format xml -output gl-assumpgo.xml ./...

Maintainers

Usage reference: docs/usage.md. Exploratory testing reports: docs/exploratory-testing/.

Development checks:

go test ./...
go vet ./...

CI also runs mutago mutation gates, govulncheck, and Go Report Card A+.

License

MIT. See LICENSE.

About

Static analysis for Go that turns assumptions into assertions — a Go port of php-assumptions

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages