bufcheck

package
v1.45.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 33 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDeprecatedIDToReplacementIDs added in v1.40.0

func GetDeprecatedIDToReplacementIDs[R RuleOrCategory](rulesOrCategories []R) (map[string][]string, error)

GetDeprecatedIDToReplacementIDs gets a map from deprecated ID to replacement IDs.

func PrintRules

func PrintRules(writer io.Writer, rules []Rule, options ...PrintRulesOption) (retErr error)

PrintRules prints the rules to the Writer.

Types

type AllCategoriesOption added in v1.40.0

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

AllCategoriesOption is an option for AllCategories.

type AllRulesOption added in v1.40.0

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

AllRulesOption is an option for AllRules.

type BreakingOption added in v1.40.0

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

BreakingOption is an option for Breaking.

func BreakingWithExcludeImports added in v1.40.0

func BreakingWithExcludeImports() BreakingOption

BreakingWithExcludeImports returns a new BreakingOption that says to exclude imports from breaking change detection.

The default is to check imports for breaking changes.

type Category added in v1.40.0

type Category interface {
	check.Category

	// Plugin returns the name of the plugin that created this Category.
	//
	// Names are freeform.
	//
	// Will be empty for Categorys based on builtin plugins.
	PluginName() string
	// contains filtered or unexported methods
}

Category is an individual line or breaking Category.

It wraps check.Category and adds the name of the plugin that implements the Category.

type Client added in v1.40.0

type Client interface {
	// Lint lints the given Image with the given LintConfig.
	//
	// The Image should have source code info for this to work properly.
	//
	// Images should *not* be filtered with regards to imports before passing to this function.
	//
	// An error of type bufanalysis.FileAnnotationSet will be returned lint failure.
	Lint(ctx context.Context, config bufconfig.LintConfig, image bufimage.Image, options ...LintOption) error
	// Breaking checks the given Images for breaking changes with the given BreakingConfig.
	//
	// The Images should have source code info for this to work properly.
	//
	// Images should *not* be filtered with regards to imports before passing to this function.
	// To exclude imports, pass BreakingWithExcludeImports.
	//
	// An error of type bufanalysis.FileAnnotationSet will be returned lint failure.
	Breaking(ctx context.Context, config bufconfig.BreakingConfig, image bufimage.Image, againstImage bufimage.Image, options ...BreakingOption) error
	// ConfiguredRules returns all of the Configured Rules for the given RuleType.
	ConfiguredRules(ctx context.Context, ruleType check.RuleType, config bufconfig.CheckConfig, options ...ConfiguredRulesOption) ([]Rule, error)
	// AllRules returns all Rules (configured or not) for the given RuleType.
	AllRules(ctx context.Context, ruleType check.RuleType, fileVersion bufconfig.FileVersion, options ...AllRulesOption) ([]Rule, error)
	// AllCategories returns all Categories.
	AllCategories(ctx context.Context, fileVersion bufconfig.FileVersion, options ...AllCategoriesOption) ([]Category, error)
}

Rules are returned sorted by ID, but PrintRules does our sort by category.

func NewClient added in v1.40.0

func NewClient(
	logger *slog.Logger,
	runnerProvider RunnerProvider,
	options ...ClientOption,
) (Client, error)

NewClient returns a new Client.

type ClientFunctionOption added in v1.40.0

ClientFunctionOption is an option that applies to any Client function.

func WithPluginConfigs added in v1.40.0

func WithPluginConfigs(pluginConfigs ...bufconfig.PluginConfig) ClientFunctionOption

WithPluginConfigs returns a new ClientFunctionOption that says to also use the given plugins.

The default is to only use the builtin Rules and Categories.

type ClientOption added in v1.40.0

type ClientOption func(*clientOptions)

ClientOption is an option for a new Client.

func ClientWithStderr added in v1.40.0

func ClientWithStderr(stderr io.Writer) ClientOption

ClientWithStderr returns a new ClientOption that specifies a stderr to proxy plugin stderrs to.

The default is the equivalent of /dev/null.

type ConfiguredRulesOption added in v1.40.0

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

ConfiguredRulesOption is an option for ConfiguredRules.

type LintOption added in v1.40.0

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

LintOption is an option for Lint.

type PrintRulesOption added in v1.37.0

type PrintRulesOption func(*printRulesOptions)

PrintRulesOption is an option for PrintRules.

func PrintRulesWithDeprecated added in v1.37.0

func PrintRulesWithDeprecated() PrintRulesOption

PrintRulesWithDeprecated returns a new PrintRulesOption that resullts in deprecated rules being printed.

func PrintRulesWithJSON added in v1.37.0

func PrintRulesWithJSON() PrintRulesOption

PrintRulesWithJSON returns a new PrintRulesOption that says to print the rules as JSON.

The default is to print as text.

type Rule

type Rule interface {
	check.Rule

	// BufcheckCategories returns the Rule's Categories.
	BufcheckCategories() []Category

	// Plugin returns the name of the plugin that created this Rule.
	//
	// Names are freeform.
	//
	// Will be empty for Rules based on builtin plugins.
	PluginName() string
	// contains filtered or unexported methods
}

Rule is an individual line or breaking Rule.

It wraps check.Rule and adds the name of the plugin that implements the Rule.

type RuleOrCategory added in v1.40.0

type RuleOrCategory interface {
	ID() string
	Purpose() string
	Deprecated() bool
	ReplacementIDs() []string
	PluginName() string
	// contains filtered or unexported methods
}

RuleOrCategory is a union interface with the common types in both Rule and Category.

type RunnerProvider added in v1.40.1

type RunnerProvider interface {
	NewRunner(pluginConfig bufconfig.PluginConfig) (pluginrpc.Runner, error)
}

RunnerProvider provides pluginrpc.Runners for a given plugin config.

func NewRunnerProvider added in v1.42.0

func NewRunnerProvider(commandRunner command.Runner, wasmRuntime wasm.Runtime) RunnerProvider

NewRunnerProvider returns a new RunnerProvider for the command.Runner and wasm.Runtime.

This implementation should only be used for local applications. It is safe to use concurrently.

The RunnerProvider selects the correct Runner based on the PluginConfigType. The supported types are:

  • bufconfig.PluginConfigTypeLocal
  • bufconfig.PluginConfigTypeLocalWasm

If the PluginConfigType is not supported, an error is returned.

type RunnerProviderFunc added in v1.40.1

type RunnerProviderFunc func(pluginConfig bufconfig.PluginConfig) (pluginrpc.Runner, error)

RunnerProviderFunc is a function that implements RunnerProvider.

func (RunnerProviderFunc) NewRunner added in v1.40.1

func (r RunnerProviderFunc) NewRunner(pluginConfig bufconfig.PluginConfig) (pluginrpc.Runner, error)

NewRunner implements RunnerProvider.

RunnerProvider selects the correct Runner based on the type of pluginConfig.

Jump to

Keyboard shortcuts

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