github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/linter/rule/rule.go (about)

     1  package rule
     2  
     3  import (
     4  	"github.com/yoheimuta/go-protoparser/v4/parser"
     5  
     6  	"github.com/yoheimuta/protolint/linter/report"
     7  )
     8  
     9  // Severity represents the severity of the rule.
    10  // All failues will have this severity on export.
    11  type Severity string
    12  
    13  const (
    14  	// SeverityNote represents a note only rule severity
    15  	SeverityNote Severity = "note"
    16  	// SeverityWarning represents a rule severity at a warning level
    17  	SeverityWarning Severity = "warning"
    18  	// SeverityError represents a rule severity at a warning level
    19  	SeverityError Severity = "error"
    20  )
    21  
    22  // HasApply represents a rule which can be applied.
    23  type HasApply interface {
    24  	// Apply applies the rule to the proto.
    25  	Apply(proto *parser.Proto) ([]report.Failure, error)
    26  }
    27  
    28  // HasID represents a rule with ID.
    29  type HasID interface {
    30  	// ID returns the ID of this rule. This should be all UPPER_SNAKE_CASE.
    31  	ID() string
    32  }
    33  
    34  // HasPurpose represents a rule with Purpose.
    35  type HasPurpose interface {
    36  	// Purpose returns the purpose of this rule. This should be a human-readable string.
    37  	Purpose() string
    38  }
    39  
    40  // HasIsOfficial represents a rule with IsOfficial.
    41  type HasIsOfficial interface {
    42  	// IsOfficial decides whether or not this rule belongs to the official guide.
    43  	IsOfficial() bool
    44  }
    45  
    46  // HasSeverity represents a rule with a configurable severity
    47  type HasSeverity interface {
    48  	// Severity returns the selected severity of a rule
    49  	Severity() Severity
    50  }
    51  
    52  // Rule represents a rule which a linter can apply.
    53  type Rule interface {
    54  	HasApply
    55  	HasID
    56  	HasPurpose
    57  	HasIsOfficial
    58  	HasSeverity
    59  }