rules

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: 0BSD Imports: 21 Imported by: 0

Documentation

Overview

Package rules defines native lint-rule contracts and canonical metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodePrototype

func NodePrototype(kind NodeKind) (ast.Node, bool)

NodePrototype returns the ast/inspector filter prototype for one interest.

Types

type Category

type Category string

Category classifies the observable concern reported by a rule.

const (
	CategoryCorrectness     Category = "correctness"
	CategorySafety          Category = "safety"
	CategorySuspicious      Category = "suspicious"
	CategoryPerformance     Category = "performance"
	CategoryComplexity      Category = "complexity"
	CategoryStyle           Category = "style"
	CategoryMigration       Category = "migration"
	CategoryMaintainability Category = "maintainability"
)

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context is the immutable per-file syntax rule context.

func NewContext

func NewContext(file *source.File, options OptionSet) *Context

NewContext creates an immutable per-file rule context.

func (*Context) BooleanOption

func (c *Context) BooleanOption(name string) (bool, bool)

BooleanOption returns one configured boolean rule option.

func (*Context) File

func (c *Context) File() *source.File

File returns the exact immutable source version for the syntax rule.

func (*Context) IntegerOption

func (c *Context) IntegerOption(name string) (int64, bool)

IntegerOption returns one configured integer rule option.

func (*Context) PositionRange

func (c *Context) PositionRange(start, end token.Pos) (source.Range, error)

PositionRange converts a token range when a caller already owns positions.

func (*Context) PreviousSignificantToken

func (c *Context) PreviousSignificantToken(position token.Pos) (source.Token, bool)

PreviousSignificantToken returns the lexical token before a parsed position, ignoring comments and automatically inserted semicolons.

func (*Context) Range

func (c *Context) Range(node ast.Node) (source.Range, error)

Range maps an isolated syntax node to its exact physical byte range.

func (*Context) StringOption

func (c *Context) StringOption(name string) (string, bool)

StringOption returns one configured string rule option.

func (*Context) StringsOption

func (c *Context) StringsOption(name string) ([]string, bool)

StringsOption returns one independently owned string-list rule option.

type ControlFlowContext

type ControlFlowContext struct {
	// contains filtered or unexported fields
}

ControlFlowContext binds one function graph to its shared typed package and exact immutable physical source.

func NewControlFlowContext

func NewControlFlowContext(
	typesContext *TypesContext,
	function ast.Node,
	body *ast.BlockStmt,
	graph *cfg.CFG,
) *ControlFlowContext

NewControlFlowContext constructs one read-only control-flow rule context.

func (*ControlFlowContext) Body

func (c *ControlFlowContext) Body() *ast.BlockStmt

Body returns the function body used to construct the graph.

func (*ControlFlowContext) BooleanOption

func (c *ControlFlowContext) BooleanOption(name string) (bool, bool)

BooleanOption returns one configured boolean rule option.

func (*ControlFlowContext) File

func (c *ControlFlowContext) File() *source.File

File returns the exact immutable source version for the current package AST.

func (*ControlFlowContext) Function

func (c *ControlFlowContext) Function() ast.Node

Function returns the function declaration or literal that owns the graph.

func (*ControlFlowContext) Graph

func (c *ControlFlowContext) Graph() *cfg.CFG

Graph returns the shared read-only control-flow graph for the function.

func (*ControlFlowContext) IllTyped

func (c *ControlFlowContext) IllTyped() bool

IllTyped reports whether package loading encountered type errors.

func (*ControlFlowContext) Info

func (c *ControlFlowContext) Info() *types.Info

Info returns the shared read-only type information for package AST nodes.

func (*ControlFlowContext) IntegerOption

func (c *ControlFlowContext) IntegerOption(name string) (int64, bool)

IntegerOption returns one configured integer rule option.

func (*ControlFlowContext) Package

func (c *ControlFlowContext) Package() *types.Package

Package returns the shared read-only go/types package.

func (*ControlFlowContext) PackageID

func (c *ControlFlowContext) PackageID() string

PackageID returns the opaque go/packages identity for the current package.

func (*ControlFlowContext) PositionRange

func (c *ControlFlowContext) PositionRange(start, end token.Pos) (source.Range, error)

PositionRange maps package positions to the exact current physical source.

func (*ControlFlowContext) Range

func (c *ControlFlowContext) Range(node ast.Node) (source.Range, error)

Range maps a package AST node to its current physical source range.

func (*ControlFlowContext) StringOption

func (c *ControlFlowContext) StringOption(name string) (string, bool)

StringOption returns one configured string rule option.

func (*ControlFlowContext) StringsOption

func (c *ControlFlowContext) StringsOption(name string) ([]string, bool)

StringsOption returns one independently owned string-list rule option.

type ControlFlowRule

type ControlFlowRule interface {
	Rule
	RunControlFlow(*ControlFlowContext) ([]Finding, error)
}

ControlFlowRule runs once for each function declaration and function literal through a graph shared with every enabled control-flow rule.

type Deprecation

type Deprecation struct {
	Since       string
	Replacement string
	Message     string
}

Deprecation records a rule replacement without silently changing its ID.

type Diagnostic

type Diagnostic struct {
	RuleID     string
	Severity   Severity
	MessageKey string
	Message    string
	Path       string
	Digest     source.Digest
	Range      source.Range
	Related    []Related
	Notes      []string
	Help       string
	Fixes      []Fix
}

Diagnostic is one source-versioned, reporter-ready lint diagnostic.

type Edit

type Edit struct {
	Range   source.Range
	NewText string
}

Edit is one exact byte replacement proposed by a fix.

type Example

type Example struct {
	Title     string
	Incorrect string
	Correct   string
}

Example is one paired incorrect and correct rule example.

type Finding

type Finding struct {
	MessageKey string
	Message    string
	Range      source.Range
	Related    []Related
	Notes      []string
	Help       string
	Fixes      []Fix
}

Finding is the rule-owned portion of a diagnostic.

type Fix

type Fix struct {
	Name   string
	Safety FixSafety
	Edits  []Edit
}

Fix is one named, safety-classified set of source edits.

type FixMetadata

type FixMetadata struct {
	Name        string
	Description string
	Safety      FixSafety
}

FixMetadata describes one named transformation a rule may offer.

type FixSafety

type FixSafety string

FixSafety controls whether a fix may run without an explicit opt-in.

const (
	FixSafe       FixSafety = "safe"
	FixSuggestion FixSafety = "suggestion"
	FixUnsafe     FixSafety = "unsafe"
)

type Metadata

type Metadata struct {
	ID                       string
	Summary                  string
	Documentation            string
	DefaultSeverity          Severity
	Presets                  []Preset
	MinimumGoVersion         string
	Requirement              Requirement
	NodeInterests            []NodeKind
	RequiresDependencySyntax bool
	RunOnGenerated           bool
	RunDespiteTypeErrors     bool
	Categories               []Category
	Fixes                    []FixMetadata
	Options                  []OptionMetadata
	Deprecation              *Deprecation
	KnownLimitations         []string
	Examples                 []Example
}

Metadata is the canonical rule documentation and scheduling contract.

func CloneMetadata

func CloneMetadata(metadata Metadata) Metadata

CloneMetadata returns an independent copy of rule metadata.

type NodeKind

type NodeKind string

NodeKind is a stable native interest in one Go syntax node type.

const (
	NodeFile           NodeKind = "file"
	NodeComment        NodeKind = "comment"
	NodeCommentGroup   NodeKind = "comment-group"
	NodeField          NodeKind = "field"
	NodeFieldList      NodeKind = "field-list"
	NodeBadExpr        NodeKind = "bad-expr"
	NodeIdent          NodeKind = "ident"
	NodeEllipsis       NodeKind = "ellipsis"
	NodeBasicLit       NodeKind = "basic-lit"
	NodeFuncLit        NodeKind = "func-lit"
	NodeCompositeLit   NodeKind = "composite-lit"
	NodeParenExpr      NodeKind = "paren-expr"
	NodeSelectorExpr   NodeKind = "selector-expr"
	NodeIndexExpr      NodeKind = "index-expr"
	NodeIndexListExpr  NodeKind = "index-list-expr"
	NodeSliceExpr      NodeKind = "slice-expr"
	NodeTypeAssertExpr NodeKind = "type-assert-expr"
	NodeCallExpr       NodeKind = "call-expr"
	NodeStarExpr       NodeKind = "star-expr"
	NodeUnaryExpr      NodeKind = "unary-expr"
	NodeBinaryExpr     NodeKind = "binary-expr"
	NodeKeyValueExpr   NodeKind = "key-value-expr"
	NodeArrayType      NodeKind = "array-type"
	NodeStructType     NodeKind = "struct-type"
	NodeFuncType       NodeKind = "func-type"
	NodeInterfaceType  NodeKind = "interface-type"
	NodeMapType        NodeKind = "map-type"
	NodeChanType       NodeKind = "chan-type"
	NodeBadStmt        NodeKind = "bad-stmt"
	NodeDeclStmt       NodeKind = "decl-stmt"
	NodeEmptyStmt      NodeKind = "empty-stmt"
	NodeLabeledStmt    NodeKind = "labeled-stmt"
	NodeExprStmt       NodeKind = "expr-stmt"
	NodeSendStmt       NodeKind = "send-stmt"
	NodeIncDecStmt     NodeKind = "inc-dec-stmt"
	NodeAssignStmt     NodeKind = "assign-stmt"
	NodeGoStmt         NodeKind = "go-stmt"
	NodeDeferStmt      NodeKind = "defer-stmt"
	NodeReturnStmt     NodeKind = "return-stmt"
	NodeBranchStmt     NodeKind = "branch-stmt"
	NodeBlockStmt      NodeKind = "block-stmt"
	NodeIfStmt         NodeKind = "if-stmt"
	NodeCaseClause     NodeKind = "case-clause"
	NodeSwitchStmt     NodeKind = "switch-stmt"
	NodeTypeSwitchStmt NodeKind = "type-switch-stmt"
	NodeCommClause     NodeKind = "comm-clause"
	NodeSelectStmt     NodeKind = "select-stmt"
	NodeForStmt        NodeKind = "for-stmt"
	NodeRangeStmt      NodeKind = "range-stmt"
	NodeBadDecl        NodeKind = "bad-decl"
	NodeGenDecl        NodeKind = "gen-decl"
	NodeFuncDecl       NodeKind = "func-decl"
	NodeImportSpec     NodeKind = "import-spec"
	NodeValueSpec      NodeKind = "value-spec"
	NodeTypeSpec       NodeKind = "type-spec"
)

func KindOf

func KindOf(node ast.Node) (NodeKind, bool)

KindOf returns the stable interest name for a concrete syntax node.

type OptionKind

type OptionKind string

OptionKind is the scalar type accepted by one rule option.

const (
	OptionBoolean OptionKind = "boolean"
	OptionInteger OptionKind = "integer"
	OptionString  OptionKind = "string"
	OptionStrings OptionKind = "strings"
)

type OptionMetadata

type OptionMetadata struct {
	Name     string
	Summary  string
	Kind     OptionKind
	Required bool
	Default  *OptionValue
}

OptionMetadata is one typed configuration field owned by a rule.

type OptionSet

type OptionSet struct {
	// contains filtered or unexported fields
}

OptionSet is one immutable name-indexed rule configuration snapshot.

func NewOptionSet

func NewOptionSet(values map[string]OptionValue) OptionSet

NewOptionSet snapshots independently owned rule option values.

func (OptionSet) Boolean

func (s OptionSet) Boolean(name string) (bool, bool)

Boolean returns one configured boolean value.

func (OptionSet) CanonicalBytes

func (s OptionSet) CanonicalBytes() []byte

CanonicalBytes returns one deterministic cache identity for this option set.

func (OptionSet) Integer

func (s OptionSet) Integer(name string) (int64, bool)

Integer returns one configured integer value.

func (OptionSet) String

func (s OptionSet) String(name string) (string, bool)

String returns one configured string value.

func (OptionSet) Strings

func (s OptionSet) Strings(name string) ([]string, bool)

Strings returns one independently owned configured string list.

type OptionValue

type OptionValue struct {
	// contains filtered or unexported fields
}

OptionValue is one immutable typed rule configuration value.

func BooleanOption

func BooleanOption(value bool) OptionValue

BooleanOption constructs one boolean rule option value.

func IntegerOption

func IntegerOption(value int64) OptionValue

IntegerOption constructs one integer rule option value.

func StringOption

func StringOption(value string) OptionValue

StringOption constructs one string rule option value.

func StringsOption

func StringsOption(value []string) OptionValue

StringsOption constructs one independently owned string-list rule option.

func (OptionValue) Kind

func (v OptionValue) Kind() OptionKind

Kind returns the declared scalar kind of this value.

func (OptionValue) String

func (v OptionValue) String() string

String renders one deterministic human-readable option value.

type PackageContext

type PackageContext struct {
	// contains filtered or unexported fields
}

PackageContext exposes one shared typed package and its canonical physical source mapping to a package-wide native rule.

func NewPackageContext

func NewPackageContext(
	fileSet *token.FileSet,
	packageID string,
	package_ *types.Package,
	info *types.Info,
	sizes types.Sizes,
	illTyped bool,
	files []PackageFile,
	dependencies []PackageDependency,
	options OptionSet,
) *PackageContext

NewPackageContext constructs one read-only package-wide rule context.

func (*PackageContext) BooleanOption

func (c *PackageContext) BooleanOption(name string) (bool, bool)

BooleanOption returns one configured boolean rule option.

func (*PackageContext) Dependencies

func (c *PackageContext) Dependencies() []PackageDependency

Dependencies returns dependency packages in deterministic dependency-first order. Rules without a declared dependency-syntax requirement receive none.

func (*PackageContext) FileSet

func (c *PackageContext) FileSet() *token.FileSet

FileSet returns the shared read-only package position mapping.

func (*PackageContext) Files

func (c *PackageContext) Files() []PackageFile

Files returns independent descriptors in canonical physical path order.

func (*PackageContext) IllTyped

func (c *PackageContext) IllTyped() bool

IllTyped reports whether package loading encountered type errors.

func (*PackageContext) Info

func (c *PackageContext) Info() *types.Info

Info returns the shared read-only type information for package AST nodes.

func (*PackageContext) IntegerOption

func (c *PackageContext) IntegerOption(name string) (int64, bool)

IntegerOption returns one configured integer rule option.

func (*PackageContext) OwnsTarget

func (c *PackageContext) OwnsTarget(file PackageFile) bool

OwnsTarget reports whether a descriptor came from this exact callback and is eligible for reporter-visible output.

func (*PackageContext) Package

func (c *PackageContext) Package() *types.Package

Package returns the shared read-only go/types package.

func (*PackageContext) PackageID

func (c *PackageContext) PackageID() string

PackageID returns the opaque go/packages identity for this package.

func (*PackageContext) Sizes

func (c *PackageContext) Sizes() types.Sizes

Sizes returns the shared architecture-specific type-size implementation.

func (*PackageContext) StringOption

func (c *PackageContext) StringOption(name string) (string, bool)

StringOption returns one configured string rule option.

func (*PackageContext) StringsOption

func (c *PackageContext) StringsOption(name string) ([]string, bool)

StringsOption returns one independently owned string-list rule option.

type PackageDependency

type PackageDependency struct {
	// contains filtered or unexported fields
}

PackageDependency is one immutable dependency package view exposed only to package-wide rules that declare dependency syntax in canonical metadata.

func NewPackageDependency

func NewPackageDependency(
	fileSet *token.FileSet,
	packageID string,
	package_ *types.Package,
	info *types.Info,
	sizes types.Sizes,
	illTyped bool,
	files []PackageFile,
) PackageDependency

NewPackageDependency constructs one read-only dependency-package view.

func (PackageDependency) FileSet

func (d PackageDependency) FileSet() *token.FileSet

FileSet returns the dependency's shared read-only position mapping.

func (PackageDependency) Files

func (d PackageDependency) Files() []PackageFile

Files returns independent, non-target dependency file descriptors in canonical physical path order.

func (PackageDependency) IllTyped

func (d PackageDependency) IllTyped() bool

IllTyped reports whether dependency loading encountered type errors.

func (PackageDependency) Info

func (d PackageDependency) Info() *types.Info

Info returns the shared read-only type information for dependency AST nodes.

func (PackageDependency) Package

func (d PackageDependency) Package() *types.Package

Package returns the shared read-only go/types package for this dependency.

func (PackageDependency) PackageID

func (d PackageDependency) PackageID() string

PackageID returns the opaque go/packages identity for this dependency.

func (PackageDependency) Sizes

func (d PackageDependency) Sizes() types.Sizes

Sizes returns the dependency's architecture-specific type sizes.

type PackageFile

type PackageFile struct {
	// contains filtered or unexported fields
}

PackageFile binds one package AST to its exact immutable physical source and records whether the current package invocation owns reporter-visible output for that file.

func NewPackageFile

func NewPackageFile(
	file *source.File,
	syntax *ast.File,
	fileSet *token.FileSet,
	target bool,
) PackageFile

NewPackageFile constructs one read-only package-file view.

func (PackageFile) PositionRange

func (f PackageFile) PositionRange(start, end token.Pos) (source.Range, error)

PositionRange maps package positions to this exact physical source.

func (PackageFile) Range

func (f PackageFile) Range(node ast.Node) (source.Range, error)

Range maps an AST node to this package file's exact physical byte range.

func (PackageFile) Source

func (f PackageFile) Source() *source.File

Source returns the exact immutable source captured for this package file.

func (PackageFile) Syntax

func (f PackageFile) Syntax() *ast.File

Syntax returns the shared package AST for this physical file.

func (PackageFile) Target

func (f PackageFile) Target() bool

Target reports whether this package invocation owns diagnostics for the file.

func (PackageFile) TokenRange

func (f PackageFile) TokenRange(position token.Pos) (source.Range, error)

TokenRange maps a package position to this file's exact lexical token.

type PackageFinding

type PackageFinding struct {
	File    PackageFile
	Finding Finding
}

PackageFinding binds one ordinary finding to the owned physical file it targets.

type PackageRule

type PackageRule interface {
	Rule
	RunPackage(*PackageContext) ([]PackageFinding, error)
}

PackageRule runs once for each selected typed package and may report against the package's canonically owned physical source files.

type Preset

type Preset string

Preset is one coherent built-in rule group.

const (
	PresetCorrectness Preset = "correctness"
	PresetSuspicious  Preset = "suspicious"
	PresetPerformance Preset = "performance"
	PresetComplexity  Preset = "complexity"
	PresetStyle       Preset = "style"
	PresetMigration   Preset = "migration"
)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is an immutable, ID-ordered native rule set.

func NewDefaultRegistry

func NewDefaultRegistry() (*Registry, error)

NewDefaultRegistry constructs the canonical built-in rule registry.

func NewRegistry

func NewRegistry(nativeRules ...Rule) (*Registry, error)

NewRegistry validates and snapshots native rules.

func (*Registry) IDs

func (r *Registry) IDs() []string

IDs returns registered IDs in canonical order.

func (*Registry) Lookup

func (r *Registry) Lookup(id string) (Rule, bool)

Lookup returns one registered native rule.

func (*Registry) Metadata

func (r *Registry) Metadata(id string) (Metadata, bool)

Metadata returns an independent metadata copy for one rule.

func (*Registry) OptionSchemas

func (r *Registry) OptionSchemas() map[string][]OptionMetadata

OptionSchemas returns independent typed option metadata by rule ID.

func (*Registry) Resolve

func (r *Registry) Resolve(preset Preset, overrides map[string]Severity) ([]Selection, error)

Resolve applies one preset and explicit overrides into an ordered selection.

func (*Registry) ResolveConfigured

func (r *Registry) ResolveConfigured(
	preset Preset,
	overrides map[string]Severity,
	options map[string]OptionSet,
) ([]Selection, error)

ResolveConfigured applies severity and typed option configuration into an ordered immutable selection.

func (*Registry) ResolveConfiguredForGoVersion

func (r *Registry) ResolveConfiguredForGoVersion(
	preset Preset,
	overrides map[string]Severity,
	options map[string]OptionSet,
	sourceGoVersion string,
) ([]Selection, error)

ResolveConfiguredForGoVersion applies configuration and omits rules whose declared minimum exceeds the selected normalized source language version. An empty source version retains the version-independent registry contract.

type Related struct {
	Range   source.Range
	Message string
}

Related identifies a secondary physical source range.

type Requirement

type Requirement uint8

Requirement is the most expensive representation a rule requires.

const (
	RequireLexical Requirement = iota
	RequireSyntax
	RequireTypes
	RequireControlFlow
	RequireSSA
)

func MaximumRequirement

func MaximumRequirement(selection []Selection) Requirement

MaximumRequirement returns the most expensive selected representation.

func (Requirement) String

func (r Requirement) String() string

type Rule

type Rule interface {
	Metadata() Metadata
}

Rule is the common metadata boundary implemented by every native rule.

type SSAContext

type SSAContext struct {
	// contains filtered or unexported fields
}

SSAContext binds one source function to its shared SSA program, typed package, and exact immutable physical source.

func NewSSAContext

func NewSSAContext(
	typesContext *TypesContext,
	program *ssa.Program,
	ssaPackage *ssa.Package,
	function *ssa.Function,
	syntax ast.Node,
) *SSAContext

NewSSAContext constructs one read-only SSA rule context.

func (*SSAContext) BooleanOption

func (c *SSAContext) BooleanOption(name string) (bool, bool)

BooleanOption returns one configured boolean rule option.

func (*SSAContext) File

func (c *SSAContext) File() *source.File

File returns the exact immutable source version for the current package AST.

func (*SSAContext) FileSet

func (c *SSAContext) FileSet() *token.FileSet

FileSet returns the shared read-only package position mapping.

func (*SSAContext) Function

func (c *SSAContext) Function() *ssa.Function

Function returns the shared read-only SSA function.

func (*SSAContext) IllTyped

func (c *SSAContext) IllTyped() bool

IllTyped reports whether package loading encountered type errors.

func (*SSAContext) Info

func (c *SSAContext) Info() *types.Info

Info returns the shared read-only type information for package AST nodes.

func (*SSAContext) IntegerOption

func (c *SSAContext) IntegerOption(name string) (int64, bool)

IntegerOption returns one configured integer rule option.

func (*SSAContext) Package

func (c *SSAContext) Package() *types.Package

Package returns the shared read-only go/types package.

func (*SSAContext) PackageID

func (c *SSAContext) PackageID() string

PackageID returns the opaque go/packages identity for the current package.

func (*SSAContext) PositionRange

func (c *SSAContext) PositionRange(start, end token.Pos) (source.Range, error)

PositionRange maps package positions to the exact current physical source.

func (*SSAContext) Program

func (c *SSAContext) Program() *ssa.Program

Program returns the shared read-only SSA program for the package load.

func (*SSAContext) Range

func (c *SSAContext) Range(node ast.Node) (source.Range, error)

Range maps a package AST node to its current physical source range.

func (*SSAContext) SSAPackage

func (c *SSAContext) SSAPackage() *ssa.Package

SSAPackage returns the shared read-only SSA package for the function.

func (*SSAContext) StringOption

func (c *SSAContext) StringOption(name string) (string, bool)

StringOption returns one configured string rule option.

func (*SSAContext) StringsOption

func (c *SSAContext) StringsOption(name string) ([]string, bool)

StringsOption returns one independently owned string-list rule option.

func (*SSAContext) Syntax

func (c *SSAContext) Syntax() ast.Node

Syntax returns the function declaration or literal represented by Function.

func (*SSAContext) TokenRange

func (c *SSAContext) TokenRange(position token.Pos) (source.Range, error)

TokenRange maps a package position to the exact physical lexical token.

type SSARule

type SSARule interface {
	Rule
	RunSSA(*SSAContext) ([]Finding, error)
}

SSARule runs once for each source function through a program shared with every enabled SSA rule.

type Selection

type Selection struct {
	ID          string
	Severity    Severity
	Requirement Requirement
	Options     OptionSet
}

Selection is one enabled rule with its resolved severity and cost.

type Severity

type Severity string

Severity is the configured diagnostic level for one rule.

const (
	SeverityOff   Severity = "off"
	SeverityWarn  Severity = "warn"
	SeverityError Severity = "error"
)

type SyntaxFileRule

type SyntaxFileRule interface {
	Rule
	RunSyntaxFile(*Context) ([]Finding, error)
}

SyntaxFileRule runs once over one immutable source-backed syntax view.

type SyntaxRule

type SyntaxRule interface {
	Rule
	RunSyntax(*Context, ast.Node) ([]Finding, error)
}

SyntaxRule receives only nodes matching its declared interests.

type TypesContext

type TypesContext struct {
	// contains filtered or unexported fields
}

TypesContext binds one package AST to its exact immutable physical source.

func NewTypesContext

func NewTypesContext(
	file *source.File,
	fileSet *token.FileSet,
	packageID string,
	package_ *types.Package,
	info *types.Info,
	illTyped bool,
	options OptionSet,
) *TypesContext

NewTypesContext constructs one read-only typed rule context.

func (*TypesContext) BooleanOption

func (c *TypesContext) BooleanOption(name string) (bool, bool)

BooleanOption returns one configured boolean rule option.

func (*TypesContext) File

func (c *TypesContext) File() *source.File

File returns the exact immutable source version for the current package AST.

func (*TypesContext) IllTyped

func (c *TypesContext) IllTyped() bool

IllTyped reports whether package loading encountered type errors.

func (*TypesContext) Info

func (c *TypesContext) Info() *types.Info

Info returns the shared read-only type information for package AST nodes.

func (*TypesContext) IntegerOption

func (c *TypesContext) IntegerOption(name string) (int64, bool)

IntegerOption returns one configured integer rule option.

func (*TypesContext) Package

func (c *TypesContext) Package() *types.Package

Package returns the shared read-only go/types package.

func (*TypesContext) PackageID

func (c *TypesContext) PackageID() string

PackageID returns the opaque go/packages identity for the current package.

func (*TypesContext) PositionRange

func (c *TypesContext) PositionRange(start, end token.Pos) (source.Range, error)

PositionRange maps package positions to the exact current physical source.

func (*TypesContext) Range

func (c *TypesContext) Range(node ast.Node) (source.Range, error)

Range maps a package AST node to its current physical source range.

func (*TypesContext) StringOption

func (c *TypesContext) StringOption(name string) (string, bool)

StringOption returns one configured string rule option.

func (*TypesContext) StringsOption

func (c *TypesContext) StringsOption(name string) ([]string, bool)

StringsOption returns one independently owned string-list rule option.

func (*TypesContext) TokenRange

func (c *TypesContext) TokenRange(position token.Pos) (source.Range, error)

TokenRange maps a package position to the exact physical lexical token.

type TypesRule

type TypesRule interface {
	Rule
	RunTypes(*TypesContext, ast.Node) ([]Finding, error)
}

TypesRule receives package AST nodes with shared type information and exact physical source identity.

Jump to

Keyboard shortcuts

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