pkgdirective

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package pkgdirective reads forge's package-level comment directives — `//forge:exclude-contract: <why>`, `//forge:not-a-component: <why>` and their kin — from a package directory's source.

It imports only the standard library, deliberately. Contract mock generation consults `//forge:exclude-contract`, and forge's own mocks are regenerated by internal/tools/mockgen WITHOUT building forge (forge#1261): a stale mock_gen.go in a package the forge binary imports must never stop the tool that refreshes it from compiling. So this package may not grow an import of anything that carries generated contract code; internal/tools/mockgen's TestMockgenImportsNoContractCodegen holds that.

internal/codegen's directive API (FindExcludeContractMarker, FindNotAComponentMarker, …) is built on these primitives, so the generator and the bootstrap tool read a directive the same way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachPackageComment

func ForEachPackageComment(dir string, fn func(path string, line int, raw string))

ForEachPackageComment calls fn for every comment in dir's non-test, non-generated .go files, in file-name then position order. Unparseable files are skipped: a directive is read best-effort.

func ParseReasoned

func ParseReasoned(raw, directive string) (reason string, ok bool)

ParseReasoned is the whole-line rule for a directive that takes a reason after a colon: `//<directive>: <why>` yields "<why>", the bare `//<directive>` yields "", and anything else — prose that mentions the directive, a different separator — is not the directive.

func TrimCommentMarkers

func TrimCommentMarkers(raw string) string

TrimCommentMarkers strips one comment's `//` or `/* */` syntax and the whitespace around its text.

Types

type Marker

type Marker struct {
	// File is the absolute path of the file carrying the marker.
	File string
	// Line is the marker's 1-indexed line.
	Line int
	// Reason is the text after `forge:<directive>:`; "" for a bare marker.
	Reason string
}

Marker is one occurrence of a package directive that takes a reason — `//forge:exclude-contract: <why>` or `//forge:not-a-component: <why>`.

func Find

func Find(dir, directive string) (Marker, bool)

Find returns the first occurrence of a reasoned package directive (`//<directive>: <why>` or the bare `//<directive>`) in dir's non-test, non-generated files, scanned in name order. A reasoned occurrence anywhere wins over a bare one.

func FindAll

func FindAll(dir, directive string) []Marker

FindAll returns every occurrence of a reasoned package directive in dir's non-test, non-generated files, in file-name then line order.

Jump to

Keyboard shortcuts

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