Documentation
¶
Index ¶
- Constants
- Variables
- func Command() cli.Command
- func GenGuide(path string, rs *RuleSet, checkOnly bool) (upToDate bool, err error)
- func MigrateCommand() cli.Command
- func RenderGuideTables(rs *RuleSet) string
- func RenderJSON(r *Report) string
- func RenderMigrate(r *MigrateReport, withDiff bool) string
- func RenderRules(rs *RuleSet, line string, asJSON bool) string
- func RenderText(r *Report, color bool) string
- func UpdateGuide(text string, rs *RuleSet) (string, error)
- type Evidence
- type FileChange
- type Finding
- type Leftover
- type LegacyInfo
- type LineInfo
- type Match
- type Meta
- type MigrateOptions
- type MigrateReport
- type MigrateSummary
- type Options
- type Report
- type Rule
- type RuleSet
- type Summary
Constants ¶
const ( ConfHigh = "high" ConfMedium = "medium" )
Confidence levels of a finding.
const DefaultMinEvidence = 2
DefaultMinEvidence is the number of distinct names that make a prefix learned.
Variables ¶
var ( Lines = []string{"v1", "v2", "v4"} Severities = []string{"aviso", "muda", "quebra"} )
Markup generations and severities, lowest to highest.
var DefaultExtensions = map[string][]string{ // contains filtered or unexported fields }
DefaultExtensions maps each class to the extensions read as that class.
var Kinds = []string{kAttribute, kHeader, kEvent, kClass, kGlobal, kIdentifier, kScript, kExtension, kPartial, kConfig}
Kinds lists the kinds of edit, in report order.
Functions ¶
func GenGuide ¶
GenGuide rewrites the guide file; with checkOnly it only reports whether the file is up to date.
func RenderGuideTables ¶
RenderGuideTables renders the equivalence tables of the upgrade guide, from the rules, between the markers.
func RenderJSON ¶
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 ¶
RenderRules prints the rule table, as text or JSON, for one markup generation ("auto" lists them all).
func RenderText ¶
RenderText prints the report for people: file:line:column, severity, rule, message, fix and guide link, then the summary.
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.
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 ¶
Scan walks paths, learns the identifier of the legacy markup from them, applies the rules and builds the report.
func (*Report) Identifiers ¶
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 ¶
RuleSet is the compiled rule table.
func Load ¶
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.