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
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
type InterfaceAnyRule ¶
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
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 ¶
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