lint

package
v1.8.26 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DeprecatedRuleID = "deprecated-rule-id"
View Source
const InternalErrorID = "internal-error"
View Source
const ParseErrorID = "parse-error"
View Source
const SuppressionID = "unknown-suppression"

Variables

This section is empty.

Functions

func AllProfiles

func AllProfiles() []string

func AllowedProfile

func AllowedProfile(p string) bool

func DelegatesToShared added in v1.5.0

func DelegatesToShared(ruleID string) bool

DelegatesToShared reports rules owned by pawn-analysis in editor runs.

func EnableUnderProfile

func EnableUnderProfile(p Profile, id string)

func NormalizeOption

func NormalizeOption(option Option, value any) (any, error)

Types

type AnalysisLevel

type AnalysisLevel uint8
const (
	SyntaxAnalysis AnalysisLevel = iota

	SemanticAnalysis

	ControlFlowAnalysis

	ProjectAnalysis
)

type Context

type Context struct {
	File           *File
	Report         func(diagnostic.Diagnostic)
	Level          AnalysisLevel
	Walk           *walk.Model
	Tokens         func(k token.Kind) []*token.Token
	Supp           []suppress.Directive
	Known          map[string]struct{}
	PerRule        map[string]map[string]any
	Semantic       *semantic.Model
	Flow           *controlflow.Model
	Project        *project.Model
	ProjectFile    *project.File
	Target         string
	API            *api.Metadata
	SharedAnalysis *analysis.Result
	// contains filtered or unexported fields
}

func (*Context) Assignments added in v1.3.0

func (ctx *Context) Assignments(function *parser.Node) []*parser.Node

func (*Context) Callbacks

func (ctx *Context) Callbacks() map[string]api.Callback

func (*Context) Constant

func (ctx *Context) Constant(node *parser.Node) (int64, bool)

func (*Context) Constants

func (ctx *Context) Constants() map[string]api.Constant

func (*Context) Eval

func (ctx *Context) Eval(node *parser.Node) (int64, bool)

func (*Context) ExpressionTag

func (ctx *Context) ExpressionTag(node *parser.Node) (string, bool)

func (*Context) ExpressionTags

func (ctx *Context) ExpressionTags(node *parser.Node) []string

func (*Context) FunctionEffects added in v1.8.0

func (ctx *Context) FunctionEffects(declaration project.Declaration) (project.FunctionEffects, bool)

func (*Context) FunctionSymbols added in v1.3.0

func (ctx *Context) FunctionSymbols(function *parser.Node) []*semantic.Symbol

func (*Context) Functions

func (ctx *Context) Functions() map[string]api.Function

func (*Context) Natives

func (ctx *Context) Natives() map[string]api.Native

func (*Context) Pure

func (ctx *Context) Pure(node *parser.Node) bool

func (*Context) PureCall

func (ctx *Context) PureCall(call *parser.Node) (string, bool)

type Engine

type Engine struct {
	Reg            *Registrar
	Defines        []string
	Target         string
	Project        *project.Model
	API            *api.Metadata
	SharedAnalysis *analysis.Result
	ObserveTiming  func(TimingEvent)
	Context        context.Context
}

func NewEngine

func NewEngine(reg *Registrar) *Engine

func (*Engine) LintFile

func (e *Engine) LintFile(path string, src []byte, maxLevel AnalysisLevel, ruleSet map[string]diagnostic.Severity, known map[string]struct{}, perRule map[string]map[string]any) []diagnostic.Diagnostic

func (*Engine) LintProjectFile

func (e *Engine) LintProjectFile(projectFile *project.File, maxLevel AnalysisLevel, ruleSet map[string]diagnostic.Severity, known map[string]struct{}, perRule map[string]map[string]any) []diagnostic.Diagnostic

type File

type File struct {
	Path      string
	Source    []byte
	Parsed    *parser.File
	LineTable *source.LineTable
}

type Metadata

type Metadata struct {
	ID              string
	Name            string
	Summary         string
	Explanation     string
	Category        diagnostic.Category
	DefaultSeverity diagnostic.Severity
	AnalysisLevel   AnalysisLevel
	Requirements    Requirements
	Scope           RuleScope
	Stability       Stability
	DefaultEnabled  bool
	Fixable         bool
	UnsafeFix       bool
	Tags            []string
	Options         []Option
	ConfigExample   string
}

type Option

type Option struct {
	Name       string
	Summary    string
	Type       OptionType
	Default    any
	Minimum    int64
	Maximum    int64
	HasMinimum bool
	HasMaximum bool
	Choices    []string
	Fields     []Option
	Required   bool
	Validate   func(any) error
}

type OptionType

type OptionType uint8
const (
	OptionBoolean OptionType = iota
	OptionInteger
	OptionString
	OptionStringList
	OptionObjectList
)

func (OptionType) String

func (t OptionType) String() string

type Profile

type Profile string
const (
	ProfileRecommended Profile = "recommended"
	ProfileStrict      Profile = "strict"
	ProfileAll         Profile = "all"
)

type Registrar

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

func NewRegistrar

func NewRegistrar() *Registrar

func (*Registrar) Aliases

func (reg *Registrar) Aliases() []RuleAlias

func (*Registrar) All

func (reg *Registrar) All() []Metadata

func (*Registrar) EnabledForProfile

func (reg *Registrar) EnabledForProfile(p Profile) (enabled map[string]diagnostic.Severity)

func (*Registrar) IDs

func (reg *Registrar) IDs() []string

func (*Registrar) Lookup

func (reg *Registrar) Lookup(id string) (Metadata, bool)

func (*Registrar) MustRegister

func (reg *Registrar) MustRegister(r Rule)

func (*Registrar) MustRegisterAlias

func (reg *Registrar) MustRegisterAlias(deprecated, replacement string)

func (*Registrar) Register

func (reg *Registrar) Register(r Rule) error

func (*Registrar) RegisterAlias

func (reg *Registrar) RegisterAlias(deprecated, replacement string) error

func (*Registrar) ResolveID

func (reg *Registrar) ResolveID(id string) (string, bool, bool)

func (*Registrar) Rule

func (reg *Registrar) Rule(id string) (Rule, bool)

func (*Registrar) Sorted

func (reg *Registrar) Sorted() []Metadata

type Requirements added in v1.2.0

type Requirements uint16
const (
	NeedSyntax Requirements = 1 << iota
	NeedPreprocessor
	NeedLocalSymbols
	NeedNames
	NeedTags
	NeedConstants
	NeedControlFlow
	NeedAPI
	NeedWorkspace
)

func (Requirements) Has added in v1.2.0

func (r Requirements) Has(requirement Requirements) bool

type Rule

type Rule interface {
	Metadata() Metadata
	Run(ctx *Context)
}

type RuleAlias

type RuleAlias struct {
	Deprecated  string
	Replacement string
}

type RuleScope added in v1.2.0

type RuleScope uint8
const (
	ScopeToken RuleScope = iota + 1
	ScopeSyntax
	ScopeFunction
	ScopeDeclaration
	ScopeFile
	ScopeWorkspace
	ScopeExternal
)

type Stability

type Stability uint8
const (
	StabilityStable Stability = iota
	StabilityPreview
)

func (Stability) String

func (s Stability) String() string

type TimingEvent

type TimingEvent struct {
	Stage    TimingStage
	RuleID   string
	Duration time.Duration
}

type TimingStage

type TimingStage string
const (
	TimingParse       TimingStage = "parse"
	TimingSemantic    TimingStage = "semantic"
	TimingControlFlow TimingStage = "control-flow"
	TimingRule        TimingStage = "rule"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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