goverhaul

package module
v0.0.0-...-f75528d Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: GPL-3.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Goverhaul

Build Status Code Coverage Go Report Card GoDoc GitHub release

Goverhaul is a high-performance CLI tool to enforce architectural rules in Go projects. It helps teams maintain the intended architecture by defining and enforcing import boundaries between packages, with intelligent caching for blazing-fast analysis.

Features

  • Define allowed imports for specific package paths
  • Define prohibited imports with explanatory causes
  • Generate visual dependency graphs
  • High-performance caching using MUS binary encoding
  • Incremental analysis for fast subsequent runs
  • Simple YAML configuration
  • Easy CI/CD integration

Performance-First Design

Goverhaul uses MUS (Marshal/Unmarshal/Size) binary serialization for cache storage, delivering exceptional performance:

  • 2,700+ MB/s encoding throughput
  • 1,000+ MB/s decoding throughput
  • Single allocation design for minimal GC pressure
  • Compact binary format for efficient storage
  • Linear scalability from small projects to enterprise monorepos
Real-World Performance
Project Size Cache Write Cache Read Memory Usage
Small (100 files) <1ms <1ms Negligible
Medium (1,000 files) ~100μs ~200μs <200KB
Large (10,000 files) ~760μs ~2ms ~2MB
Enterprise (100,000 files) ~7.4ms ~14.3ms ~20MB

This means faster CI/CD pipelines, real-time IDE integration, and efficient analysis for projects of any size.

Installation

Using Go Install
go install github.com/gophersatwork/goverhaul@latest
Using Go Tool Directive (Go 1.24+)
go get -tool github.com/gophersatwork/goverhaul@latest
From Source
git clone https://github.com/gophersatwork/goverhaul.git
cd goverhaul
go build

Quick Start

  1. Install Goverhaul:

    go install github.com/gophersatwork/goverhaul@latest
    
  2. Create a .goverhaul.yml configuration:

    # Enable high-performance incremental analysis
    incremental: true
    cache_file: ".goverhaul.cache"
    
    rules:
      # Domain layer should not depend on infrastructure
      - path: "internal/domain"
        prohibited:
          - name: "internal/infrastructure"
            cause: "Domain should not depend on infrastructure"
    
      # API layer should not access database directly
      - path: "internal/api"
        prohibited:
          - name: "internal/database"
            cause: "API should access database through domain services"
    
  3. Run Goverhaul:

    goverhaul --path . --config .goverhaul.yml
    
  4. Subsequent runs use the cache for instant results!

Usage

Basic Usage
# Run with default configuration
goverhaul --path . --config .goverhaul.yml

# Enable verbose logging
goverhaul --path . --config .goverhaul.yml --verbose

# Analyze specific directory
goverhaul --path ./internal --config .goverhaul.yml
Command Line Options
  • --path: Path to analyze (default: ".")
  • --config: Configuration file path (default: "$HOME/.goverhaul.yml")
  • --verbose: Enable verbose logging for debugging

Configuration

Goverhaul uses YAML for configuration. Here's a complete example:

# Path to go.mod file
modfile: "go.mod"

# Enable incremental analysis with high-performance MUS caching
incremental: true

# Cache file location (uses MUS binary encoding)
cache_file: ".goverhaul.cache"

rules:
  # Core business logic isolation
  - path: "internal/core"
    allowed:
      - "context"
      - "errors"
      - "fmt"
      - "time"
      - "internal/core"
    prohibited:
      - name: "internal/api"
        cause: "Core should not depend on API layer"
      - name: "internal/db"
        cause: "Core should not depend on database layer"

  # API layer constraints
  - path: "internal/api"
    prohibited:
      - name: "internal/db"
        cause: "API should access database through core interfaces"
Configuration Options
  • modfile: Path to go.mod file (default: "go.mod")
  • incremental: Enable incremental analysis for faster runs (default: false)
  • cache_file: Cache file location (default: "$HOME/.goverhaul/cache.json")
  • rules: List of architectural rules
    • path: Package path to apply the rule to
    • allowed: Whitelist of permitted imports
    • prohibited: Blacklist of forbidden imports
      • name: Package name to prohibit
      • cause: Explanation for the prohibition

High-Performance Caching

Goverhaul's caching system uses MUS binary encoding for exceptional performance:

Why MUS?
  • Minimal allocations: Single allocation per operation
  • Excellent throughput: 2,700+ MB/s encoding, 1,000+ MB/s decoding
  • Compact size: Efficient varint encoding for small cache files
  • Linear scalability: Consistent performance from 10 to 100,000 files
Cache Benefits
  1. First run: Analyzes all files and builds the cache
  2. Subsequent runs: Only analyzes changed files
  3. CI/CD: Dramatically reduced build times
  4. IDE integration: Real-time feedback with minimal overhead
Cache Location

By default, the cache is stored in $HOME/.goverhaul/cache.json. You can customize this:

cache_file: ".goverhaul.cache"  # Project-local cache

Or use an absolute path:

cache_file: "/tmp/goverhaul.cache"  # Temporary cache

Architecture Patterns

Clean Architecture
rules:
  # Domain entities: no external dependencies
  - path: "internal/domain"
    allowed:
      - "fmt"
      - "errors"
      - "context"
      - "time"

  # Use cases: depend on domain only
  - path: "internal/usecase"
    allowed:
      - "fmt"
      - "errors"
      - "context"
      - "internal/domain"
    prohibited:
      - name: "internal/infrastructure"
        cause: "Use cases should depend on interfaces, not implementations"

  # Infrastructure: implements interfaces
  - path: "internal/infrastructure"
    prohibited:
      - name: "internal/usecase"
        cause: "Infrastructure should not depend on use cases"
Hexagonal Architecture
rules:
  # Core domain: completely isolated
  - path: "pkg/core"
    prohibited:
      - name: "pkg/api"
        cause: "Core should not depend on adapters"
      - name: "pkg/db"
        cause: "Core should not depend on adapters"
      - name: "pkg/messaging"
        cause: "Core should not depend on adapters"

  # Adapters: can use core
  - path: "pkg/api"
    prohibited:
      - name: "pkg/db"
        cause: "Adapters should not depend on each other"
Layered Architecture
rules:
  # Presentation layer
  - path: "internal/presentation"
    prohibited:
      - name: "internal/data"
        cause: "Presentation should access data through business layer"

  # Business layer
  - path: "internal/business"
    prohibited:
      - name: "internal/presentation"
        cause: "Business should not depend on presentation"

  # Data layer
  - path: "internal/data"
    prohibited:
      - name: "internal/business"
        cause: "Data should not depend on business"
      - name: "internal/presentation"
        cause: "Data should not depend on presentation"

CI/CD Integration

GitHub Actions
name: Architecture Check

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  goverhaul:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.24'

    - name: Install Goverhaul
      run: go install github.com/gophersatwork/goverhaul@latest

    - name: Cache Goverhaul results
      uses: actions/cache@v3
      with:
        path: .goverhaul.cache
        key: goverhaul-${{ hashFiles('**/*.go') }}
        restore-keys: goverhaul-

    - name: Check architecture
      run: goverhaul --path . --config .goverhaul.yml
GitLab CI
architecture-check:
  stage: test
  image: golang:1.24
  script:
    - go install github.com/gophersatwork/goverhaul@latest
    - goverhaul --path . --config .goverhaul.yml
  cache:
    key: goverhaul-${CI_COMMIT_REF_SLUG}
    paths:
      - .goverhaul.cache

Use Cases

Enforcing Clean Architecture

Maintain the dependency rule:

  • Domain entities have no external dependencies
  • Use cases depend only on domain entities
  • Adapters depend on use cases but not frameworks
  • Frameworks are isolated at the boundaries
Maintaining Module Boundaries

For multi-module projects:

  • Define clear boundaries between modules
  • Enforce API contracts
  • Prevent implementation leakage
Controlling Dependencies

Limit external dependency spread:

  • Restrict third-party library usage
  • Isolate framework dependencies
  • Keep core business logic clean
Documenting Architecture

Use rules as executable documentation:

  • Encode architectural decisions
  • Make constraints visible
  • Help new team members

Best Practices

1. Start with Critical Boundaries

Focus on the most important architectural constraints first:

rules:
  # Start here: protect core business logic
  - path: "internal/domain"
    prohibited:
      - name: "external/dependencies"
        cause: "Domain should be framework-agnostic"
2. Enable Incremental Analysis

For large projects, always enable caching:

incremental: true
cache_file: ".goverhaul.cache"

This dramatically reduces analysis time for subsequent runs.

3. Use Meaningful Causes

Make violations easy to understand:

prohibited:
  - name: "internal/db"
    cause: "API layer should access database through repository interfaces defined in domain layer"
4. Version Control Your Configuration

Commit .goverhaul.yml to track architectural decisions over time.

5. Integrate Early

Add Goverhaul to CI/CD pipelines early to prevent architectural drift.

Troubleshooting

Rule Not Applied

Issue: Rule doesn't seem to work.

Solutions:

  • Verify path matches your package structure
  • Use --verbose to see which files are analyzed
  • Check package declarations in Go files
Cache Issues

Issue: Incremental analysis not detecting changes.

Solutions:

  • Delete cache file and run again
  • Verify cache file location is correct
  • Ensure file permissions allow cache writes
CI/CD Failures

Issue: Works locally but fails in CI.

Solutions:

  • Verify Go version matches
  • Check configuration file is in repository
  • Use absolute paths in CI configuration
  • Add --verbose for debug output

Performance Tips

For Large Codebases
  1. Enable incremental analysis: Mandatory for 1,000+ files
  2. Use local cache: Place cache in project directory
  3. Fast storage: Put cache on SSD/NVMe
  4. Parallel CI: Cache persists across builds
For Maximum Speed
  1. Pre-allocate cache: First run may be slower, subsequent runs are instant
  2. Network storage: Avoid network-mounted cache locations
  3. Memory: More RAM helps for very large projects (100,000+ files)

Examples

Check the examples directory for complete examples:

  • layered-architecture: Three-tier architecture enforcement
  • microservices: Service boundary enforcement
  • monolith: Module isolation in monolithic applications

Contributing

Contributions are welcome! Please feel free to open a discussion or PR.

See CONTRIBUTING.md for guidelines.

License

GNU General Public License (GPL v3)

Technical Details

For implementation details about the high-performance MUS cache, see IMPLEMENTATION_SUMMARY.md.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEntryNotFound           = errors.New("entry not found")
	ErrReadingCachedViolations = errors.New("cached violations are invalid")
)

Cache-related errors

Functions

func AbsPath

func AbsPath(path string) string

AbsPath returns the absolute path for a given path If an error occurs, it returns the original path This function works on all operating systems by normalizing paths to use forward slashes

func DirPath

func DirPath(path string) string

DirPath returns the directory portion of a path This function works on all operating systems by normalizing paths to use forward slashes

func IsAbsPath

func IsAbsPath(path string) bool

IsAbsPath checks if a path is absolute This function works on all operating systems by using the system's path separator

func IsSubPath

func IsSubPath(parentPath, childPath string) bool

IsSubPath checks if childPath is a subdirectory of parentPath. Both paths are normalized before comparison. This function works on all operating systems by normalizing paths to use forward slashes.

func JoinPaths

func JoinPaths(elem ...string) string

JoinPaths joins path elements and normalizes the result. It joins elements using the system's path separator, then normalizes to forward slashes, and cleans the path to remove redundant separators and dot-segments. This function works on all operating systems by normalizing paths to use forward slashes.

func NewCacheError

func NewCacheError(message string, err error) error

NewCacheError creates a new cache error

func NewConfigError

func NewConfigError(message string, err error) error

NewConfigError creates a new configuration error

func NewError

func NewError(message string, err error) error

NewError creates a new application error

func NewFSError

func NewFSError(message string, err error) error

NewFSError creates a new file system error

func NewLintError

func NewLintError(message string, err error) error

NewLintError creates a new linting error

func NewParseError

func NewParseError(message string, err error) error

NewParseError creates a new parsing error

func NormalizePath

func NormalizePath(path string) string

NormalizePath converts a path to use forward slashes consistently regardless of the operating system and cleans the path. It removes redundant separators, dot-segments, and normalizes separators to forward slashes. This ensures consistent path handling across different operating systems. Empty paths remain empty to maintain backward compatibility.

func WithDetails

func WithDetails(err error, details string) error

WithDetails adds additional details to an error

func WithFile

func WithFile(err error, file string) error

WithFile adds file information to an error

Types

type AppError

type AppError struct {
	Message string
	File    string
	Details string
	Err     error
}

AppError represents an application error with additional context

func GetErrorInfo

func GetErrorInfo(err error) (*AppError, bool)

GetErrorInfo extracts error information from an error

func (*AppError) Error

func (e *AppError) Error() string

Error implements the error interface

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap returns the wrapped error

type Cache

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

Cache provides high-performance caching using MUS serialization. MUS is a binary serialization format optimized for speed and size. This implementation uses varint encoding and ord package for optimal performance.

func NewCache

func NewCache(path string, fs afero.Fs) (*Cache, error)

NewCache creates a new cache with MUS encoding for maximum performance. MUS uses varint encoding and manual serialization for optimal efficiency.

func (*Cache) AddFile

func (c *Cache) AddFile(path string) error

AddFile adds a file entry to the cache without violations

func (*Cache) AddFileWithViolations

func (c *Cache) AddFileWithViolations(path string, lv []LintViolation) error

AddFileWithViolations stores violations for a file using MUS encoding

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all entries from the cache

func (*Cache) HasEntry

func (c *Cache) HasEntry(filePath string) (LintViolations, error)

HasEntry checks if a file has cached violations and returns them

type CacheInterface

type CacheInterface interface {
	// AddFile adds a file entry to the cache without violations
	AddFile(path string) error

	// AddFileWithViolations stores violations for a file using MUS encoding
	AddFileWithViolations(path string, violations []LintViolation) error

	// HasEntry checks if a file has cached violations and returns them
	HasEntry(filePath string) (LintViolations, error)
}

CacheInterface defines the interface for the MUS-based cache implementation. The cache uses MUS encoding for high-performance serialization.

type CheckstyleError

type CheckstyleError struct {
	Line     int    `xml:"line,attr"`
	Column   int    `xml:"column,attr,omitempty"`
	Severity string `xml:"severity,attr"`
	Message  string `xml:"message,attr"`
	Source   string `xml:"source,attr"`
}

type CheckstyleFile

type CheckstyleFile struct {
	Name   string            `xml:"name,attr"`
	Errors []CheckstyleError `xml:"error"`
}

type CheckstyleFormatter

type CheckstyleFormatter struct{}

CheckstyleFormatter outputs violations in Checkstyle XML format

func (*CheckstyleFormatter) ContentType

func (f *CheckstyleFormatter) ContentType() string

func (*CheckstyleFormatter) Format

func (f *CheckstyleFormatter) Format(violations *LintViolations, cfg *Config) ([]byte, error)

type CheckstyleOutput

type CheckstyleOutput struct {
	XMLName xml.Name         `xml:"checkstyle"`
	Version string           `xml:"version,attr"`
	Files   []CheckstyleFile `xml:"file"`
}

type ConcurrentLinter

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

ConcurrentLinter provides parallel linting capabilities

func NewConcurrentLinter

func NewConcurrentLinter(cfg Config, logger *slog.Logger, fs afero.Fs, opts ...Option) (*ConcurrentLinter, error)

NewConcurrentLinter creates a new concurrent linter with options

func (*ConcurrentLinter) LintWithContext

func (cl *ConcurrentLinter) LintWithContext(ctx context.Context, path string) (*LintViolations, error)

LintWithContext performs concurrent linting with context support

type Config

type Config struct {
	Rules       []Rule `json:"rules" yaml:"rules" mapstructure:"rules"`
	Modfile     string `json:"modfile" yaml:"modfile" mapstructure:"modfile"`
	Incremental bool   `json:"incremental" yaml:"incremental" mapstructure:"incremental"`
	CacheFile   string `json:"cache_file" yaml:"cache_file" mapstructure:"cache_file"`
}

func LoadConfig

func LoadConfig(fs afero.Fs, path string, cfgFile string) (Config, error)

type Formatter

type Formatter interface {
	Format(violations *LintViolations, cfg *Config) ([]byte, error)
	ContentType() string
}

Formatter interface for different output formats

func NewFormatter

func NewFormatter(format OutputFormat) (Formatter, error)

FormatterFactory creates formatters based on the output format

type JSONFormatter

type JSONFormatter struct {
	Pretty bool
}

JSONFormatter outputs violations in JSON format

func (*JSONFormatter) ContentType

func (f *JSONFormatter) ContentType() string

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(violations *LintViolations, cfg *Config) ([]byte, error)

type JSONOutput

type JSONOutput struct {
	Summary    Summary         `json:"summary"`
	Violations []JSONViolation `json:"violations"`
	Rules      []RuleSummary   `json:"rules"`
	Timestamp  string          `json:"timestamp"`
}

JSONOutput represents the JSON output structure

type JSONViolation

type JSONViolation struct {
	File     string `json:"file"`
	Line     int    `json:"line,omitempty"`
	Column   int    `json:"column,omitempty"`
	Rule     string `json:"rule"`
	Import   string `json:"import"`
	Severity string `json:"severity"`
	Message  string `json:"message"`
	Cause    string `json:"cause,omitempty"`
}

type JUnitFailure

type JUnitFailure struct {
	Type    string `xml:"type,attr"`
	Message string `xml:"message,attr"`
	Text    string `xml:",chardata"`
}

type JUnitFormatter

type JUnitFormatter struct{}

JUnitFormatter outputs violations in JUnit XML format

func (*JUnitFormatter) ContentType

func (f *JUnitFormatter) ContentType() string

func (*JUnitFormatter) Format

func (f *JUnitFormatter) Format(violations *LintViolations, cfg *Config) ([]byte, error)

type JUnitTestCase

type JUnitTestCase struct {
	Name      string        `xml:"name,attr"`
	ClassName string        `xml:"classname,attr"`
	Time      float64       `xml:"time,attr"`
	Failure   *JUnitFailure `xml:"failure,omitempty"`
}

type JUnitTestSuite

type JUnitTestSuite struct {
	Name      string          `xml:"name,attr"`
	Tests     int             `xml:"tests,attr"`
	Failures  int             `xml:"failures,attr"`
	Errors    int             `xml:"errors,attr"`
	Time      float64         `xml:"time,attr"`
	TestCases []JUnitTestCase `xml:"testcase"`
}

type JUnitTestSuites

type JUnitTestSuites struct {
	XMLName    xml.Name         `xml:"testsuites"`
	Name       string           `xml:"name,attr"`
	Tests      int              `xml:"tests,attr"`
	Failures   int              `xml:"failures,attr"`
	Errors     int              `xml:"errors,attr"`
	Time       float64          `xml:"time,attr"`
	TestSuites []JUnitTestSuite `xml:"testsuite"`
}

type Job

type Job struct {
	Path string
	Info os.FileInfo
}

Job represents a file to be linted

type LintStats

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

LintStats tracks performance metrics

func (*LintStats) Duration

func (s *LintStats) Duration() time.Duration

Duration returns the time taken for the last lint operation

func (*LintStats) FilesPerSecond

func (s *LintStats) FilesPerSecond() float64

FilesPerSecond returns the processing rate

type LintViolation

type LintViolation struct {
	File    string `json:"file"`    // The file where the violation was found
	Import  string `json:"import"`  // The import that violated the rule
	Rule    string `json:"rule"`    // The rule that was violated
	Cause   string `json:"cause"`   // The cause of the violation, if provided
	Details string `json:"details"` // Additional details about the violation
	Cached  bool   `json:"cached"`  // Whether the lint violation result was retrieved from the cache.
}

LintViolation represents a specific rule violation found during linting

func (*LintViolation) Error

func (v *LintViolation) Error() string

Error implements the error interface

type LintViolations

type LintViolations struct {
	Violations []LintViolation `json:"violations"`
}

LintViolations is a collection of LintViolation errors

func NewLintViolations

func NewLintViolations() *LintViolations

NewLintViolations creates a new empty collection of lint violations

func (*LintViolations) Add

func (v *LintViolations) Add(violation LintViolation)

Add adds a violation to the collection

func (*LintViolations) IsEmpty

func (v *LintViolations) IsEmpty() bool

IsEmpty returns true if there are no violations

func (*LintViolations) PrintByFile

func (v *LintViolations) PrintByFile() string

PrintByFile prints the violations grouped by file

func (*LintViolations) PrintByRule

func (v *LintViolations) PrintByRule() string

PrintByRule prints the violations grouped by rule

func (*LintViolations) String

func (v *LintViolations) String() string

String implements the Stringer interface

type Linter

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

func NewLinter

func NewLinter(cfg Config, logger *slog.Logger, fs afero.Fs) (*Linter, error)

func (*Linter) Lint

func (g *Linter) Lint(path string) (*LintViolations, error)

Lint analyzes Go files in the given path for import rule violations

type MarkdownFormatter

type MarkdownFormatter struct{}

MarkdownFormatter outputs violations in Markdown format

func (*MarkdownFormatter) ContentType

func (f *MarkdownFormatter) ContentType() string

func (*MarkdownFormatter) Format

func (f *MarkdownFormatter) Format(violations *LintViolations, cfg *Config) ([]byte, error)

type NoOpProgressReporter

type NoOpProgressReporter struct{}

NoOpProgressReporter is a no-op implementation

func (*NoOpProgressReporter) Complete

func (n *NoOpProgressReporter) Complete(stats *LintStats)

func (*NoOpProgressReporter) CompleteFile

func (n *NoOpProgressReporter) CompleteFile(path string, violations int)

func (*NoOpProgressReporter) StartFile

func (n *NoOpProgressReporter) StartFile(path string)

func (*NoOpProgressReporter) UpdateProgress

func (n *NoOpProgressReporter) UpdateProgress(current, total int)

type Option

type Option func(*ConcurrentLinter) error

Option is a functional option for ConcurrentLinter

func WithBufferSize

func WithBufferSize(size int) Option

WithBufferSize sets the job buffer size

func WithProgressReporter

func WithProgressReporter(reporter ProgressReporter) Option

WithProgressReporter sets a progress reporter

func WithWorkerCount

func WithWorkerCount(count int) Option

WithWorkerCount sets the number of worker goroutines

type OutputFormat

type OutputFormat string

OutputFormat represents the output format type

const (
	// FormatText outputs human-readable text (default)
	FormatText OutputFormat = "text"
	// FormatJSON outputs machine-readable JSON
	FormatJSON OutputFormat = "json"
	// FormatSARIF outputs SARIF 2.1.0 format for CI/CD integration
	FormatSARIF OutputFormat = "sarif"
	// FormatCheckstyle outputs Checkstyle XML format
	FormatCheckstyle OutputFormat = "checkstyle"
	// FormatJUnit outputs JUnit XML format
	FormatJUnit OutputFormat = "junit"
	// FormatMarkdown outputs Markdown format for documentation
	FormatMarkdown OutputFormat = "markdown"
)

type ProgressReporter

type ProgressReporter interface {
	StartFile(path string)
	CompleteFile(path string, violations int)
	UpdateProgress(current, total int)
	Complete(stats *LintStats)
}

ProgressReporter interface for progress updates

type ProhibitedPkg

type ProhibitedPkg struct {
	Name  string `json:"name" yaml:"name" mapstructure:"name"`
	Cause string `json:"cause" yaml:"cause" mapstructure:"cause"`
}

type Result

type Result struct {
	Violations []LintViolation
	Error      error
}

Result represents the violations found in a file

type Rule

type Rule struct {
	Path       string          `json:"path" yaml:"path" mapstructure:"path"`
	Allowed    []string        `json:"allowed" yaml:"allowed" mapstructure:"allowed"`
	Prohibited []ProhibitedPkg `json:"prohibited" yaml:"prohibited" mapstructure:"prohibited"`
}

type RuleMatcher

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

RuleMatcher encapsulates the logic for matching imports against rules

func (*RuleMatcher) CheckImport

func (m *RuleMatcher) CheckImport(imp string, normalizedPath string, logger *slog.Logger) *LintViolation

CheckImport checks a single import against the rule

func (*RuleMatcher) IsAllowed

func (m *RuleMatcher) IsAllowed(imp string) bool

IsAllowed checks if an import is allowed by the rule

func (*RuleMatcher) IsProhibited

func (m *RuleMatcher) IsProhibited(imp string) (string, bool)

IsProhibited checks if an import is prohibited by the rule

type RuleSummary

type RuleSummary struct {
	Name       string `json:"name"`
	Violations int    `json:"violations"`
}

type SARIFArtifactLocation

type SARIFArtifactLocation struct {
	URI string `json:"uri"`
}

type SARIFDriver

type SARIFDriver struct {
	Name            string      `json:"name"`
	InformationURI  string      `json:"informationUri"`
	Version         string      `json:"version"`
	SemanticVersion string      `json:"semanticVersion"`
	Rules           []SARIFRule `json:"rules"`
}

type SARIFFormatter

type SARIFFormatter struct{}

SARIFFormatter outputs violations in SARIF 2.1.0 format

func (*SARIFFormatter) ContentType

func (f *SARIFFormatter) ContentType() string

func (*SARIFFormatter) Format

func (f *SARIFFormatter) Format(violations *LintViolations, cfg *Config) ([]byte, error)

type SARIFLocation

type SARIFLocation struct {
	PhysicalLocation SARIFPhysicalLocation `json:"physicalLocation"`
}

type SARIFMessage

type SARIFMessage struct {
	Text string `json:"text"`
}

type SARIFOutput

type SARIFOutput struct {
	Schema  string     `json:"$schema"`
	Version string     `json:"version"`
	Runs    []SARIFRun `json:"runs"`
}

SARIF structures according to the SARIF 2.1.0 specification

type SARIFPhysicalLocation

type SARIFPhysicalLocation struct {
	ArtifactLocation SARIFArtifactLocation `json:"artifactLocation"`
	Region           *SARIFRegion          `json:"region,omitzero"`
}

type SARIFRegion

type SARIFRegion struct {
	StartLine   int `json:"startLine"`
	StartColumn int `json:"startColumn"`
	EndLine     int `json:"endLine"`
	EndColumn   int `json:"endColumn"`
}

type SARIFResult

type SARIFResult struct {
	RuleID    string          `json:"ruleId"`
	Level     string          `json:"level"`
	Message   SARIFMessage    `json:"message"`
	Locations []SARIFLocation `json:"locations"`
}

type SARIFRule

type SARIFRule struct {
	ID               string          `json:"id"`
	Name             string          `json:"name"`
	ShortDescription SARIFMessage    `json:"shortDescription"`
	FullDescription  SARIFMessage    `json:"fullDescription"`
	Help             SARIFMessage    `json:"help"`
	DefaultConfig    SARIFRuleConfig `json:"defaultConfiguration"`
	Properties       map[string]any  `json:"properties,omitzero"`
}

type SARIFRuleConfig

type SARIFRuleConfig struct {
	Level string `json:"level"`
}

type SARIFRun

type SARIFRun struct {
	Tool    SARIFTool     `json:"tool"`
	Results []SARIFResult `json:"results"`
}

type SARIFTool

type SARIFTool struct {
	Driver SARIFDriver `json:"driver"`
}

type Summary

type Summary struct {
	TotalViolations int    `json:"total_violations"`
	FilesWithIssues int    `json:"files_with_issues"`
	Status          string `json:"status"`
}

type TextFormatter

type TextFormatter struct{}

TextFormatter outputs violations in human-readable text format

func (*TextFormatter) ContentType

func (f *TextFormatter) ContentType() string

func (*TextFormatter) Format

func (f *TextFormatter) Format(violations *LintViolations, cfg *Config) ([]byte, error)

Directories

Path Synopsis
examples
cache-demo command

Jump to

Keyboard shortcuts

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