2017-08-29 10:47:29 -07:00
|
|
|
package rule
|
2017-08-27 16:57:16 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"go/token"
|
|
|
|
|
2017-08-27 21:02:59 -07:00
|
|
|
"github.com/mgechev/revive/file"
|
2017-08-27 16:57:16 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// FailureTypeWarning declares failures of type warning
|
|
|
|
FailureTypeWarning = "warning"
|
|
|
|
// FailureTypeError declares failures of type error.
|
|
|
|
FailureTypeError = "error"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FailureType is the type for the failure types.
|
|
|
|
type FailureType string
|
|
|
|
|
|
|
|
// Failure defines a struct for a linting failure.
|
|
|
|
type Failure struct {
|
|
|
|
Failure string
|
|
|
|
Type FailureType
|
|
|
|
Position FailurePosition
|
|
|
|
file *file.File
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFilename returns the filename.
|
|
|
|
func (f *Failure) GetFilename() string {
|
|
|
|
return f.Position.Start.Filename
|
|
|
|
}
|
|
|
|
|
|
|
|
// FailurePosition returns the failure position
|
|
|
|
type FailurePosition struct {
|
|
|
|
Start token.Position
|
|
|
|
End token.Position
|
|
|
|
}
|
|
|
|
|
|
|
|
// RuleArguments is type used for the arguments of a rule.
|
|
|
|
type RuleArguments []string
|
|
|
|
|
|
|
|
type RuleConfig struct {
|
|
|
|
Name string
|
|
|
|
Arguments RuleArguments
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rule defines an abstract rule.
|
|
|
|
type Rule interface {
|
|
|
|
Apply(file *file.File, args RuleArguments) []Failure
|
|
|
|
}
|