service

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxConcurrency is used when config value is invalid.
	// NewParallelExecutor() uses runtime.NumCPU() for optimal CPU utilization,
	// while NewParallelExecutorFromConfig() falls back to this constant.
	DefaultMaxConcurrency = 4
	DefaultTimeout        = 5 * time.Minute
)

Default values for parallel executor

Variables

This section is empty.

Functions

func AnalyzeDeadCode added in v0.4.0

func AnalyzeDeadCode(ctx context.Context, req domain.DeadCodeRequest) (*domain.DeadCodeResponse, error)

AnalyzeDeadCode runs dead code analysis using the shared aggregation path.

func AnalyzeDeadCodeWithTask added in v0.4.0

func AnalyzeDeadCodeWithTask(ctx context.Context, req domain.DeadCodeRequest, task domain.TaskProgress) (*domain.DeadCodeResponse, error)

AnalyzeDeadCodeWithTask runs dead code analysis with optional progress reporting.

func BuildAnalyzeSummary added in v0.2.0

func BuildAnalyzeSummary(
	complexityResponse *domain.ComplexityResponse,
	deadCodeResponse *domain.DeadCodeResponse,
	cloneResponse *domain.CloneResponse,
	cboResponse *domain.CBOResponse,
	depsResponse *domain.DependencyGraphResponse,
) *domain.AnalyzeSummary

BuildAnalyzeSummary builds an AnalyzeSummary from analysis responses

func FormatCLISummary added in v0.2.0

func FormatCLISummary(summary *domain.AnalyzeSummary, duration time.Duration) string

FormatCLISummary formats an AnalyzeSummary as a compact CLI string (pyscn-style)

func IsInteractiveEnvironment

func IsInteractiveEnvironment() bool

IsInteractiveEnvironment returns true if the environment appears to be an interactive TTY session (and not CI)

func IsSSH

func IsSSH() bool

IsSSH returns true if the session is running over SSH

func NewProgressManager

func NewProgressManager(enabled bool) domain.ProgressManager

NewProgressManager creates a new progress manager based on environment

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser opens the specified URL in the default browser

func WriteJSON

func WriteJSON(writer io.Writer, data interface{}) error

WriteJSON writes data as JSON to the writer

Types

type AggregatedError

type AggregatedError struct {
	Errors []TaskError
}

AggregatedError collects all task failures

func (*AggregatedError) Error

func (e *AggregatedError) Error() string

Error implements the error interface

func (*AggregatedError) Unwrap

func (e *AggregatedError) Unwrap() error

Unwrap returns the first error for errors.Is/As compatibility

type AnalyzeResponseJSON

type AnalyzeResponseJSON struct {
	Version     string                  `json:"version"`
	GeneratedAt string                  `json:"generated_at"`
	DurationMs  int64                   `json:"duration_ms"`
	Complexity  *ComplexityResponseJSON `json:"complexity,omitempty"`
	DeadCode    *DeadCodeResponseJSON   `json:"dead_code,omitempty"`
	Clone       *CloneResponseJSON      `json:"clone,omitempty"`
	CBO         *CBOResponseJSON        `json:"cbo,omitempty"`
	Deps        *DepsResponseJSON       `json:"deps,omitempty"`
	Summary     *domain.AnalyzeSummary  `json:"summary,omitempty"`
}

AnalyzeResponseJSON represents the unified analysis response for JSON output

type CBOResponseJSON added in v0.2.0

type CBOResponseJSON struct {
	Version     string                 `json:"version"`
	GeneratedAt string                 `json:"generated_at"`
	DurationMs  int64                  `json:"duration_ms,omitempty"`
	Classes     []domain.ClassCoupling `json:"classes"`
	Summary     domain.CBOSummary      `json:"summary"`
	Warnings    []string               `json:"warnings,omitempty"`
	Errors      []string               `json:"errors,omitempty"`
	Config      interface{}            `json:"config,omitempty"`
}

CBOResponseJSON wraps CBOResponse with JSON metadata

type CBOServiceImpl

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

CBOServiceImpl implements the CBOService interface

func NewCBOService

func NewCBOService(lowThreshold, mediumThreshold int, includeBuiltins, includeTypeImports bool) *CBOServiceImpl

NewCBOService creates a new CBO service implementation

func NewCBOServiceWithDefaults

func NewCBOServiceWithDefaults() *CBOServiceImpl

NewCBOServiceWithDefaults creates a new CBO service with default configuration

func (*CBOServiceImpl) Analyze

Analyze performs CBO analysis on multiple files

func (*CBOServiceImpl) AnalyzeFile

func (s *CBOServiceImpl) AnalyzeFile(ctx context.Context, filePath string, req domain.CBORequest) (*domain.CBOResponse, error)

AnalyzeFile analyzes a single JavaScript/TypeScript file

type CloneResponseJSON added in v0.2.0

type CloneResponseJSON struct {
	Version     string                  `json:"version"`
	GeneratedAt string                  `json:"generated_at"`
	DurationMs  int64                   `json:"duration_ms,omitempty"`
	ClonePairs  []*domain.ClonePair     `json:"clone_pairs"`
	CloneGroups []*domain.CloneGroup    `json:"clone_groups"`
	Statistics  *domain.CloneStatistics `json:"statistics"`
	Success     bool                    `json:"success"`
	Error       string                  `json:"error,omitempty"`
	Config      interface{}             `json:"config,omitempty"`
}

CloneResponseJSON wraps CloneResponse with JSON metadata

type CloneServiceImpl added in v0.2.0

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

CloneServiceImpl implements the domain.CloneService interface

func NewCloneService added in v0.2.0

func NewCloneService(config *analyzer.CloneDetectorConfig) *CloneServiceImpl

NewCloneService creates a new clone detection service

func NewCloneServiceWithDefaults added in v0.2.0

func NewCloneServiceWithDefaults() *CloneServiceImpl

NewCloneServiceWithDefaults creates a service with default configuration

func (*CloneServiceImpl) ComputeSimilarity added in v0.2.0

func (s *CloneServiceImpl) ComputeSimilarity(ctx context.Context, fragment1, fragment2 string) (float64, error)

ComputeSimilarity computes similarity between two code fragments

func (*CloneServiceImpl) DetectClones added in v0.2.0

DetectClones performs clone detection on the given request

func (*CloneServiceImpl) DetectClonesInFiles added in v0.2.0

func (s *CloneServiceImpl) DetectClonesInFiles(ctx context.Context, filePaths []string, req *domain.CloneRequest) (*domain.CloneResponse, error)

DetectClonesInFiles performs clone detection on specific files

func (*CloneServiceImpl) GetVersion added in v0.2.0

func (s *CloneServiceImpl) GetVersion() string

GetVersion returns the current version for response metadata

type ComplexityResponseJSON

type ComplexityResponseJSON struct {
	Version     string                      `json:"version"`
	GeneratedAt string                      `json:"generated_at"`
	DurationMs  int64                       `json:"duration_ms,omitempty"`
	Functions   []domain.FunctionComplexity `json:"functions"`
	Summary     domain.ComplexitySummary    `json:"summary"`
	Warnings    []string                    `json:"warnings,omitempty"`
	Errors      []string                    `json:"errors,omitempty"`
	Config      interface{}                 `json:"config,omitempty"`
}

ComplexityResponseJSON wraps ComplexityResponse with JSON metadata

type ComplexityServiceImpl

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

ComplexityServiceImpl implements the ComplexityService interface

func NewComplexityService

func NewComplexityService(cfg *config.ComplexityConfig) *ComplexityServiceImpl

NewComplexityService creates a new complexity service implementation

func NewComplexityServiceWithProgress

func NewComplexityServiceWithProgress(cfg *config.ComplexityConfig, pm domain.ProgressManager) *ComplexityServiceImpl

NewComplexityServiceWithProgress creates a new complexity service with progress reporting

func (*ComplexityServiceImpl) Analyze

Analyze performs complexity analysis on multiple files

func (*ComplexityServiceImpl) AnalyzeFile

AnalyzeFile analyzes a single JavaScript/TypeScript file

type ConfigurationLoaderImpl

type ConfigurationLoaderImpl struct{}

ConfigurationLoaderImpl implements the ConfigurationLoader interface

func NewConfigurationLoader

func NewConfigurationLoader() *ConfigurationLoaderImpl

NewConfigurationLoader creates a new configuration loader service

func (*ConfigurationLoaderImpl) FindDefaultConfigFile

func (c *ConfigurationLoaderImpl) FindDefaultConfigFile() string

FindDefaultConfigFile searches for a default configuration file

func (*ConfigurationLoaderImpl) LoadConfig

LoadConfig loads configuration from the specified path

func (*ConfigurationLoaderImpl) LoadDefaultConfig

func (c *ConfigurationLoaderImpl) LoadDefaultConfig() *domain.ComplexityRequest

LoadDefaultConfig loads the default configuration, first checking for jscan.config.json

func (*ConfigurationLoaderImpl) MergeConfig

MergeConfig merges CLI flags with configuration file

func (*ConfigurationLoaderImpl) ValidateConfig

func (c *ConfigurationLoaderImpl) ValidateConfig(req *domain.ComplexityRequest) error

ValidateConfig validates the configuration

type DOTFormatter

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

DOTFormatter formats dependency graphs as DOT for Graphviz

func NewDOTFormatter

func NewDOTFormatter(config *DOTFormatterConfig) *DOTFormatter

NewDOTFormatter creates a new DOT formatter with the given configuration

func (*DOTFormatter) FormatDependencyGraph

func (f *DOTFormatter) FormatDependencyGraph(response *domain.DependencyGraphResponse) (string, error)

FormatDependencyGraph formats a dependency graph as DOT and returns the string

func (*DOTFormatter) WriteDependencyGraph

func (f *DOTFormatter) WriteDependencyGraph(response *domain.DependencyGraphResponse, writer io.Writer) error

WriteDependencyGraph writes a dependency graph as DOT to the writer

type DOTFormatterConfig

type DOTFormatterConfig struct {
	// ClusterCycles groups cycles in subgraphs
	ClusterCycles bool

	// ShowLegend includes a legend subgraph
	ShowLegend bool

	// MaxDepth filters by depth (0 = unlimited)
	MaxDepth int

	// MinCoupling filters by minimum coupling level
	MinCoupling int

	// RankDir is the layout direction: TB, LR, BT, RL
	RankDir string
}

DOTFormatterConfig configures the DOT formatter behavior

func DefaultDOTFormatterConfig

func DefaultDOTFormatterConfig() *DOTFormatterConfig

DefaultDOTFormatterConfig returns a DOTFormatterConfig with sensible defaults

type DeadCodeResponseJSON

type DeadCodeResponseJSON struct {
	Version     string                 `json:"version"`
	GeneratedAt string                 `json:"generated_at"`
	DurationMs  int64                  `json:"duration_ms,omitempty"`
	Files       []domain.FileDeadCode  `json:"files"`
	Summary     domain.DeadCodeSummary `json:"summary"`
	Warnings    []string               `json:"warnings,omitempty"`
	Errors      []string               `json:"errors,omitempty"`
	Config      interface{}            `json:"config,omitempty"`
}

DeadCodeResponseJSON wraps DeadCodeResponse with JSON metadata

type DeadCodeServiceImpl

type DeadCodeServiceImpl struct{}

DeadCodeServiceImpl implements the DeadCodeService interface

func NewDeadCodeService

func NewDeadCodeService() *DeadCodeServiceImpl

NewDeadCodeService creates a new dead code service implementation

func (*DeadCodeServiceImpl) Analyze

Analyze performs dead code analysis on multiple files

func (*DeadCodeServiceImpl) AnalyzeFile

func (s *DeadCodeServiceImpl) AnalyzeFile(ctx context.Context, filePath string, req domain.DeadCodeRequest) (*domain.FileDeadCode, error)

AnalyzeFile analyzes a single JavaScript/TypeScript file for dead code

func (*DeadCodeServiceImpl) AnalyzeFunction

func (s *DeadCodeServiceImpl) AnalyzeFunction(ctx context.Context, functionCFG interface{}, req domain.DeadCodeRequest) (*domain.FunctionDeadCode, error)

AnalyzeFunction analyzes a single function for dead code

type DependencyGraphServiceImpl

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

DependencyGraphServiceImpl implements dependency graph analysis

func NewDependencyGraphService

func NewDependencyGraphService(includeExternal, includeTypeImports bool) *DependencyGraphServiceImpl

NewDependencyGraphService creates a new dependency graph service

func NewDependencyGraphServiceWithDefaults

func NewDependencyGraphServiceWithDefaults() *DependencyGraphServiceImpl

NewDependencyGraphServiceWithDefaults creates a new service with default configuration

func (*DependencyGraphServiceImpl) Analyze

Analyze performs complete dependency graph analysis

func (*DependencyGraphServiceImpl) AnalyzeSingleFile

func (s *DependencyGraphServiceImpl) AnalyzeSingleFile(ctx context.Context, filePath string) (*domain.ModuleInfo, error)

AnalyzeSingleFile analyzes a single file and returns its dependency information

type DepsResponseJSON added in v0.2.0

type DepsResponseJSON struct {
	Version     string                           `json:"version"`
	GeneratedAt string                           `json:"generated_at"`
	Graph       *domain.DependencyGraph          `json:"graph,omitempty"`
	Analysis    *domain.DependencyAnalysisResult `json:"analysis,omitempty"`
	Warnings    []string                         `json:"warnings,omitempty"`
	Errors      []string                         `json:"errors,omitempty"`
}

DepsResponseJSON wraps DependencyGraphResponse with JSON metadata

type FormatUtils

type FormatUtils struct{}

FormatUtils provides formatting helper functions

func NewFormatUtils

func NewFormatUtils() *FormatUtils

NewFormatUtils creates a new FormatUtils instance

type HTMLData

type HTMLData struct {
	GeneratedAt   string
	Duration      int64
	Version       string
	Complexity    *domain.ComplexityResponse
	DeadCode      *domain.DeadCodeResponse
	Clone         *domain.CloneResponse
	CBO           *domain.CBOResponse
	Deps          *domain.DependencyGraphResponse
	Summary       *domain.AnalyzeSummary
	HasComplexity bool
	HasDeadCode   bool
	HasClone      bool
	HasCBO        bool
	HasDeps       bool
}

HTMLData represents the data for HTML template

type NoOpProgressManager

type NoOpProgressManager struct{}

NoOpProgressManager implements ProgressManager with no-op methods

func (*NoOpProgressManager) Close

func (pm *NoOpProgressManager) Close()

Close is a no-op

func (*NoOpProgressManager) IsInteractive

func (pm *NoOpProgressManager) IsInteractive() bool

IsInteractive returns false for no-op manager

func (*NoOpProgressManager) StartTask

func (pm *NoOpProgressManager) StartTask(_ string, _ int) domain.TaskProgress

StartTask returns a no-op task progress

type NoOpTaskProgress

type NoOpTaskProgress struct{}

NoOpTaskProgress implements TaskProgress with no-op methods

func (*NoOpTaskProgress) Complete

func (tp *NoOpTaskProgress) Complete()

Complete is a no-op

func (*NoOpTaskProgress) Describe

func (tp *NoOpTaskProgress) Describe(_ string)

Describe is a no-op

func (*NoOpTaskProgress) Increment

func (tp *NoOpTaskProgress) Increment(_ int)

Increment is a no-op

type OutputFormatterImpl

type OutputFormatterImpl struct{}

OutputFormatterImpl implements the OutputFormatter interface

func NewOutputFormatter

func NewOutputFormatter() *OutputFormatterImpl

NewOutputFormatter creates a new output formatter

func (*OutputFormatterImpl) Write

func (f *OutputFormatterImpl) Write(response *domain.ComplexityResponse, format domain.OutputFormat, writer io.Writer) error

Write writes the complexity response in the specified format

func (*OutputFormatterImpl) WriteAnalyze

func (f *OutputFormatterImpl) WriteAnalyze(
	complexityResponse *domain.ComplexityResponse,
	deadCodeResponse *domain.DeadCodeResponse,
	cloneResponse *domain.CloneResponse,
	cboResponse *domain.CBOResponse,
	depsResponse *domain.DependencyGraphResponse,
	format domain.OutputFormat,
	writer io.Writer,
	duration time.Duration,
) error

WriteAnalyze writes the unified analysis response in the specified format

func (*OutputFormatterImpl) WriteDeadCode

func (f *OutputFormatterImpl) WriteDeadCode(response *domain.DeadCodeResponse, format domain.OutputFormat, writer io.Writer) error

WriteDeadCode writes the dead code response in the specified format

func (*OutputFormatterImpl) WriteDependencyGraph

func (f *OutputFormatterImpl) WriteDependencyGraph(response *domain.DependencyGraphResponse, format domain.OutputFormat, writer io.Writer) error

WriteDependencyGraph writes the dependency graph response in the specified format

func (*OutputFormatterImpl) WriteHTML

func (f *OutputFormatterImpl) WriteHTML(
	complexityResponse *domain.ComplexityResponse,
	deadCodeResponse *domain.DeadCodeResponse,
	cloneResponse *domain.CloneResponse,
	cboResponse *domain.CBOResponse,
	depsResponse *domain.DependencyGraphResponse,
	writer io.Writer,
	duration time.Duration,
) error

WriteHTML writes the analysis result as HTML

type ParallelExecutorImpl

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

ParallelExecutorImpl implements domain.ParallelExecutor

func NewParallelExecutor

func NewParallelExecutor() *ParallelExecutorImpl

NewParallelExecutor creates a new parallel executor with defaults Uses runtime.NumCPU() for concurrency and 5 minute timeout

func NewParallelExecutorFromConfig

func NewParallelExecutorFromConfig(cfg *config.PerformanceConfig) *ParallelExecutorImpl

NewParallelExecutorFromConfig creates a parallel executor from configuration

func NewParallelExecutorWithProgress

func NewParallelExecutorWithProgress(cfg *config.PerformanceConfig, pm domain.ProgressManager) *ParallelExecutorImpl

NewParallelExecutorWithProgress creates a parallel executor with progress tracking

func (*ParallelExecutorImpl) Execute

Execute runs tasks in parallel with the configured concurrency and timeout

func (*ParallelExecutorImpl) SetMaxConcurrency

func (e *ParallelExecutorImpl) SetMaxConcurrency(max int)

SetMaxConcurrency sets the maximum number of concurrent tasks

func (*ParallelExecutorImpl) SetTimeout

func (e *ParallelExecutorImpl) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout for all tasks

type ProgressManagerImpl

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

ProgressManagerImpl implements ProgressManager with interactive progress bars

func (*ProgressManagerImpl) Close

func (pm *ProgressManagerImpl) Close()

Close cleans up all tasks

func (*ProgressManagerImpl) IsInteractive

func (pm *ProgressManagerImpl) IsInteractive() bool

IsInteractive returns true if progress bars should be shown

func (*ProgressManagerImpl) StartTask

func (pm *ProgressManagerImpl) StartTask(description string, total int) domain.TaskProgress

StartTask creates a new progress task with a description and total count

type TaskError

type TaskError struct {
	TaskName string
	Err      error
}

TaskError represents a single task failure

func (TaskError) Error

func (e TaskError) Error() string

Error implements the error interface

func (TaskError) Unwrap

func (e TaskError) Unwrap() error

Unwrap returns the underlying error

type TaskProgressImpl

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

TaskProgressImpl implements TaskProgress with a progressbar

func (*TaskProgressImpl) Complete

func (tp *TaskProgressImpl) Complete()

Complete marks the task as finished

func (*TaskProgressImpl) Describe

func (tp *TaskProgressImpl) Describe(description string)

Describe updates the current item description

func (*TaskProgressImpl) Increment

func (tp *TaskProgressImpl) Increment(n int)

Increment adds n to the current progress

Jump to

Keyboard shortcuts

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