lint

package
v0.6.16 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyRegistryClient contextKey = iota
)

Variables

This section is empty.

Functions

func RegistryClient added in v0.6.1

func RegistryClient(ctx context.Context) connection.RegistryClient

Types

type ApiDeploymentRule

type ApiDeploymentRule struct {
	Name RuleName

	// OnlyIf determines whether this rule is applicable.
	OnlyIf func(p *rpc.ApiDeployment) bool

	// ApplyToApiDeployment accepts an ApiDeployment and checks it,
	// returning a slice of Problems it finds.
	ApplyToApiDeployment func(ctx context.Context, p *rpc.ApiDeployment) []*check.Problem
}

func (*ApiDeploymentRule) Apply

func (r *ApiDeploymentRule) Apply(ctx context.Context, res Resource) (problems []*check.Problem)

Apply calls ApplyToApiDeployment if the Resource is an ApiDeployment.

func (*ApiDeploymentRule) GetName

func (r *ApiDeploymentRule) GetName() RuleName

GetName returns the name of the rule.

type ApiRule

type ApiRule struct {
	Name RuleName

	// OnlyIf determines whether this rule is applicable.
	OnlyIf func(p *rpc.Api) bool

	// ApplyToApi accepts an Api and checks it,
	// returning a slice of Problems it finds.
	ApplyToApi func(ctx context.Context, p *rpc.Api) []*check.Problem
}

func (*ApiRule) Apply

func (r *ApiRule) Apply(ctx context.Context, res Resource) (problems []*check.Problem)

Apply calls ApplyToApi if the Resource is an Api.

func (*ApiRule) GetName

func (r *ApiRule) GetName() RuleName

GetName returns the name of the rule.

type ApiSpecRule

type ApiSpecRule struct {
	Name RuleName

	// OnlyIf determines whether this rule is applicable.
	OnlyIf func(p *rpc.ApiSpec) bool

	// ApiSpecRule accepts an ApiSpec and checks it,
	// returning a slice of Problems it finds.
	ApplyToApiSpec func(ctx context.Context, p *rpc.ApiSpec) []*check.Problem
}

func (*ApiSpecRule) Apply

func (r *ApiSpecRule) Apply(ctx context.Context, res Resource) (problems []*check.Problem)

Apply calls ApplyToApiSpec if the Resource is an ApiSpec.

func (*ApiSpecRule) GetName

func (r *ApiSpecRule) GetName() RuleName

GetName returns the name of the rule.

type ApiVersionRule

type ApiVersionRule struct {
	Name RuleName

	// OnlyIf determines whether this rule is applicable.
	OnlyIf func(p *rpc.ApiVersion) bool

	// ApplyToApiVersion accepts a Version and checks it,
	// returning a slice of Problems it finds.
	ApplyToApiVersion func(ctx context.Context, p *rpc.ApiVersion) []*check.Problem
}

func (*ApiVersionRule) Apply

func (r *ApiVersionRule) Apply(ctx context.Context, res Resource) (problems []*check.Problem)

Apply calls ApplyToVersion if the Resource is an ApiVersion.

func (*ApiVersionRule) GetName

func (r *ApiVersionRule) GetName() RuleName

GetName returns the name of the rule.

type ArtifactRule

type ArtifactRule struct {
	Name RuleName

	// OnlyIf determines whether this rule is applicable.
	OnlyIf func(p *rpc.Artifact) bool

	// ApplyToArtifact accepts an Artifact and checks it,
	// returning a slice of Problems it finds.
	ApplyToArtifact func(ctx context.Context, p *rpc.Artifact) []*check.Problem
}

func (*ArtifactRule) Apply

func (r *ArtifactRule) Apply(ctx context.Context, res Resource) (problems []*check.Problem)

Apply calls ApplyToArtifact if the Resource is an Artifact.

func (*ArtifactRule) GetName

func (r *ArtifactRule) GetName() RuleName

GetName returns the name of the rule.

type Checker

type Checker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Checker checks API files and returns a list of detected problems.

func New

func New(rules RuleRegistry, configs Configs) *Checker

New creates and returns a checker with the given rules and configs.

func (*Checker) Check

func (l *Checker) Check(ctx context.Context, admin connection.AdminClient, client connection.RegistryClient, root names.Name, filter string, jobs int) (response *check.CheckReport, err error)

type Config

type Config struct {
	IncludedPaths []string `json:"included_paths" yaml:"included_paths"`
	ExcludedPaths []string `json:"excluded_paths" yaml:"excluded_paths"`
	EnabledRules  []string `json:"enabled_rules" yaml:"enabled_rules"`
	DisabledRules []string `json:"disabled_rules" yaml:"disabled_rules"`
}

Config stores rule configurations for certain resource names such that the resource name must match any of the included paths but none of the excluded ones.

type Configs

type Configs []Config

Configs determine if a rule is enabled or not.

func ReadConfigsFromFile

func ReadConfigsFromFile(path string) (Configs, error)

ReadConfigsFromFile reads Configs from a file. It supports JSON(.json) and YAML(.yaml or .yml) files.

func ReadConfigsJSON

func ReadConfigsJSON(f io.Reader) (Configs, error)

ReadConfigsJSON reads Configs from a JSON file.

func ReadConfigsYAML

func ReadConfigsYAML(f io.Reader) (Configs, error)

ReadConfigsYAML reads Configs from a YAML(.yml or .yaml) file.

func (Configs) IsRuleEnabled

func (configs Configs) IsRuleEnabled(rule string, resourceName string) bool

IsRuleEnabled returns true if a rule is enabled by the configs.

type FieldRule

type FieldRule struct {
	Name RuleName

	// OnlyIf determines whether this rule is applicable.
	OnlyIf func(resource Resource, field string) bool

	// ApplyToField accepts a Field name and value and checks it, returning a slice of
	// Problems it finds.
	ApplyToField func(ctx context.Context, resource Resource, field string, value interface{}) []*check.Problem
}

FieldRule defines a rule that is run on each field within a file.

func (*FieldRule) Apply

func (r *FieldRule) Apply(ctx context.Context, res Resource) (problems []*check.Problem)

Apply visits every field in the passed resource and runs `ApplyToField`.

If an `OnlyIf` function is provided on the rule, it is run against each field, and if it returns false, the `ApplyToField` function is not called.

func (*FieldRule) GetName

func (r *FieldRule) GetName() RuleName

GetName returns the name of the rule.

type ProjectRule

type ProjectRule struct {
	Name RuleName

	// OnlyIf determines whether this rule is applicable.
	OnlyIf func(p *rpc.Project) bool

	// ApplyToProject accepts a Project and checks it,
	// returning a slice of Problems it finds.
	ApplyToProject func(ctx context.Context, p *rpc.Project) []*check.Problem
}

func (*ProjectRule) Apply

func (r *ProjectRule) Apply(ctx context.Context, res Resource) (problems []*check.Problem)

Apply calls ApplyToProject if the Resource is a Project.

func (*ProjectRule) GetName

func (r *ProjectRule) GetName() RuleName

GetName returns the name of the rule.

type Resource

type Resource interface {
	GetName() string
}

type Rule

type Rule interface {
	// GetName returns the name of the rule.
	GetName() RuleName

	// Apply accepts a resource and checks it,
	// returning a slice of Problems it finds.
	Apply(ctx context.Context, resource Resource) []*check.Problem
}

Rule defines a rule for checking a Resource. Anything that satisfies this interface can be used as a rule, but most rule authors will want to use the implementations provided.

type RuleName

type RuleName string

RuleName is an identifier for a rule. Allowed characters include a-z, 0-9, -.

The namespace separator :: is allowed between RuleName segments (for example, my-namespace::my-rule).

func NewRuleName

func NewRuleName(ruleNum int, name string) RuleName

NewRuleName creates a RuleName from an rule number and a unique name within that rule.

func (RuleName) HasPrefix

func (r RuleName) HasPrefix(prefix ...string) bool

HasPrefix returns true if r contains prefix as a namespace. prefix parameters can be "::" delimited or specified as independent parameters. For example:

r := NewRuleName("foo", "bar", "baz") // string(r) == "foo::bar::baz"

r.HasPrefix("foo::bar") == true r.HasPrefix("foo", "bar") == true r.HasPrefix("foo", "bar", "baz") == true // matches the entire string r.HasPrefix("foo", "ba") == false // prefix must end on a delimiter

func (RuleName) IsValid

func (r RuleName) IsValid() bool

IsValid checks if a RuleName is syntactically valid.

type RuleRegistry

type RuleRegistry map[RuleName]Rule

RuleRegistry is a registry for registering and looking up rules.

func NewRuleRegistry

func NewRuleRegistry() RuleRegistry

NewRuleRegistry creates a new rule registry.

func (RuleRegistry) Register

func (r RuleRegistry) Register(ruleNum int, rules ...Rule) error

Register registers the list of rules of the same ruleNum. Return an error if any of the rules is found duplicate in the registry.

Jump to

Keyboard shortcuts

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