directive

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package directive provides handling of zerologlintctx directive comments.

Supported Directives

The package recognizes the following comment directive:

//zerologlintctx:ignore

This directive can be placed on the same line or the line before the code to suppress warnings.

Usage Examples

Same-line ignore:

log.Info().Msg("no ctx needed") //zerologlintctx:ignore

Previous-line ignore:

//zerologlintctx:ignore
log.Info().Msg("no ctx needed")

Unused ignore directives are reported as errors to keep the codebase clean.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IgnoreMap

type IgnoreMap map[int]*ignoreEntry

IgnoreMap tracks line numbers that have ignore comments.

func BuildIgnoreMap

func BuildIgnoreMap(fset *token.FileSet, file *ast.File) IgnoreMap

BuildIgnoreMap scans a file for ignore comments and returns a map.

func (IgnoreMap) GetUnusedIgnores

func (m IgnoreMap) GetUnusedIgnores() []token.Pos

GetUnusedIgnores returns the positions of ignore directives that were not used.

func (IgnoreMap) ShouldIgnore

func (m IgnoreMap) ShouldIgnore(line int) bool

ShouldIgnore returns true if the given line should be ignored. It checks if the same line or the previous line has an ignore comment. When an ignore is used, it marks the entry as used.

Line matching logic:

Line N-1:  //zerologlintctx:ignore   ← matches line N
Line N:    log.Info().Msg("test")    ← target line

Line N:    log.Info().Msg("test") //zerologlintctx:ignore  ← also matches

Jump to

Keyboard shortcuts

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