Documentation
¶
Index ¶
- Variables
- func AbsPath(path string) string
- func DirPath(path string) string
- func IsAbsPath(path string) bool
- func IsSubPath(parentPath, childPath string) bool
- func JoinPaths(elem ...string) string
- func NewCacheError(message string, err error) error
- func NewConfigError(message string, err error) error
- func NewError(message string, err error) error
- func NewFSError(message string, err error) error
- func NewLintError(message string, err error) error
- func NewParseError(message string, err error) error
- func NormalizePath(path string) string
- func WithDetails(err error, details string) error
- func WithFile(err error, file string) error
- type AppError
- type Cache
- type CacheInterface
- type CheckstyleError
- type CheckstyleFile
- type CheckstyleFormatter
- type CheckstyleOutput
- type ConcurrentLinter
- type Config
- type Formatter
- type JSONFormatter
- type JSONOutput
- type JSONViolation
- type JUnitFailure
- type JUnitFormatter
- type JUnitTestCase
- type JUnitTestSuite
- type JUnitTestSuites
- type Job
- type LintStats
- type LintViolation
- type LintViolations
- type Linter
- type MarkdownFormatter
- type NoOpProgressReporter
- type Option
- type OutputFormat
- type ProgressReporter
- type ProhibitedPkg
- type Result
- type Rule
- type RuleMatcher
- type RuleSummary
- type SARIFArtifactLocation
- type SARIFDriver
- type SARIFFormatter
- type SARIFLocation
- type SARIFMessage
- type SARIFOutput
- type SARIFPhysicalLocation
- type SARIFRegion
- type SARIFResult
- type SARIFRule
- type SARIFRuleConfig
- type SARIFRun
- type SARIFTool
- type Summary
- type TextFormatter
Constants ¶
This section is empty.
Variables ¶
var ( ErrEntryNotFound = errors.New("entry not found") ErrReadingCachedViolations = errors.New("cached violations are invalid") )
Cache-related errors
Functions ¶
func AbsPath ¶
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 ¶
DirPath returns the directory portion of a path This function works on all operating systems by normalizing paths to use forward slashes
func IsAbsPath ¶
IsAbsPath checks if a path is absolute This function works on all operating systems by using the system's path separator
func IsSubPath ¶
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 ¶
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 ¶
NewCacheError creates a new cache error
func NewConfigError ¶
NewConfigError creates a new configuration error
func NewFSError ¶
NewFSError creates a new file system error
func NewLintError ¶
NewLintError creates a new linting error
func NewParseError ¶
NewParseError creates a new parsing error
func NormalizePath ¶
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 ¶
WithDetails adds additional details to an error
Types ¶
type AppError ¶
AppError represents an application error with additional context
func GetErrorInfo ¶
GetErrorInfo extracts error information from an 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 ¶
NewCache creates a new cache with MUS encoding for maximum performance. MUS uses varint encoding and manual serialization for optimal efficiency.
func (*Cache) AddFileWithViolations ¶
func (c *Cache) AddFileWithViolations(path string, lv []LintViolation) error
AddFileWithViolations stores violations for a file using MUS encoding
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 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"`
}
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 JUnitFailure ¶
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 JUnitTestSuites ¶
type LintStats ¶
type LintStats struct {
// contains filtered or unexported fields
}
LintStats tracks performance metrics
func (*LintStats) FilesPerSecond ¶
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 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 WithProgressReporter ¶
func WithProgressReporter(reporter ProgressReporter) Option
WithProgressReporter sets a progress reporter
func WithWorkerCount ¶
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 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 SARIFArtifactLocation ¶
type SARIFArtifactLocation struct {
URI string `json:"uri"`
}
type SARIFDriver ¶
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 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 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)