diff --git a/pkg/cli/remove_command.go b/pkg/cli/remove_command.go index d6a59ac1234..71410c9d12c 100644 --- a/pkg/cli/remove_command.go +++ b/pkg/cli/remove_command.go @@ -1,7 +1,6 @@ package cli import ( - "bufio" "fmt" "os" "path/filepath" @@ -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 @@ -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. } diff --git a/pkg/parser/import_directive.go b/pkg/parser/import_directive.go index 89a0b06c980..c365157e607 100644 --- a/pkg/parser/import_directive.go +++ b/pkg/parser/import_directive.go @@ -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