Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"bytes"
"fmt"
"path/filepath"
"regexp"
"strings"
"unicode"
Expand Down Expand Up @@ -44,7 +45,12 @@ func WhitespaceToSpace(msg string) string {
}

// ShouldIgnoreDirectory will check if directory should be ignored
func ShouldIgnoreDirectory(directoryName string) bool {
func ShouldIgnoreDirectory(directoryPath string) bool {
directoryName := filepath.Base(directoryPath)
// if a current dir is detected e.g with directoryPath being an empty string always process
if directoryName == "." {
return false
}
for _, directory := range defaultIgnoreDirectories {
if directory == directoryName {
return true
Expand Down
76 changes: 76 additions & 0 deletions internal/core/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,79 @@ func TestNormalizePath(t *testing.T) {
t.Errorf("expected = %v, got = %v", expectedOutput, result)
}
}

func TestShouldIgnoreDirectory(t *testing.T) {
tests := []struct {
name string
path string
expected bool
}{
{
name: "empty directory name",
path: "",
expected: false,
},
// Direct directory names
{
name: "direct node_modules",
path: "node_modules",
expected: true,
},
{
name: "direct .git",
path: ".git",
expected: true,
},
// Nested paths with ignored directories
{
name: "nested node_modules",
path: "plugins/foo/node_modules",
expected: true,
},
{
name: "nested .git in worktree",
path: "worktree-a/.git",
expected: true,
},
{
name: "deeply nested node_modules",
path: "project/src/components/node_modules",
expected: true,
},
{
name: "node_modules in path with backslashes",
path: filepath.Join("project", "src", "node_modules"),
expected: true,
},
// Non-ignored directories
{
name: "regular directory",
path: "src",
expected: false,
},
{
name: "nested regular directory",
path: "plugins/foo",
expected: false,
},
{
name: "directory containing node_modules in name",
path: "my_node_modules_backup",
expected: false,
},
{
name: "directory containing .git in name",
path: "my.github",
expected: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := ShouldIgnoreDirectory(tt.path)
if result != tt.expected {
t.Errorf("ShouldIgnoreDirectory(%q) = %v, expected %v", tt.path, result, tt.expected)
}
})
}
}