internal

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 11 Imported by: 0

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

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) Check

func (r *CyclomaticComplexityRule) Check(filename string, node *ast.File) ([]tt.Issue, error)

func (*CyclomaticComplexityRule) Name

func (r *CyclomaticComplexityRule) Name() string

type DeferRule

type DeferRule struct{}

func (*DeferRule) Check

func (r *DeferRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*DeferRule) Name

func (r *DeferRule) Name() string

type DetectCycleRule

type DetectCycleRule struct{}

func (*DetectCycleRule) Check

func (r *DetectCycleRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*DetectCycleRule) Name

func (r *DetectCycleRule) Name() string

type EarlyReturnOpportunityRule

type EarlyReturnOpportunityRule struct{}

func (*EarlyReturnOpportunityRule) Check

func (r *EarlyReturnOpportunityRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*EarlyReturnOpportunityRule) Name

type EmitFormatRule

type EmitFormatRule struct{}

func (*EmitFormatRule) Check

func (r *EmitFormatRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

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 NewEngine

func NewEngine(rootDir string) (*Engine, error)

NewEngine creates a new lint engine.

func (*Engine) IgnoreRule

func (e *Engine) IgnoreRule(rule string)

func (*Engine) Run

func (e *Engine) Run(filename string) ([]tt.Issue, error)

Run applies all lint rules to the given file and returns a slice of Issues.

type GnoSpecificRule

type GnoSpecificRule struct{}

GnoSpecificRule checks for gno-specific package imports. (p, r and std)

func (*GnoSpecificRule) Check

func (r *GnoSpecificRule) Check(filename string, _ *ast.File, _ *token.FileSet) ([]tt.Issue, error)

func (*GnoSpecificRule) Name

func (r *GnoSpecificRule) Name() string

type GolangciLintRule

type GolangciLintRule struct{}

func (*GolangciLintRule) Check

func (r *GolangciLintRule) Check(filename string, _ *ast.File, _ *token.FileSet) ([]tt.Issue, error)

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) Check

func (r *LoopAllocationRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*LoopAllocationRule) Name

func (r *LoopAllocationRule) Name() string

type MissingModPackageRule

type MissingModPackageRule struct{}

func (*MissingModPackageRule) Check

func (r *MissingModPackageRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*MissingModPackageRule) Name

func (r *MissingModPackageRule) Name() string

type ModRule

type ModRule interface {
	LintRule
	CheckMod(filename string) ([]tt.Issue, error)
}

type RepeatedRegexCompilationRule

type RepeatedRegexCompilationRule struct{}

func (*RepeatedRegexCompilationRule) Check

func (r *RepeatedRegexCompilationRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*RepeatedRegexCompilationRule) Name

type SimplifySliceExprRule

type SimplifySliceExprRule struct{}

func (*SimplifySliceExprRule) Check

func (r *SimplifySliceExprRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*SimplifySliceExprRule) Name

func (r *SimplifySliceExprRule) Name() string

type SliceBoundCheckRule

type SliceBoundCheckRule struct{}

func (*SliceBoundCheckRule) Check

func (r *SliceBoundCheckRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

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 SymbolType

type SymbolType int
const (
	Function SymbolType = iota
	Type
	Variable
	Method
)

type UnnecessaryConversionRule

type UnnecessaryConversionRule struct{}

func (*UnnecessaryConversionRule) Check

func (r *UnnecessaryConversionRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*UnnecessaryConversionRule) Name

type UselessBreakRule

type UselessBreakRule struct{}

func (*UselessBreakRule) Check

func (r *UselessBreakRule) Check(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error)

func (*UselessBreakRule) Name

func (r *UselessBreakRule) Name() string

Directories

Path Synopsis
analysis
cfg

Jump to

Keyboard shortcuts

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