1
0
mirror of https://github.com/mgechev/revive.git synced 2025-03-21 21:17:06 +02:00
revive/linter/rule.go

80 lines
1.7 KiB
Go
Raw Normal View History

2018-01-21 18:04:41 -08:00
package linter
2017-08-27 16:57:16 -07:00
import (
2017-11-19 17:35:56 -08:00
"go/ast"
2017-08-27 16:57:16 -07:00
"go/token"
)
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
2017-09-01 18:36:47 -07:00
// FailurePosition returns the failure position
type FailurePosition struct {
Start token.Position
End token.Position
}
2017-08-27 16:57:16 -07:00
// Failure defines a struct for a linting failure.
type Failure struct {
2017-11-26 18:48:07 -08:00
Failure string
RuleName string
2018-01-21 18:41:38 -08:00
Category string
2017-11-26 18:48:07 -08:00
Type FailureType
Position FailurePosition
2018-01-23 18:19:06 -08:00
Node ast.Node `json:"-"`
2017-11-26 18:48:07 -08:00
Confidence float64
2018-01-23 19:13:02 -08:00
URL string
2018-01-23 18:46:13 -08:00
// For future use
ReplacementLine string
2017-08-27 16:57:16 -07:00
}
// GetFilename returns the filename.
func (f *Failure) GetFilename() string {
return f.Position.Start.Filename
}
2017-09-01 18:36:47 -07:00
// DisabledInterval contains a single disabled interval and the associated rule name.
type DisabledInterval struct {
From token.Position
To token.Position
RuleName string
2017-08-27 16:57:16 -07:00
}
2017-09-01 18:36:47 -07:00
// Arguments is type used for the arguments of a rule.
type Arguments []string
2017-08-27 16:57:16 -07:00
2017-11-19 17:18:16 -08:00
// Config contains the rule configuration.
2017-09-01 18:36:47 -07:00
type Config struct {
2017-08-27 16:57:16 -07:00
Name string
2017-09-01 18:36:47 -07:00
Arguments Arguments
2017-08-27 16:57:16 -07:00
}
2017-11-19 18:23:01 -08:00
// RulesConfig defiles the config for all rules.
type RulesConfig = map[string]Arguments
2017-11-19 17:18:16 -08:00
// Rule defines an abstract rule interaface
2017-08-27 16:57:16 -07:00
type Rule interface {
2017-11-19 17:18:16 -08:00
Name() string
2018-01-21 18:04:41 -08:00
Apply(*File, Arguments) []Failure
2017-11-19 17:18:16 -08:00
}
// AbstractRule defines an abstract rule.
type AbstractRule struct {
2017-11-19 17:58:28 -08:00
Failures []Failure
2017-11-19 17:18:16 -08:00
}
2017-11-19 17:58:28 -08:00
// ToFailurePosition returns the failure position.
2018-01-21 18:04:41 -08:00
func ToFailurePosition(start token.Pos, end token.Pos, file *File) FailurePosition {
2017-11-19 17:18:16 -08:00
return FailurePosition{
2017-11-19 17:35:56 -08:00
Start: file.ToPosition(start),
End: file.ToPosition(end),
2017-11-19 17:18:16 -08:00
}
2017-08-27 16:57:16 -07:00
}