Documentation
¶
Overview ¶
Package gocognit defines Analyzer other utilities to checks and calculate the complexity of function based on "cognitive complexity" methods.
Index ¶
- Constants
- Variables
- func Complexity(fn *ast.FuncDecl) int
- func CountDown(start int) iter.Seq[int]
- func DoCount()
- func DoFilter()
- func FilteredMap(m map[string]int, threshold int) iter.Seq2[string, int]
- func ForRangeIter(all iter.Seq[int])
- type Diagnostic
- type DiagnosticPosition
- type ScanResult
- type Stat
Constants ¶
View Source
const Doc = `` /* 169-byte string literal not displayed */
Variables ¶
View Source
var Analyzer = &analysis.Analyzer{ Name: "gocognit", Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: run, }
Analyzer reports a diagnostic for every function or method which is too complex specified by its -over flag.
Functions ¶
func Complexity ¶
Complexity calculates the cognitive complexity of a function.
func FilteredMap ¶ added in v1.2.1
func ForRangeIter ¶ added in v1.2.1
Types ¶
type Diagnostic ¶ added in v1.2.0
type Diagnostic struct {
Inc int
Nesting int `json:",omitempty"`
Text string
Pos DiagnosticPosition
}
Diagnostic contains information how the complexity increase.
func (Diagnostic) String ¶ added in v1.2.0
func (d Diagnostic) String() string
type DiagnosticPosition ¶ added in v1.2.0
type DiagnosticPosition struct {
Offset int // offset, starting at 0
Line int // line number, starting at 1
Column int // column number, starting at 1 (byte count)
}
DiagnosticPosition is the position of the diagnostic.
func (DiagnosticPosition) String ¶ added in v1.2.0
func (pos DiagnosticPosition) String() string
type ScanResult ¶ added in v1.2.0
type ScanResult struct {
Diagnostics []diagnostic
Complexity int
}
func ScanComplexity ¶ added in v1.2.0
func ScanComplexity(fn *ast.FuncDecl, includeDiagnostics bool) ScanResult
ScanComplexity scans the function declaration.
type Stat ¶
type Stat struct {
PkgName string
FuncName string
Complexity int
Pos token.Position
Diagnostics []Diagnostic `json:",omitempty"`
}
Stat is statistic of the complexity.
func ComplexityStats ¶
ComplexityStats builds the complexity statistics.
Click to show internal directories.
Click to hide internal directories.