locations

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Allow, Disallowed Location
}

Filter represents a location filter

func AllowedIn

func AllowedIn(locations ...Location) Filter

AllowedIn creates a location filter, where the given location must fully match all locations given.

For example:

f := In(File, InitFunction, Variable)
f.Allowed(Variable) == false
f.Allowed(File & Variable & InitFunction & Function) == true

func (Filter) Allowed

func (f Filter) Allowed(location Location) bool

Allowed returns true if this location allowed by this filter. See both AllowedIn and ButNotIn for examples

func (Filter) ButNotIn

func (f Filter) ButNotIn(locations ...Location) Filter

ButNotIn modifies the location filter, where a given location must not be in _any_ of the locations given.

For example:

f := In(Function).NotIn(InitFunction, Variable)
f.Allowed(File & Function) == true
f.Allowed(File & Function & Variable) == false

func (Filter) Describe

func (f Filter) Describe() string

type Filters

type Filters []Filter

Filters represents a list of location filters

func (Filters) Allowed

func (f Filters) Allowed(location Location) bool

Allowed returns true if _any_ of the filters allow the location, regardless if others do not

func (Filters) Describe

func (f Filters) Describe(what string, pastTenseVerb string) string

Describe retuns an english description of where `what` can be `pastTenseVerb`

For example:

Filter{In(Function), In(InitFunction), In(Variable).NotIn(Function)}.Describe("foo", "called")

will return:

foo can be only be called in a function, an init function or a package level variable declaration

type Location

type Location int

Location represents a bitwise flag of locations

const (
	File         Location = 1 << iota // Inside a file, outside a function body
	InitFunction                      // Inside an init function declaration
	Function                          // Inside any function declaration (including the init function)
	Variable                          // Inside a variable

)

This list is ordered from most outer possible location, to most inner location

func (Location) Describe

func (i Location) Describe() string

Describe returns a list of the location parts which make up this location

func (Location) String

func (i Location) String() string

Jump to

Keyboard shortcuts

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