conformance

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package conformance checks rule implementations against annotated fixtures (see package markup for their format).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ParseMarkup strips the expectation tags of a fixture.
	ParseMarkup = markup.Parse
	// SortExpectations orders expectations by position.
	SortExpectations = markup.Sort
)

Functions

func ReadEA

func ReadEA(idx *EAIndex, rel string) ([]byte, error)

ReadEA reads a file of the EA checkout (never copied into the repo).

Types

type CompareOptions

type CompareOptions struct {
	Messages bool // compare message text (own fixtures only; EA text is never compared)
	// OnlyPrefixed keeps only expectations whose message has this prefix
	// (EA: "[EA] "), dropping IDE syntax-error markers.
	OnlyPrefixed string
	// HideExpected suppresses expected fix text in diffs (EA fixtures).
	HideExpected bool
	// NoFixWithoutFixed requires a fixture without expected fix output to
	// be left as it is by the fixes (own fixtures: a quick-fix is always
	// shown by a .fixed file).
	NoFixWithoutFixed bool
}

CompareOptions selects what is compared.

type EACase

type EACase struct {
	Test            string            `json:"test"`
	Rules           []string          `json:"rules"`
	Fixture         string            `json:"fixture"`
	Fixed           string            `json:"fixed,omitempty"`
	PHP             string            `json:"php,omitempty"`
	ComparisonStyle string            `json:"comparisonStyle,omitempty"`
	Options         map[string]string `json:"options,omitempty"`
	Calls           []string          `json:"calls,omitempty"`
	Companions      []string          `json:"companions,omitempty"`
}

EACase mirrors tools/extract's Case.

type EAIndex

type EAIndex struct {
	EAPath string   `json:"eaPath"`
	Cases  []EACase `json:"cases"`
}

EAIndex mirrors the parts of tools/extract's Index the harness needs.

func LoadEAIndex

func LoadEAIndex(path string) (*EAIndex, error)

LoadEAIndex reads the local-only index produced by `make extract`.

type Engine

type Engine interface {
	// Supports reports whether every given rule is implemented.
	Supports(rules []string) bool
	// Analyze returns findings for req.
	Analyze(req Request) ([]Finding, error)
	// Fix applies the available fixes in one pass and returns the result.
	Fix(req Request) ([]byte, error)
}

Engine is implemented by the analysis engine adapter.

type Expectation

type Expectation = markup.Expectation

Expectation is one expected finding of a fixture (see package markup).

type Finding

type Finding struct {
	Rule     string
	Severity diagnostic.Severity
	Message  string
	Start    int
	End      int
}

Finding is one reported problem, as seen by the harness.

type Request

type Request struct {
	Path            string
	Source          []byte
	Rules           []string          // rule IDs to enable (all others off)
	PHP             string            // target PHP version, "" = default
	ComparisonStyle string            // "", "regular", "yoda"
	Options         map[string]string // "Rule.OPTION" -> raw value
	Calls           []string          // raw option calls (EA list options)
	// Companions are extra project files (path -> clean source) whose
	// symbols are visible to the analyzed file.
	Companions map[string][]byte
	// CompleteWorld marks the indexed files as everything the project can
	// load (see index.World).
	CompleteWorld bool
	// Vendor is the project's vendor directory (see index.World.Vendor).
	Vendor string
	// Extensions are the PHP extensions the project requires (see
	// index.World.Extensions).
	Extensions []string
	// Assertions trusts assert() calls as guards (flow.assertions).
	Assertions bool
}

Request is one analysis run over a fixture.

type Result

type Result struct {
	Missing    []Expectation // expected but not reported
	Unexpected []Expectation // reported but not expected
	FixDiff    string        // non-empty when the fixed output differs
}

Result of checking one case.

func Check

func Check(engine Engine, req Request, marked, fixed []byte, opt CompareOptions) (Result, error)

Check runs engine on a marked-up fixture and compares the outcome. fixed may be nil when the case has no expected fix output.

func (Result) OK

func (r Result) OK() bool

OK reports whether the case passed.

Jump to

Keyboard shortcuts

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