suite

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 55 Imported by: 0

Documentation

Overview

Package yze is the analyzer catalog for the yze family: it aggregates every yze-<name> analyzer's registration and filters the set by category. The cmd/yze binary drives this catalog through the go-yze runner.

Package yze's source-analyzer catalog: which non-Go languages the suite judges, and how each decides which files it reads.

Index

Constants

View Source
const (
	// ErrConfig reports a yze configuration file that cannot be read or parsed.
	ErrConfig errs.Const = "cannot load yze config"
	// ErrSourceSetting reports a config setting supplied for a bundled SQL analyzer,
	// none of which defines any settings.
	ErrSourceSetting errs.Const = "SQL analyzer settings are not supported"
)

Configuration errors.

View Source
const (
	// ErrSourceWalk reports that walking a root for source files failed.
	ErrSourceWalk errs.Const = "cannot walk for source files"
	// ErrSourceRead reports that a source file could not be read.
	ErrSourceRead errs.Const = "cannot read source file"
)

Source run errors.

View Source
const ErrUnknownFormat errs.Const = "unknown output format"

ErrUnknownFormat reports an output format the aggregator does not support.

View Source
const ErrUnknownRuleFormat errs.Const = "unknown rule-export format"

ErrUnknownRuleFormat reports a rule-export format the aggregator does not support.

Variables

This section is empty.

Functions

func ApplySourceConfig

func ApplySourceConfig(analyzers []SourceAnalyzer, settings goyze.Settings) error

ApplySourceConfig checks settings against the suite's SQL analyzers, mirroring goyze.ApplyConfig's semantics: an unknown analyzer name is ignored (a config may target a larger suite than is present), but a setting supplied for a known analyzer must be one it defines — and the SQL analyzers define none, so any setting targeting one is ErrSourceSetting rather than a silent no-op.

func Emit

func Emit(w io.Writer, format Format, report goyze.Report) error

Emit writes the report to w in the named format.

func EmitRules

func EmitRules(w io.Writer, format RuleFormat, rules []Rule) error

EmitRules writes the rule catalog to w in the named format.

func Filter

func Filter(regs []goyze.Registration, categories []goyze.Category) []goyze.Registration

Filter selects the registrations matching the given categories. An empty category set matches every analyzer; otherwise a registration matches when it carries any of the categories.

func GitCheckIgnore

func GitCheckIgnore(files []string) (map[string]bool, error)

GitCheckIgnore is the default CheckIgnore: one `git check-ignore` over all files at once, run from the process working directory — which during a lint pass is inside the repository — reading the ignored subset from its NUL-delimited output.

func LoadConfig

func LoadConfig(read func(path string) ([]byte, error), path ConfigPath) (goyze.Settings, error)

func Registrations

func Registrations() []goyze.Registration

Registrations returns every analyzer in the suite, in stable rule-id order, each carrying the test-file scope its rule warrants.

func RootsOf

func RootsOf(patterns []goyze.Pattern) []string

RootsOf turns package patterns into the directories to walk for .sql files: the recursive "/..." suffix is dropped, and a bare or empty pattern becomes ".".

func RunSource

func RunSource(
	read goyze.FileReader,
	walk WalkDir,
	ignore CheckIgnore,
	analyzers []SourceAnalyzer,
	roots []string,
) (goyze.Report, error)

RunSource finds every file under the roots, drops the ones git ignores (an ignored file is not the repository's owned surface — the same policy the Go-package side applies, failing open when git cannot answer), and runs each analyzer over the files it claims, returning the merged diagnostics. A file no analyzer claims is never even read. A walk or read failure aborts the run.

Types

type CheckIgnore

type CheckIgnore func(files []string) (map[string]bool, error)

CheckIgnore reports which of the given files git ignores. It is the seam a test replaces to drive the filter without a real repository; the command wires GitCheckIgnore.

type ConfigPath

type ConfigPath string

LoadConfig reads and parses a yze config file into per-analyzer settings keyed by analyzer name then setting name, ready for go-yze's ApplyConfig. The reader is injected so callers control filesystem access. ConfigPath is the path to a yze per-analyzer config file.

type Format

type Format string

Format names a way the aggregator serializes a report.

const (
	FormatSticklerJSON Format = "stickler-json"
	FormatText         Format = "text"
)

The output formats cmd/yze supports. Richer formats (sarif, github) live in the stickler runner, which consumes the stickler-json emitted here.

type Rule

type Rule struct {
	ID         string
	Name       string
	Doc        string
	URL        string
	Categories []goyze.Category
}

Rule is one catalog entry: the language-neutral metadata a rule export carries. Both the Go analyzer registrations (via GoRules) and the SQL analyzers (via SQLRules) reduce to this shape, so the exported catalog always describes the whole suite — every rule id a diagnostic can carry has a catalog entry.

func CatalogRules

func CatalogRules(regs []goyze.Registration, analyzers []SourceAnalyzer) []Rule

CatalogRules merges the Go and SQL analyzers' rules into the one catalog `--emit-rules` exports, sorted by rule id so the export order is deterministic regardless of which language contributed an entry.

func GoRules

func GoRules(regs []goyze.Registration) []Rule

GoRules maps the Go analyzer registrations onto their catalog rules.

func SQLRules

func SQLRules(analyzers []SourceAnalyzer) []Rule

SQLRules maps the SQL analyzers onto their catalog rules, under the same "yze/<name>" rule-id scheme their diagnostics carry.

type RuleFormat

type RuleFormat string

RuleFormat names a way the suite's rule catalog is exported. The catalog is built from catalog metadata (id, name, doc, url, categories) — never from analyzer logic — so it carries no per-analyzer machinery.

const (
	// RuleFormatSARIF exports a SARIF 2.1.0 tool.driver.rules catalog for code
	// scanning / editor rule registration.
	RuleFormatSARIF RuleFormat = "sarif"
	// RuleFormatGrit exports a GritQL-style markdown registry. The analyzers are
	// AST-based, not pattern rewrites, so this is a documentation catalog (rule id,
	// description, docs link, categories) — not executable rewrite patterns.
	RuleFormatGrit RuleFormat = "grit"
)

The rule-export formats `yze --emit-rules` supports.

type SourceAnalyzer

type SourceAnalyzer struct {
	// Analyze reports the findings in one file's contents.
	Analyze func(path, source string) ([]goyze.Diagnostic, error)
	// Claims reports whether this analyzer reads a given path at all. Each
	// analyzer owns the rule for what it reads, because only it knows: SQL is
	// an extension, a workflow is a directory, a shell script may be
	// extensionless. A single suffix baked into the runner made the suite able
	// to host exactly one language.
	Claims     func(path string) bool
	Name       goyze.AnalyzerName
	Doc        string
	URL        goyze.HelpURL
	Categories []goyze.Category
}

SourceAnalyzer is a source analyzer the suite runs over .sql files, as opposed to the go/analysis analyzers it runs over Go packages. Its diagnostics already use the shared go-yze contract, so they merge into the same report; Doc and URL are the catalog metadata mirroring goyze.Registration, so the rule exports list SQL rules alongside the Go ones.

func FilterSource

func FilterSource(analyzers []SourceAnalyzer, categories []goyze.Category) []SourceAnalyzer

FilterSource selects the SQL analyzers matching the given categories, mirroring Filter. An empty category set matches every analyzer.

func SourceAnalyzers

func SourceAnalyzers() []SourceAnalyzer

SourceAnalyzers returns every source analyzer bundled into the suite, in stable rule-id order.

A source analyzer judges a FILE rather than a Go package, so the suite hosts more than one language: SQL by extension, markdown documents by name, shell scripts, and GitHub workflows by their directory. Each analyzer owns the rule for what it reads, because only it knows — which is why SourceAnalyzer.Claims is a function here rather than a suffix baked into the runner.

CLAIM ONLY WHAT CAN BE REPORTED. The runner reads a claimed file before analysing it, so a claim wider than the verdict costs a read per file and, worse, lets one unreadable file fail a whole run. `markup` therefore claims exactly the names it convicts rather than every path it could be asked about.

func (SourceAnalyzer) RuleID

func (a SourceAnalyzer) RuleID() string

RuleID returns the stable rule identifier "yze/<name>" carried by every diagnostic the analyzer emits, mirroring goyze.Registration.RuleID so both languages share one flat id scheme.

type WalkDir

type WalkDir func(root string, fn fs.WalkDirFunc) error

WalkDir is fs.WalkDir's signature. It's injected so a test can drive the file walk without a real directory tree.

Jump to

Keyboard shortcuts

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