package lint

import "honnef.co/go/tools/analysis/lint"

Package lint provides abstractions on top of go/analysis. These abstractions add extra information to analyzes, such as structured documentation and severities.

Index

Functions

func ExhaustiveTypeSwitch

func ExhaustiveTypeSwitch(v interface{})

ExhaustiveTypeSwitch panics when called. It can be used to ensure that type switches are exhaustive.

Types

type Analyzer

type Analyzer struct {
	// The analyzer's documentation. Unlike go/analysis.Analyzer.Doc,
	// this field is structured, providing access to severity, options
	// etc.
	Doc      *RawDocumentation
	Analyzer *analysis.Analyzer
}

Analyzer wraps a go/analysis.Analyzer and provides structured documentation.

func InitializeAnalyzer

func InitializeAnalyzer(a *Analyzer) *Analyzer

type Directive

type Directive struct {
	Command   string
	Arguments []string
	Directive *ast.Comment
	Node      ast.Node
}

A directive is a comment of the form '//lint:<command> [arguments...]'. It represents instructions to the static analysis tool.

func ParseDirectives

func ParseDirectives(files []*ast.File, fset *token.FileSet) []Directive

ParseDirectives extracts all directives from a list of Go files.

type Documentation

type Documentation struct {
	Title string
	Text  string

	TitleMarkdown string
	TextMarkdown  string

	Before     string
	After      string
	Since      string
	NonDefault bool
	Options    []string
	Severity   Severity
	MergeIf    MergeStrategy
}

func (*Documentation) Format

func (doc *Documentation) Format(metadata bool) string

func (*Documentation) FormatMarkdown

func (doc *Documentation) FormatMarkdown(metadata bool) string

func (*Documentation) String

func (doc *Documentation) String() string

type MergeStrategy

type MergeStrategy int

MergeStrategy sets how merge mode should behave for diagnostics of an analyzer.

const (
	MergeIfAny MergeStrategy = iota
	MergeIfAll
)

type RawDocumentation

type RawDocumentation struct {
	Title      string
	Text       string
	Before     string
	After      string
	Since      string
	NonDefault bool
	Options    []string
	Severity   Severity
	MergeIf    MergeStrategy
}

func (RawDocumentation) Compile

func (doc RawDocumentation) Compile() *Documentation

type Severity

type Severity int

Severity describes the severity of diagnostics reported by an analyzer.

const (
	SeverityNone Severity = iota
	SeverityError
	SeverityDeprecated
	SeverityWarning
	SeverityInfo
	SeverityHint
)

Source Files

lint.go

Directories

PathSynopsis
analysis/lint/testutil
Version
v0.6.1 (latest)
Published
Mar 5, 2025
Platform
darwin/amd64
Imports
6 packages
Last checked
5 hours ago

Tools for package owners.