refactor

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToMultiFileChanges added in v0.35.0

func ConvertToMultiFileChanges(proposals []RefactorProposal) []*review.MultiFileChange

ConvertToMultiFileChanges converts actionable proposals to MultiFileChanges.

func FormatHealthWarning

func FormatHealthWarning(result *HealthCheckResult) string

FormatHealthWarning はヘルスチェック結果を警告メッセージとしてフォーマットする

func GenerateExtractMethodCode added in v0.35.0

func GenerateExtractMethodCode(funcCode string, funcName string, filePath string, llm review.LLMClient) (*review.MultiFileChange, error)

GenerateExtractMethodCode generates code for extracting a method.

func GenerateSplitFilePlan added in v0.35.0

func GenerateSplitFilePlan(code string, filePath string, llm review.LLMClient) (*review.MultiFileChange, error)

GenerateSplitFilePlan generates a plan to split a large file.

func ShouldCheckHealth

func ShouldCheckHealth(filePath string) bool

ShouldCheckHealth はファイルが健全性チェック対象かを判定

Types

type AIRefactorProposal added in v0.35.0

type AIRefactorProposal struct {
	Type         string  `json:"type"`
	Description  string  `json:"description"`
	LineStart    int     `json:"line_start"`
	LineEnd      int     `json:"line_end"`
	FunctionName string  `json:"function_name"`
	Confidence   float64 `json:"confidence"`
}

AIRefactorProposal represents the AI response structure.

type AIRefactorResponse added in v0.35.0

type AIRefactorResponse struct {
	Proposals []AIRefactorProposal `json:"proposals"`
}

AIRefactorResponse represents the full AI response.

type ExtractMethodResult added in v0.35.0

type ExtractMethodResult struct {
	OldCode string `json:"old_code"`
	NewCode string `json:"new_code"`
}

ExtractMethodResult represents the AI extract method response.

type HealthCheckConfig

type HealthCheckConfig struct {
	Enabled          bool
	MaxFileLines     int
	MaxFunctionLines int
	CheckFileSize    bool
	CheckFuncSize    bool
	CheckDuplication bool
}

HealthCheckConfig はチェック設定

func DefaultHealthCheckConfig

func DefaultHealthCheckConfig() HealthCheckConfig

DefaultHealthCheckConfig はデフォルト設定を返す

type HealthCheckResult

type HealthCheckResult struct {
	FilePath         string
	HasWarning       bool
	FileLines        int
	MaxFileLines     int
	LongFunctions    []LongFunctionInfo
	MaxFunctionLines int
	Suggestions      []string
}

HealthCheckResult はコード健全性チェックの結果

func CheckFileHealth

func CheckFileHealth(filePath string, config HealthCheckConfig) *HealthCheckResult

CheckFileHealth はファイルの健全性をチェックする

type LongFunctionInfo

type LongFunctionInfo struct {
	Name      string
	Lines     int
	LineStart int
}

LongFunctionInfo は長い関数の情報

type RefactorConfig added in v0.35.0

type RefactorConfig struct {
	MaxFileLines      int // Default: 300
	MaxFunctionLines  int // Default: 50
	MinDuplicateLines int // Default: 10
}

RefactorConfig holds configuration for refactoring analysis.

func DefaultConfig added in v0.35.0

func DefaultConfig() RefactorConfig

DefaultConfig returns the default refactoring configuration.

type RefactorOptions added in v0.35.0

type RefactorOptions struct {
	Paths      []string
	Config     RefactorConfig
	TypeFilter RefactorType // Empty means all types
}

RefactorOptions holds options for the /refactor command.

type RefactorProposal added in v0.35.0

type RefactorProposal struct {
	ID          string
	Type        RefactorType
	Description string
	FilePath    string
	LineStart   int
	LineEnd     int

	// Details for different refactor types
	FunctionName string   // For extract-method
	NewNames     []string // For split-file (new file names)

	// For actionable proposals
	Change     *review.MultiFileChange
	Confidence float64
	Actionable bool

	// Metrics
	CurrentLines int
	TargetLines  int
}

RefactorProposal represents a refactoring suggestion.

func AnalyzeWithAI added in v0.35.0

func AnalyzeWithAI(code string, filePath string, llm review.LLMClient) ([]RefactorProposal, error)

AnalyzeWithAI uses LLM to find refactoring opportunities.

func DetectDuplicateCode added in v0.35.0

func DetectDuplicateCode(files []string, minLines int) []RefactorProposal

DetectDuplicateCode detects duplicate code blocks.

func DetectLargeFiles added in v0.35.0

func DetectLargeFiles(files []string, maxLines int) []RefactorProposal

DetectLargeFiles detects files that exceed the maximum line count.

func DetectLongFunctions added in v0.35.0

func DetectLongFunctions(files []string, maxLines int) []RefactorProposal

DetectLongFunctions detects functions that exceed the maximum line count.

func DetectPoorNaming added in v0.35.0

func DetectPoorNaming(files []string) []RefactorProposal

DetectPoorNaming detects poor naming conventions.

func FilterByType added in v0.35.0

func FilterByType(proposals []RefactorProposal, t RefactorType) []RefactorProposal

FilterByType filters proposals by refactor type.

type RefactorReport added in v0.35.0

type RefactorReport struct {
	Proposals []RefactorProposal
	Stats     RefactorStats
}

RefactorReport contains the full refactoring analysis result.

type RefactorStats added in v0.35.0

type RefactorStats struct {
	FilesAnalyzed   int
	LargeFiles      int
	LongFunctions   int
	DuplicateBlocks int
	NamingIssues    int
	TotalProposals  int
	ActionableCount int
}

RefactorStats contains statistics about the refactoring analysis.

type RefactorType added in v0.35.0

type RefactorType string

RefactorType represents the type of refactoring.

const (
	RefactorSplitFile     RefactorType = "split-file"     // Large file splitting
	RefactorExtractMethod RefactorType = "extract-method" // Long function extraction
	RefactorDRY           RefactorType = "dry"            // Duplicate code consolidation
	RefactorRename        RefactorType = "rename"         // Naming improvement
)

type Refactorer added in v0.35.0

type Refactorer struct {
	Config RefactorConfig
	LLM    review.LLMClient // Optional, for AI-powered analysis
}

Refactorer performs code refactoring analysis and application.

func NewRefactorer added in v0.35.0

func NewRefactorer() *Refactorer

NewRefactorer creates a new Refactorer with default config.

func NewRefactorerWithConfig added in v0.35.0

func NewRefactorerWithConfig(config RefactorConfig) *Refactorer

NewRefactorerWithConfig creates a new Refactorer with custom config.

func (*Refactorer) Analyze added in v0.35.0

func (r *Refactorer) Analyze(paths []string) (*RefactorReport, error)

Analyze performs refactoring analysis on the given paths.

func (*Refactorer) Apply added in v0.35.0

func (r *Refactorer) Apply(proposal RefactorProposal) error

Apply applies a refactoring proposal using the multi-file applier.

type SplitPlan added in v0.35.0

type SplitPlan struct {
	Files []SplitPlanFile `json:"files"`
}

SplitPlan represents the AI-generated split plan.

type SplitPlanFile added in v0.35.0

type SplitPlanFile struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Functions   []string `json:"functions"`
	LinesStart  int      `json:"lines_start"`
	LinesEnd    int      `json:"lines_end"`
}

SplitPlanFile represents a file in the split plan.

Jump to

Keyboard shortcuts

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