belint

package module
v1.0.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 13 Imported by: 0

README

belint

A go/analysis linter for the be matcher library. It flags assertions that hide a raw expression inside be.True()/be.False() — where the failure message degenerates to "expected true, got false" — plus be.Not(...) compositions that have a dedicated matcher. Most findings come with a suggested fix, so -fix rewrites them mechanically.

Flags Suggests
be.True(x == y) / be.False(x == y) be.Eq(y) / be.Ne(y)
be.True(x >= n) (numeric) be.Gte(n) (and Gt/Lt/Lte)
be.True(err == nil) / be.True(err != nil) be.Nil() / be.NotNil()
be.True(len(xs) == 0) / be.True(len(xs) > 0) be.Empty() / be.NotEmpty()
be.True(len(xs) >= n) be.HaveLength(be.Gte(n))
be.True(slices.Contains(xs, v)) be.ContainElement(v)
be.True(strings.Contains(s, q)) be.ContainSubstring(q)
be.True(strings.HasPrefix(s, p)) be_string.HavingPrefix(p) (report-only)
be.True(errors.Is(err, X)) be.MatchError(X)
be.True(errors.As(err, &v)) be.MatchErrorAs[V]() (report-only; suppressed when v is used after the assertion — the matcher doesn't bind it)
be.Not(be.Nil()) be.NotNil()
be.HaveLength(0) / be.Not(be.HaveLength(0)) be.Empty() / be.NotEmpty()
be.Not(be.Empty()) be.NotEmpty()
be.Not(be.Eq(0)) be.NonZero()

All assertion spellings are recognized: be.AssertThat / be.RequireThat and be.Expect(...) / be.Require(...) with .To / .NotTo / .ToNot (a fixed .NotTo(be.True()) is rewritten to .To(...) with the negation folded into the matcher). "Report-only" rows have no autofix because applying one would need a new import or a type name.

golangci-lint (module plugin)

belint registers with golangci-lint's module plugin system. Build a custom binary once:

# .custom-gcl.yml
version: v2.1.0 # your golangci-lint version
plugins:
  - module: 'github.com/expectto/be/x/belint'
    import: 'github.com/expectto/be/x/belint'
    version: latest
golangci-lint custom # produces ./custom-gcl

Then enable it:

# .golangci.yml
linters:
  enable:
    - belint
  settings:
    custom:
      belint:
        type: 'module'
        description: 'be matcher anti-patterns'

Standalone (vettool, with -fix)

go run github.com/expectto/be/x/belint/cmd/belint@latest ./...
go run github.com/expectto/be/x/belint/cmd/belint@latest -fix ./...

or via go vet:

go install github.com/expectto/be/x/belint/cmd/belint@latest
go vet -vettool=$(which belint) ./...

Documentation

Overview

Package belint is a go/analysis linter for the be matcher library. It flags assertions that hide a raw expression inside be.True()/be.False() — where the failure message degenerates to "expected true" — and be.Not(...) compositions that have a dedicated matcher, suggesting (and with -fix, applying) the matcher spelling from the anti-pattern table in MATCHERS.md.

Point-of-use feedback is the goal: a diagnostic on the offending line is how both humans and LLM agents discover a matcher exists without reading docs.

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:     "belint",
	Doc:      "flags raw expressions wrapped in be.True()/be.False() and be.Not(...) compositions that have a dedicated be matcher",
	URL:      "https://github.com/expectto/be/tree/main/x/belint",
	Requires: []*analysis.Analyzer{inspect.Analyzer},
	Run:      run,
}

Analyzer flags be assertion anti-patterns and suggests matcher spellings.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
belint command
Command belint runs the belint analyzer standalone (with -fix support):
Command belint runs the belint analyzer standalone (with -fix support):

Jump to

Keyboard shortcuts

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