archtest

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 14 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 archtest checks the package boundaries and the forbidden imports of SPEC §5.3: the editor core never imports Glutter or the GUI, no cgo, errors go through github.com/rm4n0s/errors, built where the failure happens and never in a helper (SPEC §5.3 and §13), and the extensions compiled into Emetos import only the public package extension (SPEC §10.15). ErrorTags and UntestedErrorTags list the error Tags of the code and the ones no test asserts (scripts/error-tags.sh).

Check parses every Go file under a root folder, so each rule is tested on small fixture trees under testdata, and the real repository is checked by a test too. Its tests also hold the repository's shell scripts to their rules (SPEC §15.1), such as scripts/isolated.sh never letting a run reach the user's folders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorTags

func ErrorTags(root string) ([]TagSite, []Violation, error)

ErrorTags returns the Tag of every errors.New, errors.NewErr and errors.NewErrf call in the non-test Go files of cmd, internal, extension and extensions below root, sorted by Tag, file and line. A call whose first argument is not a string literal has no Tag to list: it is returned as a RuleNonLiteralTag violation, so a Tag cannot hide in a variable.

func ReadUntestedList

func ReadUntestedList(file string) (map[string]string, error)

ReadUntestedList reads docs/ERROR-TAGS-UNTESTED.md, the only exception list of the route tests: the Tags it names, each with its reason. A line of the form "- `Tag`: reason" names one; every other line is prose. A file that does not exist is an empty list.

The error has the tag ErrorTagsExceptionsReadFailed.

func UntestedErrorTags

func UntestedErrorTags(root string) ([]TagSite, []Violation, error)

UntestedErrorTags returns the sites of the Tags that no test asserts, sorted like ErrorTags, and the violations ErrorTags found. A test asserts a Tag when, in a Go test file of cmd, internal, extension or extensions below root:

  • a string that is an argument of HasRoute ends in the Tag (after the last "." of the route, or is the Tag alone);
  • a string of a test file of a folder where some test calls HasRoute or compares a .Tag with == or != has the form of a route, Func.Tag or Type.Method->Func.Tag, and ends in the Tag (the strings of a table of cases, and of helpers like wantRoute(t, err, "Func.Tag"), are found this way);
  • a string of such a folder is the Tag alone, when a test of the folder compares a .Tag or gives HasRoute a route that is not a literal (tables of Tags, and helpers like wantTag(t, err, "Func", "Tag"));
  • errors.Is is given a &errors.Error{Tag: "..."} sentinel.

A constant of the folder with a string value counts as that string. A string that is the first argument of errors.New, errors.NewErr or errors.NewErrf (a fake error of a test) never counts, and neither does a Tag named only in a comment.

Types

type Rule

type Rule string

Rule names a boundary rule of SPEC §5.3.

const (
	// RuleCoreImportsUI: a package under internal/core imports Glutter or internal/gui.
	RuleCoreImportsUI Rule = "CoreImportsUI"
	// RuleImportC: a file contains import "C".
	RuleImportC Rule = "ImportC"
	// RuleRegexp2Outside: a package other than internal/core/regex imports regexp2.
	RuleRegexp2Outside Rule = "Regexp2Outside"
	// RuleStdErrors: a file imports the standard library errors package.
	RuleStdErrors Rule = "StdErrors"
	// RuleFmtErrorf: a file calls fmt.Errorf.
	RuleFmtErrorf Rule = "FmtErrorf"
	// RulePackageLevelError: a package-level declaration calls errors.New, errors.NewErr or errors.NewErrf.
	RulePackageLevelError Rule = "PackageLevelError"
	// RuleErrorHelper: a function whose only job is to build and return an error.
	RuleErrorHelper Rule = "ErrorHelper"
	// RuleProjectErrorRewrapped: errors.NewErr or errors.NewErrf wraps an error that a function of another package of Emetos returned.
	RuleProjectErrorRewrapped Rule = "ProjectErrorRewrapped"
	// RuleNonLiteralTag: the tag of errors.New, errors.NewErr or errors.NewErrf in non-test code is not a string literal.
	RuleNonLiteralTag Rule = "NonLiteralTag"
	// RuleExtensionImportsInternal: a package under extensions/ imports a package of Emetos other than extension, a
	// subpackage of its own or one under extensions/internal (internal/..., cmd/...). The public package extension is the
	// only bridge to the editor (SPEC §10.15).
	RuleExtensionImportsInternal Rule = "ExtensionImportsInternal"
	// RuleExtensionImportsExtension: a package under extensions/<name>/ imports another extension, extensions/<other>/... (the terminal
	// emulator, extensions/terminal/emulator, is a library that every extension may import).
	RuleExtensionImportsExtension Rule = "ExtensionImportsExtension"
	// RuleExtensionImportsForbidden: a package under extensions/ imports a module that neither the standard library nor the
	// dependencies CLAUDE.md allows are, or a package inside Glutter's internal folders.
	RuleExtensionImportsForbidden Rule = "ExtensionImportsForbidden"
	// RuleExtensionContractImportsEmetos: a package of the public contract, extension/ but not extension/ui, imports a
	// package of Emetos other than the contract's own (internal/..., cmd/..., extensions/...). The contract imports nothing of
	// the editor (SPEC §10.15).
	RuleExtensionContractImportsEmetos Rule = "ExtensionContractImportsEmetos"
	// RuleExtensionUIImportsInternal: a package under extension/ui imports a package of Emetos other than the contract, its
	// own subpackages, internal/gui/kit and internal/gui/kit/fonts; the test harness extension/ui/uitest may also import
	// internal/gui/testutil. extension/ui is the one bridge of the contract to the widgets of the editor (SPEC §10.15).
	RuleExtensionUIImportsInternal Rule = "ExtensionUIImportsInternal"
	// RuleExtensionsImportedByInternal: a package under internal/ imports extensions/...; only cmd/ lists the extensions, so
	// the editor has no special case for a bundled one. The test files of internal/gui/ are the exception: a test of the
	// window that runs a real extension in it (step 15.4: Remote Work on two windows) imports that one extension; the
	// editor's own code never does.
	RuleExtensionsImportedByInternal Rule = "ExtensionsImportedByInternal"
	// RuleEmulatorImportsUI: a package of the terminal emulator, extensions/terminal/emulator, imports Glutter, a package of
	// Emetos or a module other than the standard library and golang.org/x/text. The emulator has no user interface and is
	// tested without one (SPEC §10.25 "The emulator"); its tests may also import the pseudo-terminal package
	// extensions/internal/pty, to record real programs, and golang.org/x/sys/unix, to time the emulator by the CPU clock.
	RuleEmulatorImportsUI Rule = "EmulatorImportsUI"
)

The rules Check enforces.

type TagSite

type TagSite struct {
	// Tag is the first argument of errors.New, errors.NewErr or errors.NewErrf.
	Tag string
	// File is the slash-separated path of the file relative to the root.
	File string
	// Line is the line of the call.
	Line int
	// Func is the function that makes the error, as the route names it
	// (Type.Method or Func).
	Func string
}

TagSite is one place that makes an error with a Tag.

type Violation

type Violation struct {
	// File is the slash-separated path of the file relative to the root.
	File string
	// Line is the line of the import or call.
	Line int
	// Rule is the rule that is broken.
	Rule Rule
	// Detail says what was imported or called.
	Detail string
}

Violation is one broken rule at one place.

func Check

func Check(root string) ([]Violation, error)

Check parses every Go file under root and returns the violations of SPEC §5.3, sorted by file and line. A folder named reference, testdata, vendor, node_modules or .git below root is skipped. Paths in the rules are relative to root, so a fixture tree mirrors the repository layout.

Errors carry the tags ArchWalkFailed (a folder or file can't be read) and ArchParseFailed (a Go file doesn't parse).

Directories

Path Synopsis
cmd
errortags command
Command errortags lists the error Tags of the repository, and the Tags that no test asserts.
Command errortags lists the error Tags of the repository, and the Tags that no test asserts.

Jump to

Keyboard shortcuts

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