Documentation
¶
Overview ¶
Package custos is the Go API for rules written in Go. A program that imports it and calls Main is a complete custos binary (analyse, fix, explain, rules, the language server and the MCP server) that also runs its own rules:
package main
import (
"github.com/janalis/custos/pkg/custos"
"github.com/janalis/custos/pkg/custos/ast"
)
func main() {
noEval := custos.MustRule(custos.Info{ID: "NoEval", Summary: "eval runs arbitrary code."},
[]ast.NodeKind{ast.KEval},
func(ctx *custos.Context, n ast.Node) { ctx.ReportNode(n, "Remove eval") })
custos.Main("my-custos", noEval)
}
Rules can also be declared as patterns, as in custos.json (Pattern).
The API is unstable until custos 1.0: it exposes the engine's own types.
Index ¶
- Constants
- func Main(version string, rules ...Rule)
- func Run(version string, args []string, stdin io.Reader, stdout, stderr io.Writer, ...) int
- type Context
- type Described
- type Description
- type Facts
- type FileRule
- type Fix
- type Info
- type PatternDefinition
- type Patterns
- type Rule
- type SemanticRule
- type Severity
- type TextEdit
- type Where
Constants ¶
const ( SeverityError = diagnostic.SeverityError SeverityWarning = diagnostic.SeverityWarning SeverityInfo = diagnostic.SeverityInfo )
Severities.
const Group = pattern.Group
Group is the rule group of every rule outside the built-in catalogue.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
Context gives a rule the file under analysis, name resolution, type inference and reporting.
type Described ¶
Described is implemented by rules carrying their own facts, as every rule outside the built-in catalogue must.
type Info ¶
type Info struct {
ID string // an uppercase letter, then letters and digits
Severity Severity // default SeverityWarning
Disabled bool // off unless enabled in custos.json or run with --rule
Summary string // shown by custos explain and in SARIF output
HasFix bool // the rule offers quick-fixes
PHPMin string // minimum target PHP version, documentation only
}
Info describes a rule written in Go.
type PatternDefinition ¶
type PatternDefinition = pattern.Definition
PatternDefinition declares a pattern rule, as in custos.json.
type Rule ¶
Rule is one inspection. Implementations must be stateless and safe for concurrent use; per-file state lives in Context.
func Pattern ¶
func Pattern(d PatternDefinition) (Rule, error)
Pattern compiles a rule declared as a code pattern (see the custom rules guide).
type SemanticRule ¶
type SemanticRule = analysis.SemanticRule
SemanticRule marks rules that need the project's declarations (other files, dependencies) indexed before analysis.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ast exposes the PHP syntax tree that custom rules written in Go inspect: node types and kinds, token kinds and navigation helpers.
|
Package ast exposes the PHP syntax tree that custom rules written in Go inspect: node types and kinds, token kinds and navigation helpers. |