tools

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package tools provides quality tool implementations for multiple programming languages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterFilesByExtensions

func FilterFilesByExtensions(files, extensions []string) []string

FilterFilesByExtensions filters files by supported extensions.

Types

type BaseTool

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

BaseTool provides common functionality for quality tools.

func NewBaseTool

func NewBaseTool(name, language, executable string, toolType ToolType) *BaseTool

NewBaseTool creates a new base tool.

func (*BaseTool) BuildCommand

func (t *BaseTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the command to execute (to be implemented by specific tools).

func (*BaseTool) Execute

func (t *BaseTool) Execute(ctx context.Context, files []string, options ExecuteOptions) (*Result, error)

Execute runs the tool on the specified files.

func (*BaseTool) ExecuteCommand

func (t *BaseTool) ExecuteCommand(ctx context.Context, cmd *exec.Cmd, files []string) (*Result, error)

ExecuteCommand runs a command and returns the result.

func (*BaseTool) FindConfigFiles

func (t *BaseTool) FindConfigFiles(projectRoot string) []string

FindConfigFiles returns configuration files the tool would use.

func (*BaseTool) GetVersion

func (t *BaseTool) GetVersion() (string, error)

GetVersion returns the version of the installed tool.

func (*BaseTool) Install

func (t *BaseTool) Install() error

Install attempts to install the tool automatically.

func (*BaseTool) IsAvailable

func (t *BaseTool) IsAvailable() bool

IsAvailable checks if the tool is installed and available.

func (*BaseTool) Language

func (t *BaseTool) Language() string

Language returns the programming language.

func (*BaseTool) Name

func (t *BaseTool) Name() string

Name returns the tool name.

func (*BaseTool) ParseOutput

func (t *BaseTool) ParseOutput(output string) []Issue

ParseOutput parses tool output into issues (to be implemented by specific tools).

func (*BaseTool) SetConfigPatterns

func (t *BaseTool) SetConfigPatterns(patterns []string)

SetConfigPatterns sets the configuration file patterns to search for.

func (*BaseTool) SetInstallCommand

func (t *BaseTool) SetInstallCommand(cmd []string)

SetInstallCommand sets the command to install this tool.

func (*BaseTool) Type

func (t *BaseTool) Type() ToolType

Type returns the tool type.

func (*BaseTool) Upgrade

func (t *BaseTool) Upgrade() error

Upgrade attempts to upgrade the tool to the latest version.

type BlackTool

type BlackTool struct {
	*BaseTool
}

BlackTool implements Python formatting using black.

func NewBlackTool

func NewBlackTool() *BlackTool

NewBlackTool creates a new black tool.

func (*BlackTool) BuildCommand

func (t *BlackTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the black command.

type CargoFmtTool

type CargoFmtTool struct {
	*BaseTool
}

CargoFmtTool implements Rust formatting using cargo fmt.

func NewCargoFmtTool

func NewCargoFmtTool() *CargoFmtTool

NewCargoFmtTool creates a new cargo fmt tool.

func (*CargoFmtTool) BuildCommand

func (t *CargoFmtTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the cargo fmt command.

type ClippyTool

type ClippyTool struct {
	*BaseTool
}

ClippyTool implements Rust linting using clippy.

func NewClippyTool

func NewClippyTool() *ClippyTool

NewClippyTool creates a new clippy tool.

func (*ClippyTool) BuildCommand

func (t *ClippyTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the clippy command.

func (*ClippyTool) ParseOutput

func (t *ClippyTool) ParseOutput(output string) []Issue

ParseOutput parses clippy JSON output.

type ConfigDetector

type ConfigDetector interface {
	// FindConfigs searches for tool configuration files
	FindConfigs(projectRoot string, tools []QualityTool) map[string]string

	// ValidateConfig checks if a configuration file is valid
	ValidateConfig(toolName, configPath string) error
}

ConfigDetector finds configuration files for quality tools.

type DefaultRegistry

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

DefaultRegistry is the default registry implementation.

func NewRegistry

func NewRegistry() *DefaultRegistry

NewRegistry creates a new tool registry.

func (*DefaultRegistry) FindTool

func (r *DefaultRegistry) FindTool(name string) QualityTool

FindTool finds a tool by name.

func (*DefaultRegistry) GetTools

func (r *DefaultRegistry) GetTools() []QualityTool

GetTools returns all registered tools.

func (*DefaultRegistry) GetToolsByLanguage

func (r *DefaultRegistry) GetToolsByLanguage(language string) []QualityTool

GetToolsByLanguage returns tools for a specific language.

func (*DefaultRegistry) GetToolsByType

func (r *DefaultRegistry) GetToolsByType(toolType ToolType) []QualityTool

GetToolsByType returns tools of a specific type.

func (*DefaultRegistry) Register

func (r *DefaultRegistry) Register(tool QualityTool)

Register adds a tool to the registry.

type ESLintTool

type ESLintTool struct {
	*BaseTool
}

ESLintTool implements JavaScript/TypeScript linting using eslint.

func NewESLintTool

func NewESLintTool() *ESLintTool

NewESLintTool creates a new eslint tool.

func (*ESLintTool) BuildCommand

func (t *ESLintTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the eslint command.

func (*ESLintTool) ParseOutput

func (t *ESLintTool) ParseOutput(output string) []Issue

ParseOutput parses eslint JSON output.

type ExecuteOptions

type ExecuteOptions struct {
	// ProjectRoot is the root directory of the project
	ProjectRoot string

	// ConfigFile is the path to the tool's configuration file
	ConfigFile string

	// Fix indicates whether to auto-fix issues (if supported)
	Fix bool

	// FormatOnly runs only formatting (for tools that support both)
	FormatOnly bool

	// LintOnly runs only linting (for tools that support both)
	LintOnly bool

	// ExtraArgs are additional arguments to pass to the tool
	ExtraArgs []string

	// Env contains environment variables for the tool
	Env map[string]string
}

ExecuteOptions contains options for tool execution.

type ExecutionPlan

type ExecutionPlan struct {
	// Tasks are the individual tool execution tasks
	Tasks []Task

	// TotalFiles is the total number of files to be processed
	TotalFiles int

	// EstimatedDuration is the estimated time to complete all tasks
	EstimatedDuration string
}

ExecutionPlan represents a plan for executing quality tools.

type Executor

type Executor interface {
	// Execute runs the execution plan
	Execute(ctx context.Context, plan *ExecutionPlan) ([]*Result, error)

	// ExecuteParallel runs the plan with parallel execution
	ExecuteParallel(ctx context.Context, plan *ExecutionPlan, workers int) ([]*Result, error)
}

Executor runs quality tools according to an execution plan.

type GofumptTool

type GofumptTool struct {
	*BaseTool
}

GofumptTool implements Go formatting using gofumpt.

func NewGofumptTool

func NewGofumptTool() *GofumptTool

NewGofumptTool creates a new gofumpt tool.

func (*GofumptTool) BuildCommand

func (t *GofumptTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the gofumpt command.

type GoimportsTool

type GoimportsTool struct {
	*BaseTool
}

GoimportsTool implements Go import formatting using goimports.

func NewGoimportsTool

func NewGoimportsTool() *GoimportsTool

NewGoimportsTool creates a new goimports tool.

func (*GoimportsTool) BuildCommand

func (t *GoimportsTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the goimports command.

type GolangciLintTool

type GolangciLintTool struct {
	*BaseTool
}

GolangciLintTool implements Go linting using golangci-lint.

func NewGolangciLintTool

func NewGolangciLintTool() *GolangciLintTool

NewGolangciLintTool creates a new golangci-lint tool.

func (*GolangciLintTool) BuildCommand

func (t *GolangciLintTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the golangci-lint command.

func (*GolangciLintTool) ParseOutput

func (t *GolangciLintTool) ParseOutput(output string) []Issue

ParseOutput parses golangci-lint JSON output.

type Issue

type Issue struct {
	// File is the path to the file containing the issue
	File string

	// Line is the line number (1-based)
	Line int

	// Column is the column number (1-based)
	Column int

	// Severity is the issue severity (error, warning, info)
	Severity string

	// Rule is the rule that was violated
	Rule string

	// Message is the issue description
	Message string

	// Suggestion is an optional fix suggestion
	Suggestion string
}

Issue represents a code quality issue found by a tool.

type LanguageDetector

type LanguageDetector interface {
	// DetectLanguages scans a directory and returns detected languages
	DetectLanguages(projectRoot string) ([]string, error)

	// GetFilesByLanguage returns files grouped by language
	GetFilesByLanguage(projectRoot string, languages []string) (map[string][]string, error)
}

LanguageDetector detects programming languages in a project.

type PrettierTool

type PrettierTool struct {
	*BaseTool
}

PrettierTool implements JavaScript/TypeScript formatting using prettier.

func NewPrettierTool

func NewPrettierTool() *PrettierTool

NewPrettierTool creates a new prettier tool.

func (*PrettierTool) BuildCommand

func (t *PrettierTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the prettier command.

type PylintTool

type PylintTool struct {
	*BaseTool
}

PylintTool implements Python linting using pylint.

func NewPylintTool

func NewPylintTool() *PylintTool

NewPylintTool creates a new pylint tool.

func (*PylintTool) BuildCommand

func (t *PylintTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the pylint command.

func (*PylintTool) ParseOutput

func (t *PylintTool) ParseOutput(output string) []Issue

ParseOutput parses pylint JSON output.

type QualityTool

type QualityTool interface {
	// Name returns the tool name (e.g., "gofumpt", "eslint")
	Name() string

	// Language returns the programming language (e.g., "Go", "Python")
	Language() string

	// Type returns the tool type (FORMAT, LINT, or BOTH)
	Type() ToolType

	// IsAvailable checks if the tool is installed and available
	IsAvailable() bool

	// Install attempts to install the tool automatically
	Install() error

	// GetVersion returns the version of the installed tool
	GetVersion() (string, error)

	// Upgrade attempts to upgrade the tool to the latest version
	Upgrade() error

	// FindConfigFiles returns configuration files the tool would use
	FindConfigFiles(projectRoot string) []string

	// Execute runs the tool on the specified files
	Execute(ctx context.Context, files []string, options ExecuteOptions) (*Result, error)
}

QualityTool represents a code quality tool (formatter or linter).

type Result

type Result struct {
	// Tool is the name of the tool that was executed
	Tool string

	// Language is the programming language
	Language string

	// Success indicates whether the tool executed successfully
	Success bool

	// Error contains any execution error
	Error error

	// FilesProcessed is the number of files processed
	FilesProcessed int

	// Duration is how long the tool took to run
	Duration string

	// Issues contains any issues found by the tool
	Issues []Issue

	// Output contains the raw output from the tool
	Output string
}

Result contains the results of tool execution.

type RuffTool

type RuffTool struct {
	*BaseTool
}

RuffTool implements Python linting and formatting using ruff.

func NewRuffTool

func NewRuffTool() *RuffTool

NewRuffTool creates a new ruff tool.

func (*RuffTool) BuildCommand

func (t *RuffTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the ruff command.

func (*RuffTool) Execute

func (t *RuffTool) Execute(ctx context.Context, files []string, options ExecuteOptions) (*Result, error)

Execute overrides the base Execute to handle both format and lint modes.

func (*RuffTool) ParseOutput

func (t *RuffTool) ParseOutput(output string) []Issue

ParseOutput parses ruff JSON output.

type RustfmtTool

type RustfmtTool struct {
	*BaseTool
}

RustfmtTool implements Rust formatting using rustfmt.

func NewRustfmtTool

func NewRustfmtTool() *RustfmtTool

NewRustfmtTool creates a new rustfmt tool.

func (*RustfmtTool) BuildCommand

func (t *RustfmtTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the rustfmt command.

type TSCTool

type TSCTool struct {
	*BaseTool
}

TSCTool implements TypeScript type checking using tsc.

func NewTSCTool

func NewTSCTool() *TSCTool

NewTSCTool creates a new tsc tool.

func (*TSCTool) BuildCommand

func (t *TSCTool) BuildCommand(files []string, options ExecuteOptions) *exec.Cmd

BuildCommand builds the tsc command.

func (*TSCTool) ParseOutput

func (t *TSCTool) ParseOutput(output string) []Issue

ParseOutput parses tsc output.

type Task

type Task struct {
	// Tool is the quality tool to execute
	Tool QualityTool

	// Files are the files to process
	Files []string

	// Options are the execution options
	Options ExecuteOptions

	// Priority affects execution order (higher = earlier)
	Priority int
}

Task represents a single tool execution task.

type ToolRegistry

type ToolRegistry interface {
	// Register adds a tool to the registry
	Register(tool QualityTool)

	// GetTools returns all registered tools
	GetTools() []QualityTool

	// GetToolsByLanguage returns tools for a specific language
	GetToolsByLanguage(language string) []QualityTool

	// GetToolsByType returns tools of a specific type
	GetToolsByType(toolType ToolType) []QualityTool

	// FindTool finds a tool by name
	FindTool(name string) QualityTool
}

ToolRegistry manages available quality tools.

type ToolType

type ToolType int

ToolType defines the type of quality tool.

const (
	FORMAT ToolType = iota
	LINT
	BOTH
)

func (ToolType) String

func (t ToolType) String() string

Jump to

Keyboard shortcuts

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