rules

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package rules provides the compatibility rules engine for ccg.

Package rules provides the compatibility rules engine for ccg.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category represents the category of a finding.

const (
	CategoryExecCommand    Category = "exec_command"
	CategoryCGO            Category = "cgo"
	CategoryDynamicLinking Category = "dynamic_linking"
	CategoryDynamicLink    Category = "dynamic_link"
	CategoryDockerfile     Category = "dockerfile"
	CategoryBaseImage      Category = "base_image"
	CategoryMultiStage     Category = "multi_stage"
	CategoryCorrelation    Category = "correlation"
)

type Engine

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

Engine is the compatibility rules engine that evaluates findings.

func NewEngine

func NewEngine() *Engine

NewEngine creates a new rules engine with default rules.

func (*Engine) DisableRule

func (e *Engine) DisableRule(id string)

DisableRule disables a rule by ID.

func (*Engine) EnableRule

func (e *Engine) EnableRule(id string)

EnableRule enables a rule by ID.

func (*Engine) Evaluate

func (e *Engine) Evaluate(findings []Finding) *Result

Evaluate evaluates a list of findings and returns the result.

func (*Engine) GetRule

func (e *Engine) GetRule(id string) *Rule

GetRule returns a rule by ID.

func (*Engine) IsRuleEnabled

func (e *Engine) IsRuleEnabled(id string) bool

IsRuleEnabled returns true if the rule is enabled.

func (*Engine) ListRules

func (e *Engine) ListRules() []Rule

ListRules returns all registered rules.

type Finding

type Finding struct {
	// RuleID is the unique identifier of the rule that generated this finding.
	RuleID string `json:"rule_id"`

	// Category is the category of the finding.
	Category Category `json:"category"`

	// Severity is the severity level of the finding.
	Severity Severity `json:"severity"`

	// Message is a human-readable description of the finding.
	Message string `json:"message"`

	// Location is the file and line where the issue was found.
	Location Location `json:"location"`

	// Details contains additional context about the finding.
	Details map[string]interface{} `json:"details,omitempty"`

	// Suggestion provides a recommended fix for the issue.
	Suggestion string `json:"suggestion,omitempty"`
}

Finding represents a single compatibility issue found during analysis.

type Location

type Location struct {
	// File is the path to the file.
	File string `json:"file"`

	// Line is the line number (1-indexed).
	Line int `json:"line,omitempty"`

	// Column is the column number (1-indexed).
	Column int `json:"column,omitempty"`

	// Stage is the Docker build stage name (for multi-stage Dockerfiles).
	Stage string `json:"stage,omitempty"`
}

Location represents the location of a finding in source code or configuration.

type Result

type Result struct {
	// Findings is the list of all findings.
	Findings []Finding `json:"findings"`

	// Summary contains aggregated statistics.
	Summary Summary `json:"summary"`

	// Passed indicates whether the analysis passed (no errors).
	Passed bool `json:"passed"`
}

Result represents the overall result of the compatibility analysis.

func (*Result) HasErrors

func (r *Result) HasErrors() bool

HasErrors returns true if there are any error-level findings.

func (*Result) HasWarnings

func (r *Result) HasWarnings() bool

HasWarnings returns true if there are any warning-level findings.

type Rule

type Rule struct {
	// ID is the unique identifier of the rule.
	ID string `json:"id"`

	// Name is the human-readable name of the rule.
	Name string `json:"name"`

	// Description is a detailed description of what the rule checks.
	Description string `json:"description"`

	// Severity is the default severity of findings from this rule.
	Severity Severity `json:"severity"`

	// Category is the category this rule belongs to.
	Category Category `json:"category"`

	// Enabled indicates whether the rule is enabled.
	Enabled bool `json:"enabled"`
}

Rule represents a compatibility rule.

type Severity

type Severity string

Severity represents the severity level of a finding.

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
	SeverityInfo    Severity = "info"
)

type Summary

type Summary struct {
	// TotalFindings is the total number of findings.
	TotalFindings int `json:"total_findings"`

	// ErrorCount is the number of error-level findings.
	ErrorCount int `json:"error_count"`

	// WarningCount is the number of warning-level findings.
	WarningCount int `json:"warning_count"`

	// InfoCount is the number of info-level findings.
	InfoCount int `json:"info_count"`

	// ByCategory contains counts grouped by category.
	ByCategory map[Category]int `json:"by_category"`
}

Summary contains aggregated statistics about the findings.

Jump to

Keyboard shortcuts

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