scanner

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package scanner provides file system scanning capabilities for brfit.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHidden

func IsHidden(name string) bool

IsHidden checks if a file or directory name is hidden (starts with dot).

Example
package main

import (
	"fmt"

	"github.com/indigo-net/Brf.it/pkg/scanner"
)

func main() {
	fmt.Println(scanner.IsHidden(".gitignore"))
	fmt.Println(scanner.IsHidden("main.go"))
}
Output:
true
false

Types

type FileEntry

type FileEntry struct {
	// Path is the absolute or relative path to the file.
	Path string

	// Language is the detected programming language (e.g., "go", "typescript").
	Language string

	// Size is the file size in bytes.
	Size int64

	// Content holds the file bytes when PreloadContent is enabled.
	// nil when content was not preloaded.
	Content []byte
}

FileEntry represents a single file discovered during scanning.

type FileScanner

type FileScanner struct {
	// contains filtered or unexported fields
}

FileScanner implements Scanner for file system traversal.

func NewFileScanner

func NewFileScanner(opts *ScanOptions) (*FileScanner, error)

NewFileScanner creates a new FileScanner with the given options. If opts is nil, default options are used.

func (*FileScanner) Scan

func (s *FileScanner) Scan(ctx context.Context) (*ScanResult, error)

Scan implements the Scanner interface. It recursively traverses the directory tree and returns matching files.

type ScanOptions

type ScanOptions struct {
	// RootPath is the directory or file to scan.
	RootPath string

	// SupportedExtensions maps file extensions to language names.
	SupportedExtensions map[string]string

	// IgnoreFiles is the list of ignore file paths (default: [".gitignore"]).
	IgnoreFiles []string

	// IncludePatterns is a list of glob patterns to include.
	// If non-empty, only files matching at least one pattern are included.
	// Supports doublestar (**) patterns.
	IncludePatterns []string

	// ExcludePatterns is a list of glob patterns to exclude.
	// Files matching any pattern are excluded.
	// Supports doublestar (**) patterns.
	ExcludePatterns []string

	// ChangedFiles is an optional whitelist of file paths (relative to RootPath).
	// When non-nil, only files in this list are included in scan results.
	// Used by --changed and --since flags to restrict scanning to git-changed files.
	ChangedFiles map[string]bool

	// IncludeHidden determines whether to include hidden files (dotfiles).
	IncludeHidden bool

	// MaxFileSize is the maximum file size in bytes to include.
	MaxFileSize int64

	// PreloadContent reads file content during scan so downstream consumers
	// (e.g., the extractor) can skip a redundant os.ReadFile call.
	PreloadContent bool

	// MaxTotalPreloadSize limits the total bytes preloaded into memory when
	// PreloadContent is true. Once this budget is exceeded, remaining files
	// are included in the scan results but with Content set to nil (the
	// extractor will fall back to on-demand os.ReadFile). A value of 0 means
	// no limit. Default: 0.
	MaxTotalPreloadSize int64
}

ScanOptions configures the scanning behavior.

func DefaultScanOptions

func DefaultScanOptions() *ScanOptions

DefaultScanOptions returns a ScanOptions with sensible defaults. SupportedExtensions is derived from parser.LanguageMapping (single source of truth).

Example
package main

import (
	"fmt"

	"github.com/indigo-net/Brf.it/pkg/scanner"
)

func main() {
	opts := scanner.DefaultScanOptions()
	fmt.Println(opts.MaxFileSize)
	fmt.Println(opts.IncludeHidden)
}
Output:
512000
false

func (*ScanOptions) GetLanguage

func (o *ScanOptions) GetLanguage(path string) (string, bool)

GetLanguage returns the language for a given file path and whether it's supported.

type ScanResult

type ScanResult struct {
	// Files is the list of matched files.
	Files []FileEntry

	// TotalSize is the sum of all matched file sizes.
	TotalSize int64

	// SkippedCount is the number of files skipped (too large, unsupported, etc.).
	SkippedCount int

	// Warnings contains non-fatal issues encountered during scanning.
	Warnings []string
}

ScanResult contains the results of a scan operation.

type Scanner

type Scanner interface {
	// Scan performs the scan and returns scan results.
	// The context allows cancellation of long-running scans.
	Scan(ctx context.Context) (*ScanResult, error)
}

Scanner defines the interface for file system scanning.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL