style: apply code formatting and linting fixes

- Remove unnecessary blank lines and improve spacing
- Fix linting warnings (remove redundant nil checks)
- Standardize indentation and formatting
- No functional changes, only style improvements
This commit is contained in:
carraes
2025-07-06 12:01:32 -03:00
parent ea1a50ba33
commit fae70c6b2b
5 changed files with 32 additions and 81 deletions
+3 -24
View File
@@ -8,12 +8,10 @@ import (
"github.com/BurntSushi/toml"
)
type Config struct {
Preserve []string `toml:"preserve"`
}
func Default() *Config {
return &Config{
Preserve: []string{
@@ -32,7 +30,6 @@ func Default() *Config {
}
}
func Load() (*Config, string, error) {
if configPath, found := findProjectConfig(); found {
@@ -43,7 +40,6 @@ func Load() (*Config, string, error) {
return config, configPath, nil
}
if configPath, found := findGlobalConfig(); found {
config, err := loadFromFile(configPath)
if err != nil {
@@ -52,11 +48,9 @@ func Load() (*Config, string, error) {
return config, configPath, nil
}
return Default(), "", nil
}
func findProjectConfig() (string, bool) {
cwd, err := os.Getwd()
@@ -69,7 +63,6 @@ func findProjectConfig() (string, bool) {
return localConfig, true
}
if gitRoot := findGitRoot(cwd); gitRoot != "" {
gitConfig := filepath.Join(gitRoot, ".shush.toml")
if fileExists(gitConfig) && gitConfig != localConfig {
@@ -80,7 +73,6 @@ func findProjectConfig() (string, bool) {
return "", false
}
func findGlobalConfig() (string, bool) {
home, err := os.UserHomeDir()
if err != nil {
@@ -95,7 +87,6 @@ func findGlobalConfig() (string, bool) {
return "", false
}
func findGitRoot(startDir string) string {
dir := startDir
for {
@@ -106,21 +97,19 @@ func findGitRoot(startDir string) string {
parent := filepath.Dir(dir)
if parent == dir {
break
break
}
dir = parent
}
return ""
}
func loadFromFile(path string) (*Config, error) {
config := &Config{}
if _, err := toml.DecodeFile(path, config); err != nil {
return nil, err
}
if len(config.Preserve) == 0 {
config.Preserve = Default().Preserve
}
@@ -128,13 +117,11 @@ func loadFromFile(path string) (*Config, error) {
return config, nil
}
func fileExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func (c *Config) ShouldPreserveComment(comment string) bool {
comment = strings.TrimSpace(comment)
@@ -147,23 +134,19 @@ func (c *Config) ShouldPreserveComment(comment string) bool {
return false
}
func matchesPattern(text, pattern string) bool {
if strings.Contains(pattern, "*") {
return matchesWildcard(text, pattern)
}
return strings.Contains(text, pattern)
}
func matchesWildcard(text, pattern string) bool {
parts := strings.Split(pattern, "*")
if !strings.HasPrefix(pattern, "*") {
if !strings.HasPrefix(text, parts[0]) {
return false
@@ -171,10 +154,9 @@ func matchesWildcard(text, pattern string) bool {
text = text[len(parts[0]):]
parts = parts[1:]
} else {
parts = parts[1:]
parts = parts[1:]
}
if !strings.HasSuffix(pattern, "*") && len(parts) > 0 {
lastPart := parts[len(parts)-1]
if !strings.HasSuffix(text, lastPart) {
@@ -184,10 +166,9 @@ parts = parts[1:]
parts = parts[:len(parts)-1]
}
for _, part := range parts {
if part == "" {
continue
continue
}
index := strings.Index(text, part)
@@ -195,14 +176,12 @@ continue
return false
}
text = text[index+len(part):]
}
return true
}
func CreateExampleConfig() error {
content := `# Shush Configuration
# Patterns to preserve in comments (supports wildcards with *)
-1
View File
@@ -117,7 +117,6 @@ func getLineRangesFromDiff(file string, staged bool) ([]LineRange, error) {
output, err := cmd.Output()
if err != nil {
return []LineRange{}, nil
}
-24
View File
@@ -9,12 +9,6 @@ import (
"strings"
)
type HookScope int
const (
@@ -22,26 +16,21 @@ const (
ScopeProject
)
type ClaudeSettings struct {
Hooks map[string][]EventConfig `json:"hooks,omitempty"`
}
type EventConfig struct {
Matcher string `json:"matcher"`
Hooks []HookEntry `json:"hooks"`
}
type HookEntry struct {
Type string `json:"type"`
Command string `json:"command"`
Timeout int `json:"timeout,omitempty"`
}
func GetSettingsPath(scope HookScope) (string, error) {
switch scope {
case ScopeUser:
@@ -61,7 +50,6 @@ func GetSettingsPath(scope HookScope) (string, error) {
}
}
func EnsureSettingsDirectory(settingsPath string) error {
dir := filepath.Dir(settingsPath)
if err := os.MkdirAll(dir, 0755); err != nil {
@@ -70,7 +58,6 @@ func EnsureSettingsDirectory(settingsPath string) error {
return nil
}
func LoadSettings(path string) (*ClaudeSettings, error) {
data, err := os.ReadFile(path)
if err != nil {
@@ -88,7 +75,6 @@ func LoadSettings(path string) (*ClaudeSettings, error) {
return nil, fmt.Errorf("failed to parse settings file %s: %w", path, err)
}
if settings.Hooks == nil {
settings.Hooks = make(map[string][]EventConfig)
}
@@ -96,7 +82,6 @@ func LoadSettings(path string) (*ClaudeSettings, error) {
return &settings, nil
}
func SaveSettings(path string, settings *ClaudeSettings) error {
if err := EnsureSettingsDirectory(path); err != nil {
return err
@@ -114,7 +99,6 @@ func SaveSettings(path string, settings *ClaudeSettings) error {
return nil
}
func CreateShushHookEntry() HookEntry {
return HookEntry{
Type: "command",
@@ -123,7 +107,6 @@ func CreateShushHookEntry() HookEntry {
}
}
func CreateShushEventConfig() EventConfig {
return EventConfig{
Matcher: "Write|Edit|MultiEdit",
@@ -131,7 +114,6 @@ func CreateShushEventConfig() EventConfig {
}
}
func HasShushHook(settings *ClaudeSettings) bool {
if settings.Hooks == nil {
return false
@@ -153,7 +135,6 @@ func HasShushHook(settings *ClaudeSettings) bool {
return false
}
func AddShushHook(settings *ClaudeSettings) error {
if settings.Hooks == nil {
settings.Hooks = make(map[string][]EventConfig)
@@ -163,7 +144,6 @@ func AddShushHook(settings *ClaudeSettings) error {
return errors.New("shush hook already installed")
}
postToolUseConfigs, exists := settings.Hooks["PostToolUse"]
if !exists {
@@ -171,7 +151,6 @@ func AddShushHook(settings *ClaudeSettings) error {
return nil
}
for i, config := range postToolUseConfigs {
if config.Matcher == "Write|Edit|MultiEdit" || config.Matcher == "" {
@@ -180,12 +159,10 @@ func AddShushHook(settings *ClaudeSettings) error {
}
}
settings.Hooks["PostToolUse"] = append(postToolUseConfigs, CreateShushEventConfig())
return nil
}
func RemoveShushHook(settings *ClaudeSettings) error {
if settings.Hooks == nil {
return errors.New("no hooks configuration found")
@@ -213,7 +190,6 @@ func RemoveShushHook(settings *ClaudeSettings) error {
return errors.New("shush hook not found")
}
filteredConfigs := make([]EventConfig, 0, len(postToolUseConfigs))
for _, config := range postToolUseConfigs {
if len(config.Hooks) > 0 {
-3
View File
@@ -117,7 +117,6 @@ func (p *Processor) processFile(filename string) error {
return p.showPreview(filename, language)
}
return p.processFileInMemory(filename, language)
}
@@ -194,8 +193,6 @@ func (p *Processor) processFileInMemory(filename string, language types.Language
return nil
}
func (p *Processor) createBackup(filename string) error {
backupName := filename + ".bak"