astutil

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package astutil provides analysis utilities for the scopeguard analyzer. It includes helpers for file context management, AST node iteration, and error reporting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllAssigned added in v0.0.5

func AllAssigned(stmt *ast.AssignStmt) iter.Seq[*ast.Ident]

AllAssigned yields all assigned identifiers.

func AllDeclared added in v0.0.5

func AllDeclared(stmt *ast.DeclStmt) iter.Seq[*ast.Ident]

AllDeclared yields all declared identifiers.

func CommentHasNoLint

func CommentHasNoLint(comment *ast.Comment) bool

CommentHasNoLint checks if the provided comment contains a `//nolint:scopeguard` directive.

func InternalError

func InternalError(p *analysis.Pass, rng analysis.Range, format string, args ...any)

InternalError reports an internal error diagnostic. These errors indicate bugs in the analyzer logic rather than issues in the user's code.

Types

type CurrentFile

type CurrentFile struct {
	// contains filtered or unexported fields
}

CurrentFile holds file information for analysis.

func NewCurrentFile

func NewCurrentFile(fset *token.FileSet, file *ast.File) CurrentFile

NewCurrentFile creates a new CurrentFile from a token.FileSet and an *ast.File.

func (CurrentFile) Generated

func (c CurrentFile) Generated() bool

Generated returns true if the file is a generated file.

func (CurrentFile) Lines

func (c CurrentFile) Lines(stmt ast.Node) int

Lines returns the number of Lines a statement spans.

func (CurrentFile) NoLintComment

func (c CurrentFile) NoLintComment(pos token.Pos) bool

NoLintComment checks if a line is followed by a //nolint:scopeguard comment.

func (CurrentFile) Valid

func (c CurrentFile) Valid() bool

Valid returns true if the CurrentFile was successfully created from a valid file handle.

type NodeIndex

type NodeIndex int32

NodeIndex is the index from inspector.Cursor, increases monotonically throughout the traversal.

const InvalidNode NodeIndex = -1

InvalidNode represents an invalid node index.

func NodeIndexOf

func NodeIndexOf(c inspector.Cursor) NodeIndex

NodeIndexOf returns the NodeIndex for the current inspector.Cursor position.

func (NodeIndex) Cursor

Cursor returns the inspector.Cursor corresponding to this index.

func (NodeIndex) Node

func (n NodeIndex) Node(in *inspector.Inspector) ast.Node

Node returns the ast.Node corresponding to this index.

func (NodeIndex) Valid

func (n NodeIndex) Valid() bool

Valid checks if this index is valid.

Jump to

Keyboard shortcuts

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