find

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exclude

type Exclude struct {
	fs.DirEntry
	Path string
}

Exclude represents a file or directory that should be excluded from a search. It contains a fs.DirEntry and the Path of the file or directory. It is used as an argument for Skip's Dir and File functions to determine if a file or directory should be skipped during a search.

type Finder

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

Finder searches a Go repository for Go types and functions that are exported and optionally not commented. Use New to create a new Finder, providing the fs.FS of the repository to search and zero or more options. Call All or Uncommented on a Finder to search the repository for all types/functions or only uncommented types/functions, respectively.

func New

func New(repo fs.FS, opts ...Option) *Finder

New returns a new *Finder that searches for types and functions in a given repository. It accepts an fs.FS representing the repository and zero or more Options to configure the search. The returned Finder can be used to search for all types and functions or only those without comments.

func (*Finder) All

func (f *Finder) All() (Findings, error)

All returns a map of Findings(#Finding) for all exported types and functions in the repository.

func (*Finder) Uncommented

func (f *Finder) Uncommented() (Findings, error)

Uncommented returns all [Finding]s of uncommented types and functions in the file system under the specified path.

type Finding

type Finding struct {
	Path       string
	Identifier string
}

Finding represents a type that contains information about code entities found in a file. It has two fields: Path and Identifier, where Path is the path of the file where the code entity was found and Identifier is the name of the code entity.

func (Finding) String

func (f Finding) String() string

String returns a string representation of a Finding. It concatenates the Path and Identifier fields of the Finding with an "@" character in between.

type Findings

type Findings map[string][]Finding

Findings [type] represents a map of file paths to slices of Findings. A Finding is a struct that contains the path to a Go source file and an exported identifier within that file. Use the Finder type to search for uncommented code in a filesystem, returning Findings for all or just uncommented types/functions.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an interface for configuring a *Finder.

func Glob

func Glob(pattern ...string) Option

Glob returns an Option that appends one or more glob patterns to the Finder. The Finder will exclude files and directories that match any of the glob patterns.

func WithLogger

func WithLogger(h slog.Handler) Option

WithLogger returns an Option that sets the logger for a Finder. The logger is used to log debug, info and error messages during file searching.

type Skip

type Skip struct {
	Hidden    bool
	Dotfiles  bool
	Testdata  bool
	Testfiles bool
	Tests     bool

	Dir  func(Exclude) bool
	File func(Exclude) bool
}

Skip represents a set of rules for excluding directories and files during a file system traversal. It contains fields for excluding hidden files, dotfiles, test data directories, and test files. It also includes functions for customizing directory and file exclusion behavior. Skip is used by Finder to avoid traversing unwanted directories and files.

func SkipDefault

func SkipDefault() Skip

SkipDefault returns a Skip object with default values set for skipping hidden files and directories, dotfiles, testdata, and testfiles. It can be used as a starting point for creating custom Skip objects. Exclude objects can be passed to Skip methods to check if a file or directory should be excluded during a file search.

func SkipNone

func SkipNone() Skip

SkipNone returns a Skip value with all of its fields set to their zero value. It is used to indicate that no files or directories should be skipped during the search.

func (Skip) ExcludeDir

func (s Skip) ExcludeDir(e Exclude) bool

ExcludeDir returns a boolean indicating whether a directory should be excluded from the search. An Exclude struct with the directory's DirEntry and Path is passed as an argument. This function checks if the directory name starts with a dot when Skip.Hidden is set to true, or if it matches the "testdata" folder when Skip.Testdata is set to true. If Skip.Dir is not nil, it also calls that function to determine if the directory should be skipped.

func (Skip) ExcludeFile

func (s Skip) ExcludeFile(f Exclude) bool

ExcludeFile returns a boolean indicating whether the file should be excluded from the search. The exclusion criteria are based on the Skip struct's Dotfiles, Testfiles, and File fields. If Dotfiles is true, files with names starting with a dot (".") are excluded. If Testfiles is true, files with names ending in "_test.go" are excluded. Finally, if the File field of Skip is not nil, it will be called with the fs.DirEntry wrapped in an Exclude struct to determine whether the file should be excluded.

Jump to

Keyboard shortcuts

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