helpers

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package helpers provides shared utilities for rule implementations.

Package helpers provides shared utilities for rule implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeFuncBodies

func AnalyzeFuncBodies(ctx *core.FileContext, checker FuncBodyChecker) []*core.Violation

AnalyzeFuncBodies is a helper for rules that analyze function bodies. It handles the common boilerplate of: - Checking if AST exists - Iterating over function declarations - Filtering out functions without bodies

Usage:

func (r *MyRule) AnalyzeFile(ctx *core.FileContext) []*core.Violation {
    if !ctx.IsGoFile() || ctx.IsTestFile() {
        return nil
    }
    return helpers.AnalyzeFuncBodies(ctx, r.checkFunction)
}

func AnalyzeFuncDecls

func AnalyzeFuncDecls(ctx *core.FileContext, checker FuncDeclChecker) []*core.Violation

AnalyzeFuncDecls is a helper for rules that need full function declarations. Use this when you need function name, receiver, etc. in addition to body.

func AnalyzeGoAndFrontend

func AnalyzeGoAndFrontend(
	ctx *core.FileContext,
	analyzeGo func(*core.FileContext) []*core.Violation,
	analyzeFrontend func(*core.FileContext) []*core.Violation,
) []*core.Violation

AnalyzeGoAndFrontend dispatches a file to its language-specific analyzer.

func IsInComment

func IsInComment(line, substr string) bool

IsInComment checks if a substring appears inside a comment.

func IsInStringOrComment

func IsInStringOrComment(line, substr string) bool

IsInStringOrComment checks if a substring is inside a string literal or comment.

func IsInsideBackticks

func IsInsideBackticks(line, substr string) bool

IsInsideBackticks checks if a substring appears inside a backtick (raw) string literal.

func IsInsideString

func IsInsideString(line, substr string) bool

IsInsideString checks if a substring appears inside a double-quoted string literal. It counts quotes before the substring - odd count means inside a string.

Types

type FuncBodyChecker

type FuncBodyChecker func(ctx *core.FileContext, body *ast.BlockStmt, violations *[]*core.Violation)

FuncBodyChecker is called for each function body to check for violations. It receives the file context and function body, and appends violations to the provided slice.

type FuncDeclChecker

type FuncDeclChecker func(ctx *core.FileContext, fn *ast.FuncDecl) []*core.Violation

FuncDeclChecker is called for each function declaration. It receives the file context, function declaration, and returns violations.

Jump to

Keyboard shortcuts

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