typesafety

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyInPublicContractRule added in v1.4.2

type AnyInPublicContractRule struct {
	*rules.BaseRule
	// contains filtered or unexported fields
}

AnyInPublicContractRule detects untyped `any` in exported API contracts:

func (s *AdminService) BulkApprove(...) (any, error)   // caller gets a mystery
Metadata map[string]any                                 // in an exported request struct

Public contracts must be typed: `any` erases the schema, breaks generated TS types, and pushes type assertions onto every caller.

Not flagged: unexported symbols, comma-ok lookups (any, bool), stdlib-fixed signatures (Scan, MarshalJSON, ...), parameters (variadic logger-style ...any is idiomatic).

func NewAnyInPublicContractRule added in v1.4.2

func NewAnyInPublicContractRule() *AnyInPublicContractRule

NewAnyInPublicContractRule creates the rule

func (*AnyInPublicContractRule) AnalyzeFile added in v1.4.2

func (r *AnyInPublicContractRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation

AnalyzeFile checks exported contracts for untyped any

func (*AnyInPublicContractRule) Configure added in v1.4.2

func (r *AnyInPublicContractRule) Configure(settings map[string]any) error

Configure reads the optional excluded_methods setting (comma-separated).

type InterfaceAnyRule

type InterfaceAnyRule struct {
	*rules.BaseRule
	// contains filtered or unexported fields
}

InterfaceAnyRule detects interface{} usage that should be replaced with 'any'

func NewInterfaceAnyRule

func NewInterfaceAnyRule() *InterfaceAnyRule

NewInterfaceAnyRule creates the rule

func (*InterfaceAnyRule) AnalyzeFile

func (r *InterfaceAnyRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation

AnalyzeFile checks for interface{} usage

type TokenPosOffsetRule added in v1.4.2

type TokenPosOffsetRule struct {
	*rules.BaseRule
}

TokenPosOffsetRule detects token.Pos values treated as an offset into one file's bytes:

offset := int(node.Pos()) - 1
line := 1
for i := 0; i < offset; i++ { … }   // counts the wrong lines

A token.Pos is an offset into the whole FileSet, not into the file being analyzed. With one file per set the two coincide and the code looks correct; as soon as several files share a set — which is what happens once a project is type-checked — every position past the first file points somewhere else. The failure is silent: no panic, no error, just wrong line numbers.

The fix is always the same: ask the file set, FileSet.Position(pos).Line.

func NewTokenPosOffsetRule added in v1.4.2

func NewTokenPosOffsetRule() *TokenPosOffsetRule

NewTokenPosOffsetRule creates the rule

func (*TokenPosOffsetRule) AnalyzeFile added in v1.4.2

func (r *TokenPosOffsetRule) AnalyzeFile(_ *core.FileContext) []*core.Violation

AnalyzeFile is a no-op: recognizing a token.Pos needs type information.

func (*TokenPosOffsetRule) AnalyzeGoProject added in v1.4.2

func (r *TokenPosOffsetRule) AnalyzeGoProject(ctx *core.GoProjectContext) ([]*core.Violation, error)

AnalyzeGoProject inspects the analyzed files of every loaded package.

func (*TokenPosOffsetRule) RequiresSSA added in v1.4.2

func (r *TokenPosOffsetRule) RequiresSSA() bool

RequiresSSA reports that typed syntax is enough for this rule.

type TypeAssertionRule

type TypeAssertionRule struct {
	*rules.BaseRule
}

TypeAssertionRule detects unsafe type assertions without comma-ok idiom

func NewTypeAssertionRule

func NewTypeAssertionRule() *TypeAssertionRule

NewTypeAssertionRule creates the rule

func (*TypeAssertionRule) AnalyzeFile

func (r *TypeAssertionRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation

AnalyzeFile checks for unsafe type assertions

Jump to

Keyboard shortcuts

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