1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00
revive/lint/rule.go
2018-01-24 15:44:03 -08:00

79 lines
1.7 KiB
Go

package lint
import (
"go/ast"
"go/token"
)
const (
// SeverityWarning declares failures of type warning
SeverityWarning = "warning"
// SeverityError declares failures of type error.
SeverityError = "error"
)
// Severity is the type for the failure types.
type Severity string
// FailurePosition returns the failure position
type FailurePosition struct {
Start token.Position
End token.Position
}
// Failure defines a struct for a linting failure.
type Failure struct {
Failure string
RuleName string
Category string
Position FailurePosition
Node ast.Node `json:"-"`
Confidence float64
URL string
// For future use
ReplacementLine string
}
// GetFilename returns the filename.
func (f *Failure) GetFilename() string {
return f.Position.Start.Filename
}
// DisabledInterval contains a single disabled interval and the associated rule name.
type DisabledInterval struct {
From token.Position
To token.Position
RuleName string
}
// Arguments is type used for the arguments of a rule.
type Arguments = []string
// RuleConfig is type used for the rule configuration.
type RuleConfig struct {
Arguments Arguments
Severity Severity
}
// RulesConfig defiles the config for all rules.
type RulesConfig = map[string]RuleConfig
// Rule defines an abstract rule interaface
type Rule interface {
Name() string
Apply(*File, Arguments) []Failure
}
// AbstractRule defines an abstract rule.
type AbstractRule struct {
Failures []Failure
}
// ToFailurePosition returns the failure position.
func ToFailurePosition(start token.Pos, end token.Pos, file *File) FailurePosition {
return FailurePosition{
Start: file.ToPosition(start),
End: file.ToPosition(end),
}
}