errcheck

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package errcheck implements the `glutter-gen errcheck` subcommand, which reads the whole module and reports what breaks the rules of github.com/rm4n0s/errors (its AI_GUIDE.md, summarized in CLAUDE.md, "Error handling", and SPEC §14.4).

Flutter: no counterpart.

Index

Constants

View Source
const (
	// RuleStdErrors says that the standard library's errors package is not imported under
	// the name errors; rm4n0s/errors re-exports Is, As and Unwrap (R6).
	RuleStdErrors = "std-errors"
	// RuleFmtErrorf says that fmt.Errorf is not called; errors.NewErrf is its counterpart.
	RuleFmtErrorf = "fmt-errorf"
	// RuleMetadataChain says that the metadata of a new error is given in one call: to
	// errors.New itself, or in one SetMetadata after NewErr and NewErrf (R2).
	RuleMetadataChain = "metadata-chain"
	// RuleMetadataPairs says that metadata is alternating string keys and values (R2).
	RuleMetadataPairs = "metadata-pairs"
	// RuleSentinelCtor says that a package-level variable is not made by errors.New,
	// NewErr or NewErrf, which would capture the stack of init (R5).
	RuleSentinelCtor = "sentinel-ctor"
	// RuleErrorHelper says that a function that only builds an error and returns it is not
	// written: the constructor is called in the function that fails, so that the route is
	// right (R4).
	RuleErrorHelper = "error-helper"
	// RuleErrorRewrap says that an error that comes from a function of the module is
	// returned as it is, not wrapped again by NewErr or NewErrf (R3, case A).
	RuleErrorRewrap = "error-rewrap"
	// RuleErrorUntagged says that an error that comes from outside the module is tagged by
	// NewErr where it first appears, not returned as it is (R3, case B).
	RuleErrorUntagged = "error-untagged"
	// RuleTagBranch says that code does not compare the Tag of an error with a string
	// literal, or branch on its message; it uses a tag constant or errors.Is (R5). Tests are
	// not checked: a test pins the string that is the contract (a public tag, or the text of a
	// message that a ported Flutter test asserts).
	RuleTagBranch = "tag-branch"
	// RuleTagLiteral says that the tag given to errors.New, NewErr or NewErrf is a constant
	// or an expression, not a string literal (R5).
	RuleTagLiteral = "tag-literal"
	// RuleErrorToJson says that an error is logged with slog as "err", err, not through
	// ToJson (guide §5). Tests may call ToJson to replay an error.
	RuleErrorToJson = "error-tojson"
)

The rules, as they are named in a report and in an allow file.

View Source
const (
	// TagErrCheckAndroidNDKNotFound is the tag of the error for a missing Android NDK; the
	// metadata "install" has the sdkmanager command.
	TagErrCheckAndroidNDKNotFound = "ErrCheckAndroidNDKNotFound"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

Variables

View Source
var AndroidPass = Pass{GOOS: "android", GOARCH: "arm64"}

AndroidPass is the build for Android. The module is built with cgo and the NDK's clang there (SPEC §24.2), so that the *_android.go files of internal/platform/android are read.

Flutter: no counterpart.

View Source
var DefaultPasses = []Pass{
	{GOOS: "linux", GOARCH: "amd64"},
	{GOOS: "js", GOARCH: "wasm"},
	{GOOS: "linux", GOARCH: "amd64", Tags: []string{"glutter_display", "glutter_browser", "glutter_wine"}},
	AndroidPass,
	WindowsPass,
}

DefaultPasses are the builds that together cover every file of the module: Linux, the web, Linux with the tags of the display, browser and Wine tests (the host-side tests that start Wine), Android (SPEC §24.13) and Windows with the tag of the Wine tests (SPEC §25.13).

Flutter: no counterpart.

View Source
var WindowsPass = Pass{GOOS: "windows", GOARCH: "amd64", Tags: []string{"glutter_wine"}}

WindowsPass is the build for Windows with the tag of the Wine tests, so that the *_windows.go files and the tests that run inside Wine are read (SPEC §25.13). It needs no toolchain besides the go command: Windows is built without cgo.

Flutter: no counterpart.

Functions

func ReadAllow

func ReadAllow(path string) (map[string]bool, error)

ReadAllow reads an allow file: each line is "rule file:Func", optionally followed by "# why". Blank lines and lines that start with # are skipped.

Flutter: no counterpart.

func Run

func Run(args []string) error

Run is the subcommand. It prints the violations that the allow file does not list and fails with ErrCheckViolations when there are some.

Flutter: no counterpart.

Types

type Pass

type Pass struct {
	GOOS, GOARCH string
	Tags         []string
}

Pass is one way of building the module: a platform and a set of build tags.

Flutter: no counterpart.

type Violation

type Violation struct {
	// Rule is one of the Rule constants.
	Rule string
	// File is the path of the file below the root, with slashes.
	File string
	// Func is the function that holds the code: "Name", "Type.Name", or "-" outside any.
	Func string
	// Line is where the problem is.
	Line int
	// Message says what is wrong.
	Message string
}

Violation is one place where the code breaks a rule.

Flutter: no counterpart.

func CheckModule

func CheckModule(ctx context.Context, root string, passes []Pass) ([]Violation, error)

CheckModule checks every package of the module below root for each pass and returns the violations, without duplicates, in the order of their files and lines.

Flutter: no counterpart.

func (Violation) Key

func (v Violation) Key() string

Key is how an allow file names the violation: "rule file:Func".

Flutter: no counterpart.

func (Violation) String

func (v Violation) String() string

String is the line of the report.

Flutter: no counterpart.

Jump to

Keyboard shortcuts

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