pattern

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 21 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 pattern compiles the custom rules a project declares in its configuration: PHP code patterns with metavariables, matched on resolved names, with an optional quick-fix template.

Index

Constants

View Source
const Group = "Custom"

Group is the rule group of every custom rule.

Variables

This section is empty.

Functions

func CheckID

func CheckID(id string) error

CheckID checks the ID of a rule outside the catalogue: an uppercase letter then letters and digits, naming no built-in rule.

func Compile

func Compile(d Definition) (analysis.Rule, error)

Compile checks d and returns the rule it declares.

Types

type Definition

type Definition struct {
	ID    string           `json:"id"`
	Match Patterns         `json:"match"`
	Where map[string]Where `json:"where,omitempty"`
	// Inside lists code the match must lie within (one must match an
	// enclosing node); NotInside, code it must not lie within.
	Inside      Patterns `json:"inside,omitempty"`
	NotInside   Patterns `json:"notInside,omitempty"`
	Message     string   `json:"message"`
	Severity    string   `json:"severity,omitempty"` // error | warning (default) | info
	Enabled     *bool    `json:"enabled,omitempty"`  // default true
	Description string   `json:"description,omitempty"`
	PHP         string   `json:"php,omitempty"` // minimum target PHP version
	Paths       []string `json:"paths,omitempty"`
	Exclude     []string `json:"exclude,omitempty"`
	Fix         *string  `json:"fix,omitempty"`
	FixTitle    string   `json:"fixTitle,omitempty"`
}

Definition is the JSON shape of one custom rule.

type Patterns

type Patterns []string

Patterns is one pattern or a list of them; JSON accepts both forms.

func (*Patterns) UnmarshalJSON

func (p *Patterns) UnmarshalJSON(b []byte) error

UnmarshalJSON accepts a string or an array of strings.

type Where

type Where struct {
	// Type is a PHPDoc type the bound expression's inferred type must be
	// accepted by, with fully qualified class names.
	Type string `json:"type,omitempty"`
	// Regex must match the bound source text.
	Regex string `json:"regex,omitempty"`
	// Not lists patterns the bound code must not match.
	Not Patterns `json:"not,omitempty"`
}

Where constrains what a metavariable may bind.

Jump to

Keyboard shortcuts

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