codes

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ImmutableFieldAssignment     = "IMM01"
	ImmutableFieldCompoundAssign = "IMM02"
	ImmutableFieldIncDec         = "IMM03"
	ImmutableIndexAssignment     = "IMM04"
	ImmutableCategoryPrefix      = "IMM"
)

Error code constants for immutable violations

View Source
const (
	ConstructorCompositeLiteral = "CTOR01"
	ConstructorNewCall          = "CTOR02"
	ConstructorVarDeclaration   = "CTOR03"
	ConstructorCategoryPrefix   = "CTOR"
)

Error code constants for constructor violations

View Source
const (
	TestOnlyTypeUsage      = "TONL01"
	TestOnlyFunctionCall   = "TONL02"
	TestOnlyMethodCall     = "TONL03"
	TestOnlyCategoryPrefix = "TONL"
)

Error code constants for testonly violations

View Source
const (
	ImplementsPackageNotFound   = "IMPL01"
	ImplementsInterfaceNotFound = "IMPL02"
	ImplementsMissingMethods    = "IMPL03"
	ImplementsCategoryPrefix    = "IMPL"
)

Error code constants for implements violations

View Source
const (
	PackageOnlyTypeUsage      = "PKGO01"
	PackageOnlyFunctionCall   = "PKGO02"
	PackageOnlyMethodCall     = "PKGO03"
	PackageOnlyCategoryPrefix = "PKGO"
)

Error code constants for package-only violations

Variables

View Source
var CodesByCategory = map[string][]Code{
	ImmutableCategoryPrefix: {
		{ImmutableFieldAssignment, "Field of immutable type is being assigned"},
		{ImmutableFieldCompoundAssign, "Compound assignment to immutable field (e.g., +=, -=)"},
		{ImmutableFieldIncDec, "Increment/decrement of immutable field (e.g., ++, --)"},
		{ImmutableIndexAssignment, "Index assignment to immutable collection (slice/map element)"},
	},
	ConstructorCategoryPrefix: {
		{ConstructorCompositeLiteral, "Composite literal used outside allowed constructor functions"},
		{ConstructorNewCall, "new() call used outside allowed constructor functions"},
		{ConstructorVarDeclaration, "Variable declaration creates zero-initialized instance outside allowed constructor functions"},
	},
	TestOnlyCategoryPrefix: {
		{TestOnlyTypeUsage, "TestOnly type used outside test context"},
		{TestOnlyFunctionCall, "TestOnly function called outside test context"},
		{TestOnlyMethodCall, "TestOnly method called outside test context"},
	},
	PackageOnlyCategoryPrefix: {
		{PackageOnlyTypeUsage, "PackageOnly type used outside allowed packages"},
		{PackageOnlyFunctionCall, "PackageOnly function called outside allowed packages"},
		{PackageOnlyMethodCall, "PackageOnly method called outside allowed packages"},
	},
	ImplementsCategoryPrefix: {
		{ImplementsPackageNotFound, "Package not found in imports"},
		{ImplementsInterfaceNotFound, "Interface not found in package"},
		{ImplementsMissingMethods, "Type does not implement all required methods"},
	},
}

CodesByCategory contains all error codes grouped by their category prefix. This structure is easy to read, format, and validate in tests. Key: category prefix (e.g., "IMM") Value: slice of codes belonging to that category

Functions

func GetCodesForCheck

func GetCodesForCheck(code string) iter.Seq[string]

GetCodesForCheck returns an iterator of all codes that should be checked for ignore directives for the given error code. The iterator yields codes in order: "ALL", category prefix, specific code.

Example: GetCodesForCheck("IMM01") yields: "ALL", "IMM", "IMM01" Example: GetCodesForCheck("CTOR02") yields: "ALL", "CTOR", "CTOR02"

func GetDocumentationURL

func GetDocumentationURL(code string) string

GetDocumentationURL returns the documentation URL for the given error code

Types

type Code

type Code struct {
	ID          string // Unique error code (e.g., "IMM01")
	Description string // Human-readable description
}

Code represents an error code with its metadata

Jump to

Keyboard shortcuts

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