diff --git a/filefusion.xml b/filefusion.xml deleted file mode 100644 index 8922a9d..0000000 --- a/filefusion.xml +++ /dev/null @@ -1,6320 +0,0 @@ - - - -filefusion/internal/core/cleaner/handlers/bash_handler.go -package handlers -import ( - "strings" - sitter "github.com/smacker/go-tree-sitter" -) -type BashHandler struct { - BaseHandler -} -func (h *BashHandler) GetCommentTypes() []string { - return []string{"comment"} -} -func (h *BashHandler) GetImportTypes() []string { - return []string{"source_command", "command"} -} -func (h *BashHandler) GetDocCommentPrefix() string { - return "#" -} -func (h *BashHandler) IsLoggingCall(node *sitter.Node, content []byte) bool { - if node == nil { - return false - } - nodeType := node.Type() - if nodeType == "redirected_statement" { - return true - } - if nodeType != "command" { - return false - } - if node.StartByte() >= uint32(len(content)) || node.EndByte() > uint32(len(content)) { - return false - } - cmdText := string(content[node.StartByte():node.EndByte()]) - return strings.Contains(cmdText, "logger") || - strings.Contains(cmdText, "echo \"Debug") || - strings.Contains(cmdText, "printf \"Debug") -} -func (h *BashHandler) IsGetterSetter(node *sitter.Node, content []byte) bool { - return false -} - - - -filefusion/internal/core/cleaner/handlers/base_handler.go -package handlers -import ( - "strings" - sitter "github.com/smacker/go-tree-sitter" -) -type LanguageHandler interface { - GetCommentTypes() []string - GetImportTypes() []string - GetDocCommentPrefix() string - IsLoggingCall(node *sitter.Node, content []byte) bool - IsGetterSetter(node *sitter.Node, content []byte) bool -} -type BaseHandler struct{} -func (h *BaseHandler) IsMethodNamed(node *sitter.Node, content []byte, prefix string) bool { - if node.Type() != "method_declaration" && - node.Type() != "function_declaration" && - node.Type() != "getter_declaration" && - node.Type() != "method_definition" { - return false - } - nameNode := node.ChildByFieldName("name") - if nameNode == nil { - return false - } - name := string(content[nameNode.StartByte():nameNode.EndByte()]) - return strings.HasPrefix(strings.ToLower(name), strings.ToLower(prefix)) -} -func stringSliceEqual(a, b []string) bool { - if len(a) != len(b) { - return false - } - for i, v := range a { - if v != b[i] { - return false - } - } - return true -} - - - -filefusion/internal/core/cleaner/handlers/base_handler_test.go -package handlers -import ( - "testing" - sitter "github.com/smacker/go-tree-sitter" - "github.com/smacker/go-tree-sitter/golang" -) -func TestBaseHandler(t *testing.T) { - handler := &BaseHandler{} - parser := sitter.NewParser() - parser.SetLanguage(golang.GetLanguage()) - tests := []struct { - name string - input string - prefix string - expected bool - }{ - { - name: "get method", - input: "package main\nfunc GetName() string { return name }", - prefix: "Get", - expected: true, - }, - { - name: "set method", - input: "package main\nfunc SetName(name string) { this.name = name }", - prefix: "Set", - expected: true, - }, - { - name: "non-matching method", - input: "package main\nfunc Process() error { return nil }", - prefix: "Get", - expected: false, - }, - { - name: "case insensitive match", - input: "package main\nfunc getName() string { return name }", - prefix: "Get", - expected: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tree := parser.Parse(nil, []byte(tt.input)) - if tree == nil { - t.Fatal("Failed to parse input") - } - defer tree.Close() - var funcNode *sitter.Node - cursor := sitter.NewTreeCursor(tree.RootNode()) - defer cursor.Close() - ok := cursor.GoToFirstChild() - for ok { - if cursor.CurrentNode().Type() == "function_declaration" { - funcNode = cursor.CurrentNode() - break - } - ok = cursor.GoToNextSibling() - } - if funcNode == nil { - t.Fatal("No function declaration found") - } - if got := handler.IsMethodNamed(funcNode, []byte(tt.input), tt.prefix); got != tt.expected { - t.Errorf("IsMethodNamed() = %v, want %v", got, tt.expected) - } - }) - } -} - - - -filefusion/internal/core/cleaner/handlers/css_handler.go -package handlers -import ( - sitter "github.com/smacker/go-tree-sitter" -) -type CSSHandler struct { - BaseHandler -} -func (h *CSSHandler) GetCommentTypes() []string { - return []string{"comment"} -} -func (h *CSSHandler) GetImportTypes() []string { - return []string{"import_statement", "@import"} -} -func (h *CSSHandler) GetDocCommentPrefix() string { - return "/*" -} -func (h *CSSHandler) IsLoggingCall(node *sitter.Node, content []byte) bool { - return false -} -func (h *CSSHandler) IsGetterSetter(node *sitter.Node, content []byte) bool { - return false -} - - - -filefusion/internal/core/cleaner/handlers/cpp_handler.go -package handlers -import ( - "bytes" - "strings" - sitter "github.com/smacker/go-tree-sitter" -) -type CPPHandler struct { - BaseHandler -} -func (h *CPPHandler) GetCommentTypes() []string { - return []string{"comment", "multiline_comment"} -} -func (h *CPPHandler) GetImportTypes() []string { - return []string{"preproc_include", "using_declaration"} -} -func (h *CPPHandler) GetDocCommentPrefix() string { - return "///" -} -func (h *CPPHandler) IsLoggingCall(node *sitter.Node, content []byte) bool { - if node == nil || (node.Type() != "call_expression" && node.Type() != "binary_expression") { - return false - } - if node.StartByte() >= uint32(len(content)) || node.EndByte() > uint32(len(content)) { - return false - } - callText := content[node.StartByte():node.EndByte()] - return bytes.Contains(callText, []byte("cout")) || - bytes.Contains(callText, []byte("cerr")) || - bytes.Contains(callText, []byte("clog")) || - bytes.Contains(callText, []byte("printf")) || - bytes.Contains(callText, []byte("fprintf")) || - bytes.Contains(callText, []byte("log")) -} -func (h *CPPHandler) IsGetterSetter(node *sitter.Node, content []byte) bool { - if node == nil || (node.Type() != "function_definition" && node.Type() != "function_declarator") { - return false - } - if node.StartByte() >= uint32(len(content)) || node.EndByte() > uint32(len(content)) { - return false - } - funcText := string(content[node.StartByte():node.EndByte()]) - isGetter := (strings.Contains(strings.ToLower(funcText), "get") && !strings.Contains(strings.ToLower(funcText), "getvalue")) || - (strings.Contains(strings.ToLower(funcText), "is") && !strings.Contains(strings.ToLower(funcText), "isvalue")) - isSetter := strings.Contains(funcText, "set") || - strings.Contains(funcText, "Set") - if isGetter { - return !strings.Contains(funcText, "void") && - strings.Count(funcText, ",") == 0 - } - if isSetter { - return strings.Contains(funcText, "void") && - strings.Count(funcText, ",") <= 1 - } - return false -} - - - -filefusion/internal/core/cleaner/handlers/css_handler_test.go -package handlers -import ( - "testing" - sitter "github.com/smacker/go-tree-sitter" - "github.com/smacker/go-tree-sitter/css" -) -func TestCSSHandlerBasics(t *testing.T) { - handler := &CSSHandler{} - commentTypes := handler.GetCommentTypes() - expected := []string{"comment"} - if !stringSliceEqual(commentTypes, expected) { - t.Errorf("Expected %v, got %v", expected, commentTypes) - } - importTypes := handler.GetImportTypes() - expected = []string{"import_statement", "@import"} - if !stringSliceEqual(importTypes, expected) { - t.Errorf("Expected %v, got %v", expected, importTypes) - } - if prefix := handler.GetDocCommentPrefix(); prefix != "/*" { - t.Errorf("Expected '/*', got %s", prefix) - } -} -func TestCSSLoggingCalls(t *testing.T) { - handler := &CSSHandler{} - parser := sitter.NewParser() - parser.SetLanguage(css.GetLanguage()) - tests := []struct { - name string - input string - expected bool - }{ - { - name: "regular rule", - input: ".class { color: red; }", - expected: false, - }, - { - name: "import statement", - input: "@import 'styles.css';", - expected: false, - }, - { - name: "media query", - input: "@media screen { body { color: blue; } }", - expected: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tree := parser.Parse(nil, []byte(tt.input)) - if tree == nil { - t.Fatal("Failed to parse input") - } - defer tree.Close() - node := tree.RootNode() - result := handler.IsLoggingCall(node, []byte(tt.input)) - if result != tt.expected { - t.Errorf("Expected IsLoggingCall() = %v for input %q", tt.expected, tt.input) - } - }) - } - if handler.IsLoggingCall(nil, []byte("")) { - t.Error("Expected IsLoggingCall to return false for nil node") - } -} -func TestCSSGetterSetter(t *testing.T) { - handler := &CSSHandler{} - parser := sitter.NewParser() - parser.SetLanguage(css.GetLanguage()) - tests := []struct { - name string - input string - expected bool - }{ - { - name: "regular rule", - input: ".class { color: red; }", - expected: false, - }, - { - name: "pseudo class", - input: ".class:hover { color: blue; }", - expected: false, - }, - { - name: "variable declaration", - input: ":root { --main-color: blue; }", - expected: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tree := parser.Parse(nil, []byte(tt.input)) - if tree == nil { - t.Fatal("Failed to parse input") - } - defer tree.Close() - node := tree.RootNode() - result := handler.IsGetterSetter(node, []byte(tt.input)) - if result != tt.expected { - t.Errorf("Expected IsGetterSetter() = %v for input %q", tt.expected, tt.input) - } - }) - } - if handler.IsGetterSetter(nil, []byte("")) { - t.Error("Expected IsGetterSetter to return false for nil node") - } -} - - - -filefusion/internal/core/cleaner/handlers/go_handler.go -package handlers -import ( - "bytes" - "strings" - sitter "github.com/smacker/go-tree-sitter" -) -type GoHandler struct { - BaseHandler -} -func (h *GoHandler) GetCommentTypes() []string { - return []string{"comment"} -} -func (h *GoHandler) GetImportTypes() []string { - return []string{"import_declaration", "import_spec"} -} -func (h *GoHandler) GetDocCommentPrefix() string { - return "///" -} -func (h *GoHandler) IsLoggingCall(node *sitter.Node, content []byte) bool { - if node.Type() != "call_expression" { - return false - } - callText := content[node.StartByte():node.EndByte()] - return || - || - || -} -func (h *GoHandler) IsGetterSetter(node *sitter.Node, content []byte) bool { - if node.Type() != "function_declaration" { - return false - } - nameNode := node.ChildByFieldName("name") - if nameNode == nil { - return false - } - name := string(content[nameNode.StartByte():nameNode.EndByte()]) - return strings.HasPrefix(strings.ToLower(name), "get") || - strings.HasPrefix(strings.ToLower(name), "set") -} - - - -filefusion/internal/core/cleaner/handlers/bash_handler_test.go -package handlers -import ( - "strings" - "testing" - sitter "github.com/smacker/go-tree-sitter" - "github.com/smacker/go-tree-sitter/bash" -) -func TestBashHandlerBasics(t *testing.T) { - handler := &BashHandler{} - commentTypes := handler.GetCommentTypes() - if len(commentTypes) != 1 || commentTypes[0] != "comment" { - t.Errorf("Expected ['comment'], got %v", commentTypes) - } - importTypes := handler.GetImportTypes() - if len(importTypes) != 2 || importTypes[0] != "source_command" || importTypes[1] != "command" { - t.Errorf("Expected ['source_command', 'command'], got %v", importTypes) - } - if prefix := handler.GetDocCommentPrefix(); prefix != "#" { - t.Errorf("Expected '#', got %s", prefix) - } -} -func TestBashLoggingCalls(t *testing.T) { - handler := &BashHandler{} - parser := sitter.NewParser() - parser.SetLanguage(bash.GetLanguage()) - tests := []struct { - name string - input string - expected bool - }{ - { - name: "stderr redirection", - input: "echo 'Error' >&2", - expected: true, - }, - { - name: "logger command", - input: "logger 'System startup complete'", - expected: true, - }, - { - name: "debug echo", - input: "echo \"Debug: process started\"", - expected: true, - }, - { - name: "debug printf", - input: "printf \"Debug: %s\\n\" \"$var\"", - expected: true, - }, - { - name: "regular echo", - input: "echo 'Hello world'", - expected: false, - }, - { - name: "regular command", - input: "ls -l", - expected: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tree := parser.Parse(nil, []byte(tt.input)) - if tree == nil { - t.Fatal("Failed to parse input") - } - defer tree.Close() - node := tree.RootNode() - if node == nil { - t.Fatal("Failed to get root node") - } - var printNode func(*sitter.Node, int) - printNode = func(n *sitter.Node, depth int) { - if n == nil { - return - } - indent := strings.Repeat(" ", depth) - content := "" - if n.StartByte() < uint32(len(tt.input)) && n.EndByte() <= uint32(len(tt.input)) { - content = string([]byte(tt.input)[n.StartByte():n.EndByte()]) - } - t.Logf("%sNode type: %s, Content: %q", indent, n.Type(), content) - for i := 0; i < int(n.ChildCount()); i++ { - printNode(n.Child(i), depth+1) - } - } - printNode(node, 0) - var cmdNode *sitter.Node - var findCommand func(*sitter.Node) - findCommand = func(n *sitter.Node) { - if n.Type() == "command" || n.Type() == "redirected_statement" { - cmdNode = n - return - } - for i := 0; i < int(n.NamedChildCount()); i++ { - findCommand(n.NamedChild(i)) - } - } - findCommand(node) - if cmdNode == nil { - t.Fatal("No command node found") - } - result := handler.IsLoggingCall(cmdNode, []byte(tt.input)) - if result != tt.expected { - t.Errorf("Expected IsLoggingCall() = %v for input %q", tt.expected, tt.input) - } - }) - } -} -func TestBashGetterSetter(t *testing.T) { - handler := &BashHandler{} - parser := sitter.NewParser() - parser.SetLanguage(bash.GetLanguage()) - input := `function get_value() { echo "$value"; }` - tree := parser.Parse(nil, []byte(input)) - defer tree.Close() - node := tree.RootNode() - if handler.IsGetterSetter(node, []byte(input)) { - t.Error("Expected IsGetterSetter to always return false for Bash") - } -} - - - -filefusion/internal/core/cleaner/handlers/csharp_handler.go -package handlers -import ( - "bytes" - "fmt" - "strings" - sitter "github.com/smacker/go-tree-sitter" -) -type CSharpHandler struct { - BaseHandler -} -func (h *CSharpHandler) GetCommentTypes() []string { - return []string{"comment", "multiline_comment"} -} -func (h *CSharpHandler) GetImportTypes() []string { - return []string{"using_directive"} -} -func (h *CSharpHandler) GetDocCommentPrefix() string { - return "///" -} -func (h *CSharpHandler) IsLoggingCall(node *sitter.Node, content []byte) bool { - if node == nil { - return false - } - if node.Type() != "invocation_expression" { - return false - } - memberAccess := node.Child(0) - if memberAccess == nil { - return false - } - if memberAccess.Type() != "member_access_expression" { - return false - } - callText := content[memberAccess.StartByte():memberAccess.EndByte()] - return bytes.Contains(callText, []byte("Console.")) || - bytes.Contains(callText, []byte("Debug.")) || - bytes.Contains(callText, []byte("Logger.")) || - bytes.Contains(callText, []byte("Trace.")) -} -func (h *CSharpHandler) IsGetterSetter(node *sitter.Node, content []byte) bool { - if node == nil { - return false - } - switch node.Type() { - case "property_declaration": - accessorList := node.ChildByFieldName("accessors") - if accessorList != nil { - hasGetter := false - hasSetter := false - for i := 0; i < int(accessorList.ChildCount()); i++ { - accessor := accessorList.Child(i) - if accessor.Type() != "accessor_declaration" { - continue - } - text := string(content[accessor.StartByte():accessor.EndByte()]) - if strings.Contains(text, "get") { - hasGetter = true - } - if strings.Contains(text, "set") { - hasSetter = true - } - } - return hasGetter || hasSetter - } - return false - case "method_declaration": - nameNode := node.ChildByFieldName("name") - bodyNode := node.ChildByFieldName("body") - if nameNode != nil && bodyNode != nil { - name := string(content[nameNode.StartByte():nameNode.EndByte()]) - bodyText := string(content[bodyNode.StartByte():bodyNode.EndByte()]) - if strings.HasPrefix(name, "Get") && strings.Contains(bodyText, "return") { - return true - } - if strings.HasPrefix(name, "Set") && strings.Contains(bodyText, "=") { - return true - } - } - return false - default: - return false - } -} -func hasAccessor(block *sitter.Node, content []byte) bool { - hasGetter := false - hasSetter := false - for i := 0; i < int(block.ChildCount()); i++ { - child := block.Child(i) - if child.Type() == "ERROR" { - text := string(content[child.StartByte():child.EndByte()]) - if text == "get" { - hasGetter = true - } else if text == "set" { - hasSetter = true - } - } - } - return hasGetter || hasSetter -} -func findNextSibling(node *sitter.Node, nodeType string) *sitter.Node { - if node == nil || node.Parent() == nil { - return nil - } - parent := node.Parent() - for i := 0; i < int(parent.ChildCount()); i++ { - child := parent.Child(i) - if child == node { - for j := i + 1; j < int(parent.ChildCount()); j++ { - sibling := parent.Child(j) - if sibling.Type() == nodeType { - return sibling - } - } - break - } - } - return nil -} - - - -filefusion/internal/core/cleaner/handlers/html_handler.go -package handlers -import ( - sitter "github.com/smacker/go-tree-sitter" -) -type HTMLHandler struct { - BaseHandler -} -func (h *HTMLHandler) GetCommentTypes() []string { - return []string{"comment"} -} -func (h *HTMLHandler) GetImportTypes() []string { - return []string{"link_element", "script_element"} -} -func (h *HTMLHandler) GetDocCommentPrefix() string { - return "