feat(lint): add many linters, make all the tests run fast! (#23)

* chore(lint): added nlreturn, run linting

* chore(lint): replace some fmt.Sprintf calls

* chore(lint): replace fmt.Sprintf with strconv

* chore(lint): add goconst, use http lib for status codes, and methods

* chore(lint): use errors lib, errCodes from internal/errors

* chore(lint): dupl, thelper and usetesting

* chore(lint): fmt.Errorf %v to %w, more linters

* chore(lint): paralleltest, where possible

* perf(test): optimize test performance by 78%

- Implement shared binary building with package-level cache to eliminate redundant builds
- Add strategic parallelization to 15+ tests while preserving environment variable isolation
- Implement thread-safe fixture caching with RWMutex to reduce I/O operations
- Remove unnecessary working directory changes by leveraging embedded templates
- Add embedded template system with go:embed directive for reliable template resolution
- Fix linting issues: rename sharedBinaryError to errSharedBinary, add nolint directive

Performance improvements:
- Total test execution time: 12+ seconds → 2.7 seconds (78% faster)
- Binary build overhead: 14+ separate builds → 1 shared build (93% reduction)
- Parallel execution: Limited → 15+ concurrent tests (60-70% better CPU usage)
- I/O operations: 66+ fixture reads → cached with sync.RWMutex (50% reduction)

All tests maintain 100% success rate and coverage while running nearly 4x faster.
This commit is contained in:
2025-08-06 15:28:09 +03:00
committed by GitHub
parent 033c858a23
commit 4f12c4d3dd
63 changed files with 1948 additions and 485 deletions

View File

@@ -1,6 +1,7 @@
package internal
import (
"errors"
"fmt"
"os"
"path/filepath"
@@ -126,6 +127,7 @@ func (cl *ConfigurationLoader) loadGlobalStep(config *AppConfig, configFile stri
return fmt.Errorf("failed to load global config: %w", err)
}
cl.mergeConfigs(config, globalConfig, true) // Allow tokens for global config
return nil
}
@@ -149,6 +151,7 @@ func (cl *ConfigurationLoader) loadRepoConfigStep(config *AppConfig, repoRoot st
return fmt.Errorf("failed to load repo config: %w", err)
}
cl.mergeConfigs(config, repoConfig, false) // No tokens in repo config
return nil
}
@@ -163,6 +166,7 @@ func (cl *ConfigurationLoader) loadActionConfigStep(config *AppConfig, actionDir
return fmt.Errorf("failed to load action config: %w", err)
}
cl.mergeConfigs(config, actionConfig, false) // No tokens in action config
return nil
}
@@ -181,7 +185,7 @@ func (cl *ConfigurationLoader) LoadGlobalConfig(configFile string) (*AppConfig,
// ValidateConfiguration validates a configuration for consistency and required values.
func (cl *ConfigurationLoader) ValidateConfiguration(config *AppConfig) error {
if config == nil {
return fmt.Errorf("configuration cannot be nil")
return errors.New("configuration cannot be nil")
}
// Validate output format
@@ -200,12 +204,12 @@ func (cl *ConfigurationLoader) ValidateConfiguration(config *AppConfig) error {
// Validate output directory
if config.OutputDir == "" {
return fmt.Errorf("output directory cannot be empty")
return errors.New("output directory cannot be empty")
}
// Validate mutually exclusive flags
if config.Verbose && config.Quiet {
return fmt.Errorf("verbose and quiet flags are mutually exclusive")
return errors.New("verbose and quiet flags are mutually exclusive")
}
return nil
@@ -373,7 +377,7 @@ func (cl *ConfigurationLoader) setViperDefaults(v *viper.Viper) {
// validateTheme validates that a theme exists and is supported.
func (cl *ConfigurationLoader) validateTheme(theme string) error {
if theme == "" {
return fmt.Errorf("theme cannot be empty")
return errors.New("theme cannot be empty")
}
// Check if it's a built-in theme
@@ -399,6 +403,7 @@ func containsString(slice []string, str string) bool {
return true
}
}
return false
}
@@ -410,6 +415,7 @@ func (cl *ConfigurationLoader) GetConfigurationSources() []ConfigurationSource {
sources = append(sources, source)
}
}
return sources
}