Documentation ¶
Overview ¶
Package internal provides the core functionality for a Go-compatible linting tool.
This package implements a flexible and extensible linting engine that can be used to analyze Go and Gno code for potential issues, style violations, and areas of improvement. It is designed to be easily extendable with custom lint rules while providing a set of default rules out of the box.
Key components:
Engine: The main linting engine that coordinates the linting process. It manages a collection of lint rules and applies them to the given source files.
LintRule: An interface that defines the contract for all lint rules. Each lint rule must implement the Check method to analyze the code and return issues.
Issue: Represents a single lint issue found in the code, including its location and description.
SymbolTable: A data structure that keeps track of defined symbols across the codebase, helping to reduce false positives in certain lint rules.
SourceCode: A simple structure to represent the content of a source file as a collection of lines.
The package also includes several helper functions for file operations, running external tools, and managing temporary files during the linting process.
Usage:
engine, err := internal.NewEngine("path/to/root/dir") if err != nil { // handle error } // Optionally add custom rules engine.AddRule(myCustomRule) issues, err := engine.Run("path/to/file.go") if err != nil { // handle error } // Process the found issues for _, issue := range issues { fmt.Printf("Found issue: %s at %s\n", issue.Message, issue.Start) }
This package is intended for internal use within the linting tool and should not be imported by external packages.
Index ¶
- type ConstErrorDeclarationRule
- type CyclomaticComplexityRule
- type DeferRule
- type DeprecateFuncRule
- type DetectCycleRule
- type EarlyReturnOpportunityRule
- type EmitFormatRule
- type Engine
- type GnoSpecificRule
- type GolangciLintRule
- type LintRule
- func NewConstErrorDeclarationRule() LintRule
- func NewCyclomaticComplexityRule(threshold int) LintRule
- func NewDeferRule() LintRule
- func NewDeprecateFuncRule() LintRule
- func NewDetectCycleRule() LintRule
- func NewEarlyReturnOpportunityRule() LintRule
- func NewEmitFormatRule() LintRule
- func NewGnoSpecificRule() LintRule
- func NewGolangciLintRule() LintRule
- func NewLoopAllocationRule() LintRule
- func NewMissingModPackageRule() LintRule
- func NewRepeatedRegexCompilationRule() LintRule
- func NewSimplifySliceExprRule() LintRule
- func NewSliceBoundCheckRule() LintRule
- func NewUnnecessaryConversionRule() LintRule
- func NewUselessBreakRule() LintRule
- type LoopAllocationRule
- type MissingModPackageRule
- type ModRule
- type RepeatedRegexCompilationRule
- func (r *RepeatedRegexCompilationRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)
- func (r *RepeatedRegexCompilationRule) Name() string
- func (r *RepeatedRegexCompilationRule) SetSeverity(severity tt.Severity)
- func (r *RepeatedRegexCompilationRule) Severity() tt.Severity
- type SimplifySliceExprRule
- type SliceBoundCheckRule
- type SourceCode
- type UnnecessaryConversionRule
- type UselessBreakRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstErrorDeclarationRule ¶
type ConstErrorDeclarationRule struct {
// contains filtered or unexported fields
}
func (*ConstErrorDeclarationRule) Name ¶
func (r *ConstErrorDeclarationRule) Name() string
func (*ConstErrorDeclarationRule) SetSeverity ¶
func (r *ConstErrorDeclarationRule) SetSeverity(severity tt.Severity)
func (*ConstErrorDeclarationRule) Severity ¶
func (r *ConstErrorDeclarationRule) Severity() tt.Severity
type CyclomaticComplexityRule ¶
type CyclomaticComplexityRule struct { Threshold int // contains filtered or unexported fields }
func (*CyclomaticComplexityRule) Name ¶
func (r *CyclomaticComplexityRule) Name() string
func (*CyclomaticComplexityRule) SetSeverity ¶
func (r *CyclomaticComplexityRule) SetSeverity(severity tt.Severity)
func (*CyclomaticComplexityRule) Severity ¶
func (r *CyclomaticComplexityRule) Severity() tt.Severity
type DeferRule ¶
type DeferRule struct {
// contains filtered or unexported fields
}
func (*DeferRule) SetSeverity ¶
type DeprecateFuncRule ¶
type DeprecateFuncRule struct {
// contains filtered or unexported fields
}
func (*DeprecateFuncRule) Name ¶
func (r *DeprecateFuncRule) Name() string
func (*DeprecateFuncRule) SetSeverity ¶
func (r *DeprecateFuncRule) SetSeverity(severity tt.Severity)
func (*DeprecateFuncRule) Severity ¶
func (r *DeprecateFuncRule) Severity() tt.Severity
type DetectCycleRule ¶
type DetectCycleRule struct {
// contains filtered or unexported fields
}
func (*DetectCycleRule) Name ¶
func (r *DetectCycleRule) Name() string
func (*DetectCycleRule) SetSeverity ¶
func (r *DetectCycleRule) SetSeverity(severity tt.Severity)
func (*DetectCycleRule) Severity ¶
func (r *DetectCycleRule) Severity() tt.Severity
type EarlyReturnOpportunityRule ¶
type EarlyReturnOpportunityRule struct {
// contains filtered or unexported fields
}
func (*EarlyReturnOpportunityRule) Name ¶
func (r *EarlyReturnOpportunityRule) Name() string
func (*EarlyReturnOpportunityRule) SetSeverity ¶
func (r *EarlyReturnOpportunityRule) SetSeverity(severity tt.Severity)
func (*EarlyReturnOpportunityRule) Severity ¶
func (r *EarlyReturnOpportunityRule) Severity() tt.Severity
type EmitFormatRule ¶
type EmitFormatRule struct {
// contains filtered or unexported fields
}
func (*EmitFormatRule) Name ¶
func (r *EmitFormatRule) Name() string
func (*EmitFormatRule) SetSeverity ¶
func (r *EmitFormatRule) SetSeverity(severity tt.Severity)
func (*EmitFormatRule) Severity ¶
func (r *EmitFormatRule) Severity() tt.Severity
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine manages the linting process. TODO: use symbol table
func (*Engine) IgnoreRule ¶
type GnoSpecificRule ¶
type GnoSpecificRule struct {
// contains filtered or unexported fields
}
GnoSpecificRule checks for gno-specific package imports. (p, r and std)
func (*GnoSpecificRule) Name ¶
func (r *GnoSpecificRule) Name() string
func (*GnoSpecificRule) SetSeverity ¶
func (r *GnoSpecificRule) SetSeverity(severity tt.Severity)
func (*GnoSpecificRule) Severity ¶
func (r *GnoSpecificRule) Severity() tt.Severity
type GolangciLintRule ¶
type GolangciLintRule struct {
// contains filtered or unexported fields
}
func (*GolangciLintRule) Name ¶
func (r *GolangciLintRule) Name() string
func (*GolangciLintRule) SetSeverity ¶
func (r *GolangciLintRule) SetSeverity(severity tt.Severity)
func (*GolangciLintRule) Severity ¶
func (r *GolangciLintRule) Severity() tt.Severity
type LintRule ¶
type LintRule interface { // Check runs the lint rule on the given file and returns a slice of Issues. Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error) // Name returns the name of the lint rule. Name() string // Severity returns the severity of the lint rule. Severity() tt.Severity // SetSeverity sets the severity of the lint rule. SetSeverity(tt.Severity) }
LintRule defines the interface for all lint rules.
func NewConstErrorDeclarationRule ¶
func NewConstErrorDeclarationRule() LintRule
func NewDeferRule ¶
func NewDeferRule() LintRule
func NewDeprecateFuncRule ¶
func NewDeprecateFuncRule() LintRule
func NewDetectCycleRule ¶
func NewDetectCycleRule() LintRule
func NewEarlyReturnOpportunityRule ¶
func NewEarlyReturnOpportunityRule() LintRule
func NewEmitFormatRule ¶
func NewEmitFormatRule() LintRule
func NewGnoSpecificRule ¶
func NewGnoSpecificRule() LintRule
func NewGolangciLintRule ¶
func NewGolangciLintRule() LintRule
func NewLoopAllocationRule ¶
func NewLoopAllocationRule() LintRule
func NewMissingModPackageRule ¶
func NewMissingModPackageRule() LintRule
func NewRepeatedRegexCompilationRule ¶
func NewRepeatedRegexCompilationRule() LintRule
func NewSimplifySliceExprRule ¶
func NewSimplifySliceExprRule() LintRule
func NewSliceBoundCheckRule ¶
func NewSliceBoundCheckRule() LintRule
func NewUnnecessaryConversionRule ¶
func NewUnnecessaryConversionRule() LintRule
func NewUselessBreakRule ¶
func NewUselessBreakRule() LintRule
type LoopAllocationRule ¶
type LoopAllocationRule struct {
// contains filtered or unexported fields
}
func (*LoopAllocationRule) Name ¶
func (r *LoopAllocationRule) Name() string
func (*LoopAllocationRule) SetSeverity ¶
func (r *LoopAllocationRule) SetSeverity(severity tt.Severity)
func (*LoopAllocationRule) Severity ¶
func (r *LoopAllocationRule) Severity() tt.Severity
type MissingModPackageRule ¶
type MissingModPackageRule struct {
// contains filtered or unexported fields
}
func (*MissingModPackageRule) Name ¶
func (r *MissingModPackageRule) Name() string
func (*MissingModPackageRule) SetSeverity ¶
func (r *MissingModPackageRule) SetSeverity(severity tt.Severity)
func (*MissingModPackageRule) Severity ¶
func (r *MissingModPackageRule) Severity() tt.Severity
type RepeatedRegexCompilationRule ¶
type RepeatedRegexCompilationRule struct {
// contains filtered or unexported fields
}
func (*RepeatedRegexCompilationRule) Name ¶
func (r *RepeatedRegexCompilationRule) Name() string
func (*RepeatedRegexCompilationRule) SetSeverity ¶
func (r *RepeatedRegexCompilationRule) SetSeverity(severity tt.Severity)
func (*RepeatedRegexCompilationRule) Severity ¶
func (r *RepeatedRegexCompilationRule) Severity() tt.Severity
type SimplifySliceExprRule ¶
type SimplifySliceExprRule struct {
// contains filtered or unexported fields
}
func (*SimplifySliceExprRule) Name ¶
func (r *SimplifySliceExprRule) Name() string
func (*SimplifySliceExprRule) SetSeverity ¶
func (r *SimplifySliceExprRule) SetSeverity(severity tt.Severity)
func (*SimplifySliceExprRule) Severity ¶
func (r *SimplifySliceExprRule) Severity() tt.Severity
type SliceBoundCheckRule ¶
type SliceBoundCheckRule struct {
// contains filtered or unexported fields
}
func (*SliceBoundCheckRule) Name ¶
func (r *SliceBoundCheckRule) Name() string
func (*SliceBoundCheckRule) SetSeverity ¶
func (r *SliceBoundCheckRule) SetSeverity(severity tt.Severity)
func (*SliceBoundCheckRule) Severity ¶
func (r *SliceBoundCheckRule) Severity() tt.Severity
type SourceCode ¶
type SourceCode struct {
Lines []string
}
SourceCode stores the content of a source code file.
func ReadSourceCode ¶
func ReadSourceCode(filename string) (*SourceCode, error)
ReadSourceFile reads the content of a file and returns it as a `SourceCode` struct.
type UnnecessaryConversionRule ¶
type UnnecessaryConversionRule struct {
// contains filtered or unexported fields
}
func (*UnnecessaryConversionRule) Name ¶
func (r *UnnecessaryConversionRule) Name() string
func (*UnnecessaryConversionRule) SetSeverity ¶
func (r *UnnecessaryConversionRule) SetSeverity(severity tt.Severity)
func (*UnnecessaryConversionRule) Severity ¶
func (r *UnnecessaryConversionRule) Severity() tt.Severity
type UselessBreakRule ¶
type UselessBreakRule struct {
// contains filtered or unexported fields
}
func (*UselessBreakRule) Name ¶
func (r *UselessBreakRule) Name() string
func (*UselessBreakRule) SetSeverity ¶
func (r *UselessBreakRule) SetSeverity(severity tt.Severity)
func (*UselessBreakRule) Severity ¶
func (r *UselessBreakRule) Severity() tt.Severity