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 CyclomaticComplexityRule
- type DeferRule
- type DetectCycleRule
- type EarlyReturnOpportunityRule
- type EmitFormatRule
- type Engine
- type GnoSpecificRule
- type GolangciLintRule
- type LintRule
- type LoopAllocationRule
- type MissingModPackageRule
- type ModRule
- type RepeatedRegexCompilationRule
- type SimplifySliceExprRule
- type SliceBoundCheckRule
- type SourceCode
- type SymbolInfo
- type SymbolTable
- type SymbolType
- type UnnecessaryConversionRule
- type UselessBreakRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CyclomaticComplexityRule ¶
type CyclomaticComplexityRule struct {
Threshold int
}
func (*CyclomaticComplexityRule) Name ¶
func (r *CyclomaticComplexityRule) Name() string
type DetectCycleRule ¶
type DetectCycleRule struct{}
func (*DetectCycleRule) Name ¶
func (r *DetectCycleRule) Name() string
type EarlyReturnOpportunityRule ¶
type EarlyReturnOpportunityRule struct{}
func (*EarlyReturnOpportunityRule) Name ¶
func (r *EarlyReturnOpportunityRule) Name() string
type EmitFormatRule ¶
type EmitFormatRule struct{}
func (*EmitFormatRule) Name ¶
func (r *EmitFormatRule) Name() string
type Engine ¶
type Engine struct { SymbolTable *SymbolTable // contains filtered or unexported fields }
Engine manages the linting process.
func (*Engine) IgnoreRule ¶
type GnoSpecificRule ¶
type GnoSpecificRule struct{}
GnoSpecificRule checks for gno-specific package imports. (p, r and std)
func (*GnoSpecificRule) Name ¶
func (r *GnoSpecificRule) Name() string
type GolangciLintRule ¶
type GolangciLintRule struct{}
func (*GolangciLintRule) Name ¶
func (r *GolangciLintRule) Name() string
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 }
LintRule defines the interface for all lint rules.
type LoopAllocationRule ¶
type LoopAllocationRule struct{}
func (*LoopAllocationRule) Name ¶
func (r *LoopAllocationRule) Name() string
type MissingModPackageRule ¶
type MissingModPackageRule struct{}
func (*MissingModPackageRule) Name ¶
func (r *MissingModPackageRule) Name() string
type RepeatedRegexCompilationRule ¶
type RepeatedRegexCompilationRule struct{}
func (*RepeatedRegexCompilationRule) Name ¶
func (r *RepeatedRegexCompilationRule) Name() string
type SimplifySliceExprRule ¶
type SimplifySliceExprRule struct{}
func (*SimplifySliceExprRule) Name ¶
func (r *SimplifySliceExprRule) Name() string
type SliceBoundCheckRule ¶
type SliceBoundCheckRule struct{}
func (*SliceBoundCheckRule) Name ¶
func (r *SliceBoundCheckRule) Name() string
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 SymbolInfo ¶
type SymbolInfo struct { Name string Type SymbolType Package string FilePath string Interfaces []string // list of interfaces the symbol implements }
type SymbolTable ¶
type SymbolTable struct {
// contains filtered or unexported fields
}
func BuildSymbolTable ¶
func BuildSymbolTable(rootDir string) (*SymbolTable, error)
func (*SymbolTable) AddInterfaceImplementation ¶
func (st *SymbolTable) AddInterfaceImplementation(typeName, interfaceName string)
func (*SymbolTable) GetSymbolInfo ¶
func (st *SymbolTable) GetSymbolInfo(symbol string) (SymbolInfo, bool)
func (*SymbolTable) IsDefined ¶
func (st *SymbolTable) IsDefined(symbol string) bool
type UnnecessaryConversionRule ¶
type UnnecessaryConversionRule struct{}
func (*UnnecessaryConversionRule) Name ¶
func (r *UnnecessaryConversionRule) Name() string