1
0
mirror of https://github.com/mgechev/revive.git synced 2025-03-19 21:07:46 +02:00
revive/lint/rule.go

87 lines
1.9 KiB
Go
Raw Normal View History

2018-01-24 15:44:03 -08:00
package lint
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 (
2018-01-24 15:41:40 -08:00
// SeverityWarning declares failures of type warning
SeverityWarning = "warning"
// SeverityError declares failures of type error.
SeverityError = "error"
2017-08-27 16:57:16 -07:00
)
2018-01-24 15:41:40 -08:00
// Severity is the type for the failure types.
type Severity string
2017-08-27 16:57:16 -07:00
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
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.
2018-01-26 20:45:17 -08:00
type Arguments = []interface{}
2017-08-27 16:57:16 -07:00
2018-01-24 15:41:40 -08:00
// RuleConfig is type used for the rule configuration.
type RuleConfig struct {
2018-01-26 20:27:52 -08:00
Arguments Arguments
Severity Severity
2017-08-27 16:57:16 -07:00
}
2018-01-25 12:33:46 -08:00
// RulesConfig defines the config for all rules.
2018-01-24 15:41:40 -08:00
type RulesConfig = map[string]RuleConfig
2017-11-19 18:23:01 -08:00
2018-01-25 12:33:46 -08:00
// Config defines the config of the linter.
type Config struct {
2018-01-27 16:37:30 -08:00
IgnoreGeneratedHeader bool `toml:"ignore-generated-header"`
Confidence float64
Severity Severity
Rules RulesConfig `toml:"rule"`
2018-01-25 12:33:46 -08:00
}
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
}