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
7 changes: 2 additions & 5 deletions pkg/cli/remove_command.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
"bufio"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -391,9 +390,7 @@ func findIncludesInContent(content, baseDir string, verbose bool) ([]string, err
_ = verbose // unused parameter for now, keeping for potential future use
var includes []string

scanner := bufio.NewScanner(strings.NewReader(content))
for scanner.Scan() {
line := scanner.Text()
for line := range strings.Lines(content) {
directive := parser.ParseImportDirective(line)
if directive != nil {
includePath := directive.Path
Expand All @@ -411,5 +408,5 @@ func findIncludesInContent(content, baseDir string, verbose bool) ([]string, err
}
}

return includes, scanner.Err()
return includes, nil // strings.Lines iterates over an in-memory string; no I/O errors can occur.
}
10 changes: 8 additions & 2 deletions pkg/parser/import_directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ type ImportDirectiveMatch struct {
func ParseImportDirective(line string) *ImportDirectiveMatch {
trimmedLine := strings.TrimSpace(line)

// Fast-path: import directives must start with '@' or '{'; skip the regex for all other lines.
if len(trimmedLine) == 0 || (trimmedLine[0] != '@' && trimmedLine[0] != '{') {
return nil
}

// Check if it matches the import pattern at all
matches := IncludeDirectivePattern.FindStringSubmatch(trimmedLine)
if matches == nil {
return nil
}

// Check if it's legacy syntax
isLegacy := LegacyIncludeDirectivePattern.MatchString(trimmedLine)
// Determine legacy vs new syntax from the captured groups of the first match.
// Group 2 (path for @include/@import) is non-empty iff the legacy alternative matched.
isLegacy := matches[2] != ""
importDirectiveLog.Printf("Parsing import directive: legacy=%t, line=%s", isLegacy, trimmedLine)

var isOptional bool
Expand Down
Loading