check

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfHigh   = "high"
	ConfMedium = "medium"
)

Confidence levels of a finding.

View Source
const DefaultMinEvidence = 2

DefaultMinEvidence is the number of distinct names that make a prefix learned.

Variables

View Source
var (
	Lines      = []string{"v1", "v2", "v4"}
	Severities = []string{"aviso", "muda", "quebra"}
)

Markup generations and severities, lowest to highest.

View Source
var DefaultExtensions = map[string][]string{
	// contains filtered or unexported fields
}

DefaultExtensions maps each class to the extensions read as that class.

View Source
var Kinds = []string{kAttribute, kHeader, kEvent, kClass, kGlobal, kIdentifier, kScript, kExtension, kPartial, kConfig}

Kinds lists the kinds of edit, in report order.

Functions

func Command

func Command() cli.Command

Command is the "check" subcommand.

func GenGuide

func GenGuide(path string, rs *RuleSet, checkOnly bool) (upToDate bool, err error)

GenGuide rewrites the guide file; with checkOnly it only reports whether the file is up to date.

func MigrateCommand

func MigrateCommand() cli.Command

MigrateCommand is the "migrate" subcommand.

func RenderGuideTables

func RenderGuideTables(rs *RuleSet) string

RenderGuideTables renders the equivalence tables of the upgrade guide, from the rules, between the markers.

func RenderJSON

func RenderJSON(r *Report) string

RenderJSON prints the report as one JSON document (schema 1).

func RenderMigrate

func RenderMigrate(r *MigrateReport, withDiff bool) string

RenderMigrate prints the migration report for people.

func RenderRules

func RenderRules(rs *RuleSet, line string, asJSON bool) string

RenderRules prints the rule table, as text or JSON, for one markup generation ("auto" lists them all).

func RenderText

func RenderText(r *Report, color bool) string

RenderText prints the report for people: file:line:column, severity, rule, message, fix and guide link, then the summary.

func UpdateGuide

func UpdateGuide(text string, rs *RuleSet) (string, error)

UpdateGuide replaces the generated block of the guide text.

Types

type Evidence

type Evidence struct {
	What string  `json:"what"`
	File string  `json:"file"`
	Line int     `json:"line"`
	Rule *string `json:"rule"`
}

Evidence is one sign that decided the markup generation.

type FileChange

type FileChange struct {
	File         string         `json:"file"`
	Replacements int            `json:"replacements"`
	ByKind       map[string]int `json:"byKind"`
	Written      bool           `json:"written"`
	Diff         string         `json:"diff,omitempty"`
}

FileChange is one converted file.

type Finding

type Finding struct {
	File       string  `json:"file"`
	Line       int     `json:"line"`
	Column     int     `json:"column"`
	Severity   string  `json:"severity"`
	Rule       string  `json:"rule"`
	Message    string  `json:"message"`
	Match      string  `json:"match"`
	Fix        *string `json:"fix"`
	Native     *string `json:"native"`
	Guide      string  `json:"guide"`
	Count      int     `json:"count"`
	Confidence string  `json:"confidence"`
}

Finding is one legacy use.

func ScanText

func ScanText(text, file string, opts Options) []Finding

ScanText scans one text, learning the identifier of the legacy markup from it (plus the ones in opts.IDs). It is the unit the tests and editors use.

type Leftover

type Leftover struct {
	File   string `json:"file"`
	Line   int    `json:"line"`
	Kind   string `json:"kind"`
	Text   string `json:"text"`
	Reason string `json:"reason"`
}

Leftover is a place that still spells the legacy markup after the conversion: a comment, running text or a context the converter does not recognize.

type LegacyInfo

type LegacyInfo struct {
	AttributePrefixes []string `json:"attributePrefixes"`
	HeaderPrefixes    []string `json:"headerPrefixes"`
	Identifiers       []string `json:"identifiers"`
}

LegacyInfo lists the spellings of the legacy markup that a scan learned from the project (or was given): the attribute prefixes, the header prefixes and the identifiers of its global, events and classes.

type LineInfo

type LineInfo struct {
	Requested string     `json:"requested"`
	Used      string     `json:"used"`
	Assumed   bool       `json:"assumed"`
	Evidence  []Evidence `json:"evidence"`
}

LineInfo says which markup generation was used and why.

type Match

type Match struct {
	Names     []string `json:"names"`
	Name      string   `json:"name"`
	Prefix    *bool    `json:"prefix"`
	Tags      []string `json:"tags"`
	NotTags   []string `json:"notTags"`
	Value     string   `json:"value"`
	ValueNot  string   `json:"valueNot"`
	NameRegex string   `json:"nameRegex"`
	Flags     string   `json:"flags"`
	Regex     string   `json:"regex"`
	Group     int      `json:"group"`
	Key       string   `json:"key"`
	Keys      []string `json:"keys"`
	Src       string   `json:"src"`
	IDGroup   int      `json:"idGroup"`
	Check     string   `json:"check"`
	Context   string   `json:"context"`
	Suffixes  []string `json:"suffixes"`
	Skip      []string `json:"skip"`
}

Match holds the kind-specific matching data of a rule; every field is optional and which ones are read depends on Rule.Kind.

type Meta

type Meta struct {
	Schema     int               `json:"schema"`
	Version    string            `json:"version"`
	Guide      string            `json:"guide"`
	Lines      map[string]string `json:"lines"`
	Severities map[string]string `json:"severities"`
}

Meta is the header of the rule table.

type MigrateOptions

type MigrateOptions struct {
	// Scan holds what the scan needs: Rules, Line ("auto" or the line pinned
	// into the converted script tags), IDs, AttrPrefixes, HeaderPrefixes,
	// MinEvidence, ExtraExt and Cwd.
	Scan Options
	// Write applies the edits; without it nothing is written.
	Write bool
	// Comments also converts the recognized names inside comments.
	Comments bool
	// NoIdentifiers leaves identifiers (<P>Target, <p>_request) alone.
	NoIdentifiers bool
	// ScriptSrc replaces the URL of an external script tag of the legacy markup.
	ScriptSrc string
}

MigrateOptions configure a migration.

type MigrateReport

type MigrateReport struct {
	Schema       int            `json:"schema"`
	Tool         string         `json:"tool"`
	RulesVersion string         `json:"rulesVersion"`
	Mode         string         `json:"mode"`
	Line         LineInfo       `json:"line"`
	Legacy       LegacyInfo     `json:"legacy"`
	Scanned      int            `json:"scanned"`
	Summary      MigrateSummary `json:"summary"`
	Files        []FileChange   `json:"files"`
	Unconverted  []Leftover     `json:"unconverted"`
	Skipped      []string       `json:"skipped"`
	Warnings     []string       `json:"warnings"`
}

MigrateReport is the result of a migration; its JSON form is schema 1.

func Migrate

func Migrate(paths []string, opts MigrateOptions) (*MigrateReport, error)

Migrate converts the files under paths.

func (*MigrateReport) Diff

func (r *MigrateReport) Diff(file string) string

Diff returns the unified diff of one converted file ("" when it did not change).

type MigrateSummary

type MigrateSummary struct {
	Files        int            `json:"files"`
	Replacements int            `json:"replacements"`
	ByKind       map[string]int `json:"byKind"`
	Unconverted  int            `json:"unconverted"`
	Mentions     int            `json:"mentions"`
}

MigrateSummary counts what changed and what was left.

type Options

type Options struct {
	Rules *RuleSet
	// Line is "v1", "v2", "v4" or "auto" (the default).
	Line          string
	MinSeverity   string // default "aviso"
	MinConfidence string // "medium" (default, everything) or "high"
	Ignore, Only  []string
	// ExtraExt lists extensions to read as templates, with the leading dot.
	ExtraExt []string
	// IDs names the identifier(s) of the legacy markup explicitly.
	IDs []string
	// AttrPrefixes and HeaderPrefixes force the attribute and header prefixes
	// of the legacy markup when the project does not reveal them (HeaderPrefixes
	// defaults to AttrPrefixes).
	AttrPrefixes, HeaderPrefixes []string
	// MinEvidence is the number of distinct names that make a prefix learned
	// (default DefaultMinEvidence).
	MinEvidence int
	// KeepText keeps the text of every file in the analysis (for the migration).
	KeepText bool
	// Cwd makes the reported paths relative; default the working directory.
	Cwd string
}

Options configure a scan.

type Report

type Report struct {
	Schema       int       `json:"schema"`
	Tool         string    `json:"tool"`
	RulesVersion string    `json:"rulesVersion"`
	Line         LineInfo  `json:"line"`
	Scanned      int       `json:"scanned"`
	Summary      Summary   `json:"summary"`
	Findings     []Finding `json:"findings"`
	Warnings     []string  `json:"warnings"`
	// Legacy says which spellings of the legacy markup the scan learned.
	Legacy LegacyInfo `json:"legacy"`
}

Report is the result of a scan; its JSON form is schema 1.

func Scan

func Scan(paths []string, opts Options) (*Report, error)

Scan walks paths, learns the identifier of the legacy markup from them, applies the rules and builds the report.

func (*Report) Identifiers

func (r *Report) Identifiers() []string

Identifiers lists the identifiers of the legacy markup that the scan found or was given.

type Rule

type Rule struct {
	ID        string   `json:"id"`
	Lines     []string `json:"lines"`
	Severity  string   `json:"severity"`
	Group     string   `json:"group"`
	Kind      string   `json:"kind"`
	Match     Match    `json:"match"`
	Files     []string `json:"files"`
	Aggregate bool     `json:"aggregate"`
	Generic   bool     `json:"generic"`
	// Anchor marks the js-api rules whose method name belongs to the legacy API
	// alone: a call to it names the legacy identifier by itself.
	Anchor bool   `json:"anchor"`
	Signal string `json:"signal"`
	What   string `json:"what"`
	Fix    string `json:"fix"`
	Native string `json:"native"`
}

Rule is one entry of the table. The legacy identifier of the legacy markup is never written in a rule: kinds that need it (event, event-prefix, js-api, config, class, api-global, meta-config, script-library) apply to the identifier the scan learned from the project, or to the one given with --id.

type RuleSet

type RuleSet struct {
	Meta  Meta
	Rules []*Rule
	// contains filtered or unexported fields
}

RuleSet is the compiled rule table.

func Load

func Load() (*RuleSet, error)

Load compiles the rule table embedded in the binary. The prefixes of the old library are not known yet: Bind gives the rule set the ones a project uses.

func Parse

func Parse(data []byte) (*RuleSet, error)

Parse compiles a rule table with no legacy prefix bound.

func (*RuleSet) Bind

func (rs *RuleSet) Bind(attr, hdr []string) (*RuleSet, error)

Bind returns the rule set with the attribute prefixes and the header prefixes of the legacy markup written into the rules that name them ({A} and {H} in the table). With no prefix, those rules match nothing.

func (*RuleSet) Rule

func (rs *RuleSet) Rule(id string) (*Rule, bool)

Rule returns a rule by id.

type Summary

type Summary struct {
	Quebra int `json:"quebra"`
	Muda   int `json:"muda"`
	Aviso  int `json:"aviso"`
	Total  int `json:"total"`
	Files  int `json:"files"`
}

Summary counts the findings.

Jump to

Keyboard shortcuts

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