internal

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 10 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 ConstErrorDeclarationRule

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

func (*ConstErrorDeclarationRule) Check

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

func (*ConstErrorDeclarationRule) Name

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

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

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

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

func (*DeferRule) Name

func (r *DeferRule) Name() string

func (*DeferRule) SetSeverity

func (r *DeferRule) SetSeverity(severity tt.Severity)

func (*DeferRule) Severity

func (r *DeferRule) Severity() tt.Severity

type DeprecateFuncRule

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

func (*DeprecateFuncRule) Check

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

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

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

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

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

func (*EarlyReturnOpportunityRule) Name

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

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

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 NewEngine

func NewEngine(rootDir string, source []byte, rules map[string]tt.ConfigRule) (*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.

func (*Engine) RunSource

func (e *Engine) RunSource(source []byte) ([]tt.Issue, error)

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

type GnoSpecificRule

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

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

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

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

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 NewCyclomaticComplexityRule

func NewCyclomaticComplexityRule(threshold int) 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) Check

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

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

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

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 ModRule

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

type RepeatedRegexCompilationRule

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

func (*RepeatedRegexCompilationRule) Check

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

func (*RepeatedRegexCompilationRule) Name

func (*RepeatedRegexCompilationRule) SetSeverity

func (r *RepeatedRegexCompilationRule) SetSeverity(severity tt.Severity)

func (*RepeatedRegexCompilationRule) Severity

type SimplifySliceExprRule

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

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

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

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

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

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

func (*UnnecessaryConversionRule) Name

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

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

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

Directories

Path Synopsis
analysis
cfg

Jump to

Keyboard shortcuts

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