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:
@@ -8,12 +8,10 @@ import (
|
|||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Preserve []string `toml:"preserve"`
|
Preserve []string `toml:"preserve"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Default() *Config {
|
func Default() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Preserve: []string{
|
Preserve: []string{
|
||||||
@@ -32,7 +30,6 @@ func Default() *Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Load() (*Config, string, error) {
|
func Load() (*Config, string, error) {
|
||||||
|
|
||||||
if configPath, found := findProjectConfig(); found {
|
if configPath, found := findProjectConfig(); found {
|
||||||
@@ -43,7 +40,6 @@ func Load() (*Config, string, error) {
|
|||||||
return config, configPath, nil
|
return config, configPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if configPath, found := findGlobalConfig(); found {
|
if configPath, found := findGlobalConfig(); found {
|
||||||
config, err := loadFromFile(configPath)
|
config, err := loadFromFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -52,11 +48,9 @@ func Load() (*Config, string, error) {
|
|||||||
return config, configPath, nil
|
return config, configPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return Default(), "", nil
|
return Default(), "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func findProjectConfig() (string, bool) {
|
func findProjectConfig() (string, bool) {
|
||||||
|
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
@@ -69,7 +63,6 @@ func findProjectConfig() (string, bool) {
|
|||||||
return localConfig, true
|
return localConfig, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if gitRoot := findGitRoot(cwd); gitRoot != "" {
|
if gitRoot := findGitRoot(cwd); gitRoot != "" {
|
||||||
gitConfig := filepath.Join(gitRoot, ".shush.toml")
|
gitConfig := filepath.Join(gitRoot, ".shush.toml")
|
||||||
if fileExists(gitConfig) && gitConfig != localConfig {
|
if fileExists(gitConfig) && gitConfig != localConfig {
|
||||||
@@ -80,7 +73,6 @@ func findProjectConfig() (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func findGlobalConfig() (string, bool) {
|
func findGlobalConfig() (string, bool) {
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -95,7 +87,6 @@ func findGlobalConfig() (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func findGitRoot(startDir string) string {
|
func findGitRoot(startDir string) string {
|
||||||
dir := startDir
|
dir := startDir
|
||||||
for {
|
for {
|
||||||
@@ -106,21 +97,19 @@ func findGitRoot(startDir string) string {
|
|||||||
|
|
||||||
parent := filepath.Dir(dir)
|
parent := filepath.Dir(dir)
|
||||||
if parent == dir {
|
if parent == dir {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
dir = parent
|
dir = parent
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func loadFromFile(path string) (*Config, error) {
|
func loadFromFile(path string) (*Config, error) {
|
||||||
config := &Config{}
|
config := &Config{}
|
||||||
if _, err := toml.DecodeFile(path, config); err != nil {
|
if _, err := toml.DecodeFile(path, config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if len(config.Preserve) == 0 {
|
if len(config.Preserve) == 0 {
|
||||||
config.Preserve = Default().Preserve
|
config.Preserve = Default().Preserve
|
||||||
}
|
}
|
||||||
@@ -128,13 +117,11 @@ func loadFromFile(path string) (*Config, error) {
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func fileExists(path string) bool {
|
func fileExists(path string) bool {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *Config) ShouldPreserveComment(comment string) bool {
|
func (c *Config) ShouldPreserveComment(comment string) bool {
|
||||||
comment = strings.TrimSpace(comment)
|
comment = strings.TrimSpace(comment)
|
||||||
|
|
||||||
@@ -147,23 +134,19 @@ func (c *Config) ShouldPreserveComment(comment string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func matchesPattern(text, pattern string) bool {
|
func matchesPattern(text, pattern string) bool {
|
||||||
|
|
||||||
if strings.Contains(pattern, "*") {
|
if strings.Contains(pattern, "*") {
|
||||||
return matchesWildcard(text, pattern)
|
return matchesWildcard(text, pattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return strings.Contains(text, pattern)
|
return strings.Contains(text, pattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func matchesWildcard(text, pattern string) bool {
|
func matchesWildcard(text, pattern string) bool {
|
||||||
|
|
||||||
parts := strings.Split(pattern, "*")
|
parts := strings.Split(pattern, "*")
|
||||||
|
|
||||||
|
|
||||||
if !strings.HasPrefix(pattern, "*") {
|
if !strings.HasPrefix(pattern, "*") {
|
||||||
if !strings.HasPrefix(text, parts[0]) {
|
if !strings.HasPrefix(text, parts[0]) {
|
||||||
return false
|
return false
|
||||||
@@ -171,10 +154,9 @@ func matchesWildcard(text, pattern string) bool {
|
|||||||
text = text[len(parts[0]):]
|
text = text[len(parts[0]):]
|
||||||
parts = parts[1:]
|
parts = parts[1:]
|
||||||
} else {
|
} else {
|
||||||
parts = parts[1:]
|
parts = parts[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if !strings.HasSuffix(pattern, "*") && len(parts) > 0 {
|
if !strings.HasSuffix(pattern, "*") && len(parts) > 0 {
|
||||||
lastPart := parts[len(parts)-1]
|
lastPart := parts[len(parts)-1]
|
||||||
if !strings.HasSuffix(text, lastPart) {
|
if !strings.HasSuffix(text, lastPart) {
|
||||||
@@ -184,10 +166,9 @@ parts = parts[1:]
|
|||||||
parts = parts[:len(parts)-1]
|
parts = parts[:len(parts)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
if part == "" {
|
if part == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
index := strings.Index(text, part)
|
index := strings.Index(text, part)
|
||||||
@@ -195,14 +176,12 @@ continue
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
text = text[index+len(part):]
|
text = text[index+len(part):]
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func CreateExampleConfig() error {
|
func CreateExampleConfig() error {
|
||||||
content := `# Shush Configuration
|
content := `# Shush Configuration
|
||||||
# Patterns to preserve in comments (supports wildcards with *)
|
# Patterns to preserve in comments (supports wildcards with *)
|
||||||
|
|||||||
@@ -117,7 +117,6 @@ func getLineRangesFromDiff(file string, staged bool) ([]LineRange, error) {
|
|||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
|
||||||
return []LineRange{}, nil
|
return []LineRange{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type HookScope int
|
type HookScope int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -22,26 +16,21 @@ const (
|
|||||||
ScopeProject
|
ScopeProject
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type ClaudeSettings struct {
|
type ClaudeSettings struct {
|
||||||
Hooks map[string][]EventConfig `json:"hooks,omitempty"`
|
Hooks map[string][]EventConfig `json:"hooks,omitempty"`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type EventConfig struct {
|
type EventConfig struct {
|
||||||
Matcher string `json:"matcher"`
|
Matcher string `json:"matcher"`
|
||||||
Hooks []HookEntry `json:"hooks"`
|
Hooks []HookEntry `json:"hooks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type HookEntry struct {
|
type HookEntry struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Command string `json:"command"`
|
Command string `json:"command"`
|
||||||
Timeout int `json:"timeout,omitempty"`
|
Timeout int `json:"timeout,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func GetSettingsPath(scope HookScope) (string, error) {
|
func GetSettingsPath(scope HookScope) (string, error) {
|
||||||
switch scope {
|
switch scope {
|
||||||
case ScopeUser:
|
case ScopeUser:
|
||||||
@@ -61,7 +50,6 @@ func GetSettingsPath(scope HookScope) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func EnsureSettingsDirectory(settingsPath string) error {
|
func EnsureSettingsDirectory(settingsPath string) error {
|
||||||
dir := filepath.Dir(settingsPath)
|
dir := filepath.Dir(settingsPath)
|
||||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||||
@@ -70,7 +58,6 @@ func EnsureSettingsDirectory(settingsPath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func LoadSettings(path string) (*ClaudeSettings, error) {
|
func LoadSettings(path string) (*ClaudeSettings, error) {
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
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)
|
return nil, fmt.Errorf("failed to parse settings file %s: %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if settings.Hooks == nil {
|
if settings.Hooks == nil {
|
||||||
settings.Hooks = make(map[string][]EventConfig)
|
settings.Hooks = make(map[string][]EventConfig)
|
||||||
}
|
}
|
||||||
@@ -96,7 +82,6 @@ func LoadSettings(path string) (*ClaudeSettings, error) {
|
|||||||
return &settings, nil
|
return &settings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func SaveSettings(path string, settings *ClaudeSettings) error {
|
func SaveSettings(path string, settings *ClaudeSettings) error {
|
||||||
if err := EnsureSettingsDirectory(path); err != nil {
|
if err := EnsureSettingsDirectory(path); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -114,7 +99,6 @@ func SaveSettings(path string, settings *ClaudeSettings) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func CreateShushHookEntry() HookEntry {
|
func CreateShushHookEntry() HookEntry {
|
||||||
return HookEntry{
|
return HookEntry{
|
||||||
Type: "command",
|
Type: "command",
|
||||||
@@ -123,7 +107,6 @@ func CreateShushHookEntry() HookEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func CreateShushEventConfig() EventConfig {
|
func CreateShushEventConfig() EventConfig {
|
||||||
return EventConfig{
|
return EventConfig{
|
||||||
Matcher: "Write|Edit|MultiEdit",
|
Matcher: "Write|Edit|MultiEdit",
|
||||||
@@ -131,7 +114,6 @@ func CreateShushEventConfig() EventConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func HasShushHook(settings *ClaudeSettings) bool {
|
func HasShushHook(settings *ClaudeSettings) bool {
|
||||||
if settings.Hooks == nil {
|
if settings.Hooks == nil {
|
||||||
return false
|
return false
|
||||||
@@ -153,7 +135,6 @@ func HasShushHook(settings *ClaudeSettings) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func AddShushHook(settings *ClaudeSettings) error {
|
func AddShushHook(settings *ClaudeSettings) error {
|
||||||
if settings.Hooks == nil {
|
if settings.Hooks == nil {
|
||||||
settings.Hooks = make(map[string][]EventConfig)
|
settings.Hooks = make(map[string][]EventConfig)
|
||||||
@@ -163,7 +144,6 @@ func AddShushHook(settings *ClaudeSettings) error {
|
|||||||
return errors.New("shush hook already installed")
|
return errors.New("shush hook already installed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
postToolUseConfigs, exists := settings.Hooks["PostToolUse"]
|
postToolUseConfigs, exists := settings.Hooks["PostToolUse"]
|
||||||
if !exists {
|
if !exists {
|
||||||
|
|
||||||
@@ -171,7 +151,6 @@ func AddShushHook(settings *ClaudeSettings) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for i, config := range postToolUseConfigs {
|
for i, config := range postToolUseConfigs {
|
||||||
if config.Matcher == "Write|Edit|MultiEdit" || config.Matcher == "" {
|
if config.Matcher == "Write|Edit|MultiEdit" || config.Matcher == "" {
|
||||||
|
|
||||||
@@ -180,12 +159,10 @@ func AddShushHook(settings *ClaudeSettings) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
settings.Hooks["PostToolUse"] = append(postToolUseConfigs, CreateShushEventConfig())
|
settings.Hooks["PostToolUse"] = append(postToolUseConfigs, CreateShushEventConfig())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func RemoveShushHook(settings *ClaudeSettings) error {
|
func RemoveShushHook(settings *ClaudeSettings) error {
|
||||||
if settings.Hooks == nil {
|
if settings.Hooks == nil {
|
||||||
return errors.New("no hooks configuration found")
|
return errors.New("no hooks configuration found")
|
||||||
@@ -213,7 +190,6 @@ func RemoveShushHook(settings *ClaudeSettings) error {
|
|||||||
return errors.New("shush hook not found")
|
return errors.New("shush hook not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
filteredConfigs := make([]EventConfig, 0, len(postToolUseConfigs))
|
filteredConfigs := make([]EventConfig, 0, len(postToolUseConfigs))
|
||||||
for _, config := range postToolUseConfigs {
|
for _, config := range postToolUseConfigs {
|
||||||
if len(config.Hooks) > 0 {
|
if len(config.Hooks) > 0 {
|
||||||
|
|||||||
@@ -117,7 +117,6 @@ func (p *Processor) processFile(filename string) error {
|
|||||||
return p.showPreview(filename, language)
|
return p.showPreview(filename, language)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return p.processFileInMemory(filename, language)
|
return p.processFileInMemory(filename, language)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,8 +193,6 @@ func (p *Processor) processFileInMemory(filename string, language types.Language
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (p *Processor) createBackup(filename string) error {
|
func (p *Processor) createBackup(filename string) error {
|
||||||
backupName := filename + ".bak"
|
backupName := filename + ".bak"
|
||||||
|
|
||||||
|
|||||||
+20
-20
@@ -3,26 +3,26 @@ package types
|
|||||||
import "github.com/alecthomas/kong"
|
import "github.com/alecthomas/kong"
|
||||||
|
|
||||||
type CLI struct {
|
type CLI struct {
|
||||||
Path string `arg:"" name:"path" help:"Source code file or directory to process" optional:""`
|
Path string `arg:"" name:"path" help:"Source code file or directory to process" optional:""`
|
||||||
Inline bool `help:"Remove only line comments"`
|
Inline bool `help:"Remove only line comments"`
|
||||||
Block bool `help:"Remove only block comments"`
|
Block bool `help:"Remove only block comments"`
|
||||||
Recursive bool `short:"r" help:"Process directories recursively"`
|
Recursive bool `short:"r" help:"Process directories recursively"`
|
||||||
DryRun bool `help:"Show what would be removed without making changes"`
|
DryRun bool `help:"Show what would be removed without making changes"`
|
||||||
Backup bool `help:"Create backup files before modification"`
|
Backup bool `help:"Create backup files before modification"`
|
||||||
Verbose bool `help:"Show detailed output"`
|
Verbose bool `help:"Show detailed output"`
|
||||||
PreserveLines bool `help:"Remove comments but preserve empty lines"`
|
PreserveLines bool `help:"Remove comments but preserve empty lines"`
|
||||||
LLM bool `help:"Show LLM-friendly usage guide"`
|
LLM bool `help:"Show LLM-friendly usage guide"`
|
||||||
ChangesOnly bool `help:"Remove comments only from git changes (staged + unstaged + untracked)"`
|
ChangesOnly bool `help:"Remove comments only from git changes (staged + unstaged + untracked)"`
|
||||||
Staged bool `help:"Remove comments only from staged git changes"`
|
Staged bool `help:"Remove comments only from staged git changes"`
|
||||||
Unstaged bool `help:"Remove comments only from unstaged git changes"`
|
Unstaged bool `help:"Remove comments only from unstaged git changes"`
|
||||||
InstallHook bool `help:"Install Claude Code hooks for automatic comment cleanup"`
|
InstallHook bool `help:"Install Claude Code hooks for automatic comment cleanup"`
|
||||||
UninstallHook bool `help:"Uninstall Claude Code hooks"`
|
UninstallHook bool `help:"Uninstall Claude Code hooks"`
|
||||||
ListHooks bool `help:"List current Claude Code hooks configuration"`
|
ListHooks bool `help:"List current Claude Code hooks configuration"`
|
||||||
HookStatus bool `help:"Check if shush hooks are installed"`
|
HookStatus bool `help:"Check if shush hooks are installed"`
|
||||||
HookScope string `short:"s" help:"Hook scope: 'project' for local, default for user-wide"`
|
HookScope string `short:"s" help:"Hook scope: 'project' for local, default for user-wide"`
|
||||||
Config bool `help:"Show current configuration and location"`
|
Config bool `help:"Show current configuration and location"`
|
||||||
CreateConfig bool `help:"Create example .shush.toml configuration file"`
|
CreateConfig bool `help:"Create example .shush.toml configuration file"`
|
||||||
Version kong.VersionFlag `help:"Show version information"`
|
Version kong.VersionFlag `help:"Show version information"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Language struct {
|
type Language struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user