linter

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package linter provides Go code quality rules for wetwire pipeline definitions.

Index

Constants

View Source
const (
	SeverityError   = corelint.SeverityError
	SeverityWarning = corelint.SeverityWarning
	SeverityInfo    = corelint.SeverityInfo
)

Severity level constants from wetwire-core-go/lint.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config = corelint.Config

Config is a type alias for corelint.Config.

type Context

type Context struct {
	// JobNames tracks discovered job names across files
	JobNames map[string][]JobLocation
	// JobCount tracks jobs per file
	JobCount map[string]int
	// MaxJobsPerFile is the threshold for WGL008
	MaxJobsPerFile int
	// PackageVars tracks all declared variable names across files (for cross-file references)
	PackageVars map[string]VarLocation
	// JobVars tracks specifically job variable names for Needs validation
	JobVars map[string]VarLocation
}

Context provides shared context for rules during linting.

type Fix

type Fix struct {
	RuleID      string    `json:"rule_id"`
	Message     string    `json:"message"`
	Start       token.Pos `json:"-"`
	End         token.Pos `json:"-"`
	Replacement string    `json:"replacement"`
	StartOffset int       `json:"start_offset"`
	EndOffset   int       `json:"end_offset"`
}

Fix represents a single auto-fix that can be applied to source code.

type FixResult

type FixResult struct {
	FilePath   string   `json:"file_path"`
	Modified   bool     `json:"modified"`
	FixedCount int      `json:"fixed_count"`
	Errors     []string `json:"errors,omitempty"`
}

FixResult represents the result of applying fixes to a file.

type Fixer

type Fixer interface {
	// Fix returns a list of fixes for the given file. Each fix contains the position
	// and replacement text needed to fix the issue.
	Fix(fset *token.FileSet, file *ast.File, filePath string, ctx *Context) []Fix
}

Fixer is an optional interface that rules can implement to provide auto-fix capability.

type Issue

type Issue = corelint.Issue

Issue is a type alias for corelint.Issue. Field mapping from previous local type:

  • Rule (was RuleID) -> rule identifier
  • File (was FilePath) -> file path
  • Message, Line, Column, Severity, Fixable, Suggestion unchanged

type JobLocation

type JobLocation struct {
	FilePath     string
	Line         int
	VariableName string
}

JobLocation tracks where a job name was defined.

type Linter

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

Linter provides Go code linting for wetwire pipeline definitions.

func New

func New() *Linter

New creates a new Linter with all default rules enabled.

func (*Linter) DisableRule

func (l *Linter) DisableRule(id string)

DisableRule disables a rule by ID.

func (*Linter) EnableRule

func (l *Linter) EnableRule(id string)

EnableRule enables a rule by ID.

func (*Linter) Fix

func (l *Linter) Fix(filePath string) (*FixResult, error)

Fix applies auto-fixes to a file and returns the result.

func (*Linter) FixDir

func (l *Linter) FixDir(dir string) (*FixResult, error)

FixDir applies auto-fixes to all Go files in a directory recursively.

func (*Linter) IsRuleEnabled

func (l *Linter) IsRuleEnabled(id string) bool

IsRuleEnabled returns whether a rule is enabled.

func (*Linter) LintDir

func (l *Linter) LintDir(dir string) (*Result, error)

LintDir lints all Go files in a directory recursively.

func (*Linter) LintFile

func (l *Linter) LintFile(filePath string) (*Result, error)

LintFile lints a single Go file.

func (*Linter) Rules

func (l *Linter) Rules() []Rule

Rules returns all registered rules.

func (*Linter) SetApprovedRegistries

func (l *Linter) SetApprovedRegistries(registries []string)

SetApprovedRegistries sets the list of approved container registries for WGL039. When set, WGL039 will flag images from registries not in this list. If empty, WGL039 will not check registries.

func (*Linter) SetMaxJobsPerFile

func (l *Linter) SetMaxJobsPerFile(n int)

SetMaxJobsPerFile sets the threshold for WGL008.

type Result

type Result struct {
	Success bool    `json:"success"`
	Issues  []Issue `json:"issues,omitempty"`
}

Result represents the result of a lint operation.

type Rule

type Rule interface {
	ID() string
	Description() string
	Check(fset *token.FileSet, file *ast.File, filePath string, ctx *Context) []Issue
}

Rule represents a lint rule for wetwire-gitlab pipelines. This extends the core lint.Rule interface with context-aware checking.

type Severity

type Severity = corelint.Severity

Severity is a type alias for corelint.Severity.

type VarLocation

type VarLocation struct {
	FilePath string
	Line     int
}

VarLocation tracks where a variable was declared.

Jump to

Keyboard shortcuts

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