From d6d494f3c24121b58c98033dd2c6cb50f3326197 Mon Sep 17 00:00:00 2001 From: baeyc0510 Date: Wed, 12 Nov 2025 14:42:34 +0900 Subject: [PATCH] feat: clean up convert-generated files on init --force MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add automatic removal of linter configuration files generated by convert command when running `sym init --force`. This ensures a clean slate when re-initializing the repository. Changes: - Remove code-policy.json from both .sym/ and current directory - Remove .eslintrc.json from .sym/ - Remove checkstyle.xml from .sym/ - Remove pmd-ruleset.xml from .sym/ - Add removeExistingCodePolicy() function to handle cleanup - Display confirmation messages for each deleted file 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/cmd/init.go | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/internal/cmd/init.go b/internal/cmd/init.go index a41b634..6d0d9da 100644 --- a/internal/cmd/init.go +++ b/internal/cmd/init.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "path/filepath" "github.com/DevSymphony/sym-cli/internal/config" "github.com/DevSymphony/sym-cli/internal/git" "github.com/DevSymphony/sym-cli/internal/github" @@ -82,6 +83,13 @@ func runInit(cmd *cobra.Command, args []string) { os.Exit(1) } + // If force flag is set, remove existing code-policy.json + if initForce { + if err := removeExistingCodePolicy(); err != nil { + fmt.Printf("⚠ Warning: Failed to remove existing code-policy.json: %v\n", err) + } + } + // Create roles with current user as admin newRoles := roles.Roles{ "admin": []string{user.Login}, @@ -165,3 +173,41 @@ func createDefaultPolicy(cfg *config.Config) error { return policy.SavePolicy(defaultPolicy, cfg.PolicyPath) } + +// removeExistingCodePolicy removes all files generated by convert command +// including linter configurations and code-policy.json +func removeExistingCodePolicy() error { + // Files generated by convert command + convertGeneratedFiles := []string{ + "code-policy.json", + ".eslintrc.json", + "checkstyle.xml", + "pmd-ruleset.xml", + } + + // Check and remove from .sym directory + symDir, err := getSymDir() + if err == nil { + for _, filename := range convertGeneratedFiles { + filePath := filepath.Join(symDir, filename) + if _, err := os.Stat(filePath); err == nil { + if err := os.Remove(filePath); err != nil { + fmt.Printf("⚠ Warning: Failed to remove %s: %v\n", filePath, err) + } else { + fmt.Printf("✓ Removed existing %s\n", filePath) + } + } + } + } + + // Check and remove from current directory (legacy mode for code-policy.json) + legacyPath := "code-policy.json" + if _, err := os.Stat(legacyPath); err == nil { + if err := os.Remove(legacyPath); err != nil { + return fmt.Errorf("failed to remove %s: %w", legacyPath, err) + } + fmt.Printf("✓ Removed existing %s\n", legacyPath) + } + + return nil +}