importvet

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package importvet implements import path linter.

Index

Constants

View Source
const (
	ActionAllow = Action("allow")
	ActionDeny  = Action("deny")
)

Defined actions.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:      "importvet",
	Doc:       "checks that import paths conforman to restrictions",
	Run:       run,
	FactTypes: []analysis.Fact{new(importFact)},
}

Analyzer ...

Functions

func InitConfig

func InitConfig(rootPath string) (err error)

InitConfig should be called to initialize configs for the import restrictions.

Types

type Action

type Action string

Action is rule action (firewall style).

type Config

type Config struct {
	Path    string `yaml:"-"`
	RuleSet `yaml:",inline"`
}

Config is YAML representation of the config.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads import restrictions config from specified path.

type ConfigTree

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

ConfigTree accumulates config files by looking recursively over the tree.

func NewConfigTree

func NewConfigTree(rootPath string) (*ConfigTree, error)

NewConfigTree generates config tree by walking the source tree.

func (*ConfigTree) Match

func (cfgTree *ConfigTree) Match(path string) ([]*Config, error)

Match returns list of configs applicable to the path.

All matching configs in the tree are returned with least specific config first.

type Rule

type Rule struct {
	// Regexp is regular expression against the import path.
	Regexp string `yaml:"regexp"`
	// Set is a way to refer to some set of packages (e.g. `std` packages).
	Set string `yaml:"set"`
	// Action is one of the "Allow", "Deny"
	Action Action `yaml:"action"`
	// Stop indicates whether rule processing should stop or continue.
	Stop bool `yaml:"stop"`
	// contains filtered or unexported fields
}

Rule represents single import restriction rule.

func (*Rule) Matches

func (rule *Rule) Matches(pkg *types.Package) bool

Matches checks whether rule applies to imported package.

func (*Rule) Validate

func (rule *Rule) Validate() error

Validate rule syntax.

type RuleSet

type RuleSet struct {
	Rules []Rule `yaml:"rules"`
}

RuleSet is an order set of Rules processed top-down.

Rules are processed firewall-style, top-down, only matching rules are applied. Action of the last matched rule (or rule with Stop enabled) is the action taken. Default action is 'allow'.

func (*RuleSet) Process

func (ruleset *RuleSet) Process(pkg *types.Package) Action

Process evaluates rules and returns final result: is import of pkg allowed or not.

func (*RuleSet) Validate

func (ruleset *RuleSet) Validate() error

Validate the rules, stops on first error.

Jump to

Keyboard shortcuts

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