rule

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

All lists every rule the analyzer reports, in the order they are reported.

Functions

func IsModuleWide added in v0.13.0

func IsModuleWide(r Rule) bool

IsModuleWide reports whether only a module-wide subcommand reports r.

func Names

func Names() []string

Names returns every rule name, for use in diagnostics.

Types

type BoundaryMode added in v0.10.0

type BoundaryMode int

BoundaryMode says whether the boundary rule reports: on or off. Only rules.boundary reads one.

A mode rather than a boolean, so that the key spells the rule's own name: boundary: true would read as "boundary: yes please", which is why the switch used to be named for what it did (allowBoundary). With a mode, the rule's name, its diagnostic category, its baseline key, its ignore target and its configuration key are one word, as they are for surplus.

const (
	// BoundaryModeOn reports a private declaration used from outside its
	// namespace. It is the default.
	BoundaryModeOn BoundaryMode = iota

	// BoundaryModeOff reports nothing, leaving only the naming rule.
	BoundaryModeOff
)

func (BoundaryMode) Reports added in v0.10.0

func (m BoundaryMode) Reports() bool

Reports reports whether the rule says anything at all.

func (BoundaryMode) String added in v0.10.0

func (m BoundaryMode) String() string

String returns the spelling the settings use.

type BoundaryModeSet added in v0.10.0

type BoundaryModeSet []BoundaryMode

BoundaryModeSet is the values rules.boundary accepts, in the order an error message names them.

func (BoundaryModeSet) Parse added in v0.10.0

func (s BoundaryModeSet) Parse(value string) (BoundaryMode, bool)

Parse reads a setting's value, of the members of the set only.

func (BoundaryModeSet) String added in v0.10.0

func (s BoundaryModeSet) String() string

String lists the accepted spellings: "off or on".

type QualifyMode added in v0.10.0

type QualifyMode int

QualifyMode says when a name must carry its namespace: always, never, or only once a package has a second namespace. Only rules.naming.qualify reads one.

const (
	// QualifyModeNever disables the rule.
	QualifyModeNever QualifyMode = iota

	// QualifyModeAlways applies the rule to every package. For the naming
	// rule this means a package gaining its second namespace is not a mass
	// rename.
	QualifyModeAlways

	// QualifyModeOnDemand applies the rule only to a package with more than
	// one namespace. In a package with one there is no boundary for a prefix to
	// mark: every other rule is structurally inert there, since every
	// reference is already inside the single namespace, and a prefix repeated
	// on every declaration would distinguish nothing.
	QualifyModeOnDemand
)

func (QualifyMode) Applies added in v0.10.0

func (m QualifyMode) Applies(namespaces int) bool

Applies reports whether the rule applies to a package with the given number of namespaces.

func (QualifyMode) String added in v0.10.0

func (m QualifyMode) String() string

String returns the spelling the settings use.

type QualifyModeSet added in v0.10.0

type QualifyModeSet []QualifyMode

QualifyModeSet is the values one setting accepts, in the order an error message names them. Each setting declares its own, so that a rejected value is answered with what that setting accepts rather than with everything QualifyMode can hold.

func (QualifyModeSet) Parse added in v0.10.0

func (s QualifyModeSet) Parse(value string) (QualifyMode, bool)

Parse reads a setting's value: always, never or ondemand, and of those only the members of the set.

func (QualifyModeSet) String added in v0.10.0

func (s QualifyModeSet) String() string

String lists the accepted spellings the way an error message names them: "always, never or ondemand".

type Rule

type Rule string

Rule is the name of a check.

const (
	// Boundary: a declaration used from outside the namespace it is private
	// to — a boundary crossing.
	Boundary Rule = "boundary"
	// Qualify: a package-level declaration whose name does not carry its
	// namespace, which namespace.Qualify fixes by prefixing.
	Qualify Rule = "qualify"
	// Surplus: package scope wider than any use visible to declscope. It
	// reports from an absence, in two shapes that share the name. Under
	// rules.surplus: loose, a //declscope:package whose every dependent is
	// unreached, with no fix — every remaining false positive would be an
	// automatic edit deleting a load-bearing directive. Under strict, also
	// each unreached dependent of a directive that is otherwise in use, fixed
	// by narrowing that one declaration.
	Surplus Rule = "surplus"
	// Unused: a directive that decides nothing. A scope directive that binds
	// no declaration, or under rules.unused: strict one that names the scope
	// everything it reaches would have without it, and an ignore that
	// silenced nothing. rules.unused sets how far it goes, off included.
	Unused Rule = "unused"
	// Directive: a directive that is malformed, unknown, conflicting or
	// misplaced. It has no fix and no configuration, so it is always on. It
	// carries a name so that an ignore can silence one, which a report with no
	// rule could never allow.
	Directive Rule = "directive"
	// Filter: a filter.only that cannot take effect, because an only above it
	// in the chain of config files removes everything it matches. It is about
	// the configuration rather than a declaration, so it carries no fix and no
	// baseline entry, and a file-level ignore is what silences it.
	Filter Rule = "filter"
	// Overexported: an exported declaration of an internal package that
	// nothing outside its package uses. Only declscope shrink reports it,
	// because only a run that loads the whole module can see every importer.
	// The analyzer never does, so it is not in All.
	Overexported Rule = "overexported"
)

func Parse

func Parse(name string) (Rule, bool)

Parse resolves a rule name.

type SurplusMode added in v0.10.0

type SurplusMode int

SurplusMode says how much the surplus rule reports: nothing, a whole directive nothing needs, or also each declaration a directive widens for nothing. Only rules.surplus reads one.

It is QualifyMode's sibling rather than three more QualifyMode values. QualifyMode carries a predicate, Applies, that asks how many namespaces a package has, and that question means nothing here; a QualifyMode that could hold loose would need an answer for it anyway. What the two share — parse by spelling, and list the spellings in an error — is small, and modeJoin is where it is shared.

const (
	// SurplusModeLoose reports a //declscope:package when nothing that takes
	// its scope from it is reached from another namespace. It is the default.
	SurplusModeLoose SurplusMode = iota

	// SurplusModeOff reports nothing.
	SurplusModeOff

	// SurplusModeStrict reports what loose does, and also each declaration
	// that takes package scope from an enclosing directive which is otherwise
	// in use, when nothing reaches that declaration from another namespace.
	SurplusModeStrict
)

func (SurplusMode) Reports added in v0.10.0

func (m SurplusMode) Reports() bool

Reports reports whether the rule says anything at all.

func (SurplusMode) ReportsDeclarations added in v0.10.0

func (m SurplusMode) ReportsDeclarations() bool

ReportsDeclarations reports whether the rule also judges each declaration a directive in use widens, not only the directive as a whole.

func (SurplusMode) String added in v0.10.0

func (m SurplusMode) String() string

String returns the spelling the settings use.

type SurplusModeSet added in v0.10.0

type SurplusModeSet []SurplusMode

SurplusModeSet is the values rules.surplus accepts, in the order an error message names them.

func (SurplusModeSet) Parse added in v0.10.0

func (s SurplusModeSet) Parse(value string) (SurplusMode, bool)

Parse reads a setting's value, of the members of the set only.

func (SurplusModeSet) String added in v0.10.0

func (s SurplusModeSet) String() string

String lists the accepted spellings: "off, loose or strict".

type UnusedMode added in v0.12.1

type UnusedMode int

UnusedMode says when the unused rule reports a directive: never, only when no configuration could make a scope directive bind, or also when it names the scope the declaration would have without it under this one. Only rules.unused reads one.

Its off reaches the unused rule alone. Malformed, unknown, conflicting and misplaced directives are the directive rule's, which has no switch.

const (
	// UnusedModeLoose reports an ignore that silenced nothing, and a scope
	// directive only when the scope it names is one every declaration it
	// reaches would have under every configuration. It is the default.
	UnusedModeLoose UnusedMode = iota

	// UnusedModeOff reports nothing.
	UnusedModeOff

	// UnusedModeStrict also reports a scope directive that names, for
	// everything it reaches, the scope that declaration would have without it
	// under the configuration in force, and offers to delete it.
	UnusedModeStrict
)

func (UnusedMode) Reports added in v0.12.1

func (m UnusedMode) Reports() bool

Reports reports whether the rule says anything at all.

func (UnusedMode) ReportsRedundant added in v0.12.1

func (m UnusedMode) ReportsRedundant() bool

ReportsRedundant reports whether a directive restating the scope the configuration already gives is reported.

func (UnusedMode) String added in v0.12.1

func (m UnusedMode) String() string

String returns the spelling the settings use.

type UnusedModeSet added in v0.12.1

type UnusedModeSet []UnusedMode

UnusedModeSet is the values rules.unused accepts, in the order an error message names them.

func (UnusedModeSet) Parse added in v0.12.1

func (s UnusedModeSet) Parse(value string) (UnusedMode, bool)

Parse reads a setting's value, of the members of the set only.

func (UnusedModeSet) String added in v0.12.1

func (s UnusedModeSet) String() string

String lists the accepted spellings: "off, loose or strict".

Jump to

Keyboard shortcuts

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