Documentation ¶
Index ¶
- type Finding
- type JotBot
- func (bot *JotBot) ConfigureLanguage(name string, lang Language)
- func (bot *JotBot) Extensions() []string
- func (bot *JotBot) Find(ctx context.Context, opts ...find.Option) ([]Finding, error)
- func (bot *JotBot) Generate(ctx context.Context, findings []Finding, svc generate.Service, ...) (*Patch, error)
- type Language
- type Option
- type Patch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Finding ¶ added in v0.0.4
Finding represents a discovered identifier within a particular file and programming language. It holds the unique identifier found, the file in which it was found, and the language of that file. The Finding type provides a way to reference specific code elements that have been identified during analysis or processing across various files and languages.
type JotBot ¶ added in v0.0.4
type JotBot struct {
// contains filtered or unexported fields
}
JotBot orchestrates the process of searching, analyzing, and transforming code across multiple programming languages within a specified directory structure. It leverages configurable language-specific behaviors to locate identifiers, generate updates, and apply patches based on findings. JotBot allows for flexible extension by registering different languages and can be customized through various options to match specific project needs. It provides methods to configure languages, find code patterns, generate code changes, and apply those changes as patches. Additionally, it supports logging for traceability of operations.
func New ¶
New initializes and returns a new instance of JotBot configured with the provided root directory and options.
func (*JotBot) ConfigureLanguage ¶ added in v0.0.4
ConfigureLanguage associates a given language with its name and file extensions within the JotBot instance. It enables the JotBot to recognize files of this language by their extensions when performing operations such as finding identifiers or generating patches.
func (*JotBot) Extensions ¶ added in v0.0.4
Extensions returns a slice of all file extensions that are associated with configured languages within the JotBot instance. These extensions can be used to filter files for processing based on the languages that the JotBot is capable of handling.
func (*JotBot) Find ¶ added in v0.0.4
Find performs a search for identifiers within the files of a repository based on the configured languages and file extensions. It accepts a context and variadic find options to customize the search behavior. The function returns a slice of Findings, which contain the identifier, file, and language of each found item, or an error if the search could not be completed. The Findings are sorted by file and then by identifier. If filters are configured, only findings matching those filters are included in the results.
func (*JotBot) Generate ¶ added in v0.0.4
func (bot *JotBot) Generate(ctx context.Context, findings []Finding, svc generate.Service, opts ...generate.Option) (*Patch, error)
Generate creates a patch based on the provided findings and generation service, applying additional options if specified. It processes each finding to prepare the input for the generator, then invokes the generator to create file patches. On success, it returns a *Patch that encapsulates the generated patches along with any errors that occurred during generation. If an error is encountered during the preparation of inputs or generation process, it returns an error detailing the failure.
type Language ¶ added in v0.0.4
type Language interface { patch.Language generate.Language // Extensions reports the file extensions associated with a language. These // extensions typically do not include the leading dot. Extensions() []string // Find locates and returns all identifiers within a given byte slice according // to the rules of the implementing language, or an error if the search cannot // be completed. It returns a slice of strings representing the found // identifiers and an error, if any occurred during the search process. Find([]byte) ([]string, error) }
Language represents a programming language with the ability to describe itself, such as providing its file extensions and identifying code patterns within its syntax. It integrates with patching and code generation systems, allowing for modifications and enhancements of code written in the language it represents. It also offers methods to locate identifiers within a body of text, aiding in various analysis and automation tasks.
type Option ¶
type Option func(*JotBot)
Option configures a *JotBot instance with custom settings, such as specifying languages to recognize, logging behavior, or file matching patterns. It is used when creating a new *JotBot or adjusting its configuration at runtime. Each Option is a function that applies a specific configuration to the *JotBot.
func Match ¶ added in v0.0.4
Match configures a JotBot with custom filters for identifying relevant findings. It accepts a variable number of regular expressions that are used to filter the search results when finding identifiers within files. The provided filters are appended to any existing filters the JotBot may have.
func WithLanguage ¶ added in v0.0.4
WithLanguage configures a JotBot instance to use a specified language with an associated name. It allows the JotBot to recognize and handle files that pertain to the given language during its operations. This configuration is done through an option that can be passed to the JotBot constructor.
func WithLogger ¶
WithLogger configures a JotBot instance to use the provided slog.Handler for logging operations. It returns an Option which, when applied, sets up the internal logger of the JotBot with the specified handler.
type Patch ¶ added in v0.0.4
Patch applies modifications across a collection of files within a specified root directory. It leverages a provided callback to determine the language-specific behaviors required for each file based on its extension, ensuring that patches are applied correctly according to language rules and syntax. Patch also supports a dry run mode that simulates the patch application, returning a map of the proposed changes without altering the original files, allowing for pre-application review and validation.
func (*Patch) Apply ¶ added in v0.0.4
Apply applies the patch to the files within the specified root directory. It takes a context and a string representing the root directory path as arguments and returns an error if the patch cannot be applied. The operation respects the context cancellation and will abort if the context is canceled.
func (*Patch) DryRun ¶ added in v0.0.4
DryRun simulates the application of the patch to the given root directory without making actual changes, and returns a map of file paths to their new content as it would appear after applying the patch. It accepts a context for cancellation and deadline control, and requires the root directory as an argument. The function returns an error if any issues occur during the dry run process.