analysisflags

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package analysisflags defines helpers for processing flags of analysis driver tools.

Index

Constants

This section is empty.

Variables

View Source
var (
	JSON    = false // -json
	Context = -1    // -c=N: if N>0, display offending line plus N lines of context
)

flags common to all {single,multi,unit}checkers.

Functions

func Help

func Help(progname string, analyzers []*analysis.Analyzer, args []string)

Help implements the help subcommand for a multichecker or unitchecker style command. The optional args specify the analyzers to describe. Help calls log.Fatal if no such analyzer exists.

func Parse

func Parse(analyzers []*analysis.Analyzer, multi bool) []*analysis.Analyzer

Parse creates a flag for each of the analyzer's flags, including (in multi mode) a flag named after the analyzer, parses the flags, then filters and returns the list of analyzers enabled by flags.

The result is intended to be passed to unitchecker.Run or checker.Run. Use in unitchecker.Run will gob.Register all fact types for the returned graph of analyzers but of course not the ones only reachable from dropped analyzers. To avoid inconsistency about which gob types are registered from run to run, Parse itself gob.Registers all the facts only reachable from dropped analyzers. This is not a particularly elegant API, but this is an internal package.

func PrintPlain

func PrintPlain(fset *token.FileSet, diag analysis.Diagnostic)

PrintPlain prints a diagnostic in plain text form, with context specified by the -c flag.

func ResolveURL added in v0.9.0

func ResolveURL(a *analysis.Analyzer, d analysis.Diagnostic) (string, error)

ResolveURL resolves the URL field for a Diagnostic from an Analyzer and returns the URL. See Diagnostic.URL for details.

Types

type JSONDiagnostic added in v0.2.0

type JSONDiagnostic struct {
	Category       string                   `json:"category,omitempty"`
	Posn           string                   `json:"posn"` // e.g. "file.go:line:column"
	Message        string                   `json:"message"`
	SuggestedFixes []JSONSuggestedFix       `json:"suggested_fixes,omitempty"`
	Related        []JSONRelatedInformation `json:"related,omitempty"`
}

A JSONDiagnostic describes the JSON schema of an analysis.Diagnostic.

TODO(matloob): include End position if present.

type JSONRelatedInformation added in v0.18.0

type JSONRelatedInformation struct {
	Posn    string `json:"posn"` // e.g. "file.go:line:column"
	Message string `json:"message"`
}

A JSONRelated describes a secondary position and message related to a primary diagnostic.

TODO(adonovan): include End position if present.

type JSONSuggestedFix added in v0.2.0

type JSONSuggestedFix struct {
	Message string         `json:"message"`
	Edits   []JSONTextEdit `json:"edits"`
}

A JSONSuggestedFix describes an edit that should be applied as a whole or not at all. It might contain multiple TextEdits/text_edits if the SuggestedFix consists of multiple non-contiguous edits.

type JSONTextEdit added in v0.2.0

type JSONTextEdit struct {
	Filename string `json:"filename"`
	Start    int    `json:"start"`
	End      int    `json:"end"`
	New      string `json:"new"`
}

A TextEdit describes the replacement of a portion of a file. Start and End are zero-based half-open indices into the original byte sequence of the file, and New is the new text.

type JSONTree

type JSONTree map[string]map[string]interface{}

A JSONTree is a mapping from package ID to analysis name to result. Each result is either a jsonError or a list of JSONDiagnostic.

func (JSONTree) Add

func (tree JSONTree) Add(fset *token.FileSet, id, name string, diags []analysis.Diagnostic, err error)

Add adds the result of analysis 'name' on package 'id'. The result is either a list of diagnostics or an error.

func (JSONTree) Print

func (tree JSONTree) Print()

Jump to

Keyboard shortcuts

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