github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/_example/plugin/customrules/simpleRule.go (about)

     1  package customrules
     2  
     3  import (
     4  	"github.com/yoheimuta/go-protoparser/v4/parser"
     5  	"github.com/yoheimuta/go-protoparser/v4/parser/meta"
     6  
     7  	"github.com/yoheimuta/protolint/linter/report"
     8  	"github.com/yoheimuta/protolint/linter/rule"
     9  )
    10  
    11  // SimpleRule verifies that all enum names are LowerSnakeCase.
    12  type SimpleRule struct {
    13  	verbose  bool
    14  	fixMode  bool
    15  	severity rule.Severity
    16  }
    17  
    18  // NewSimpleRule creates a new SimpleRule.
    19  func NewSimpleRule(
    20  	verbose bool,
    21  	fixMode bool,
    22  	severity rule.Severity,
    23  ) SimpleRule {
    24  	return SimpleRule{
    25  		verbose:  verbose,
    26  		fixMode:  fixMode,
    27  		severity: severity,
    28  	}
    29  }
    30  
    31  // ID returns the ID of this rule.
    32  func (r SimpleRule) ID() string {
    33  	return "SIMPLE"
    34  }
    35  
    36  // Purpose returns the purpose of this rule.
    37  func (r SimpleRule) Purpose() string {
    38  	return "Simple custom rule."
    39  }
    40  
    41  // IsOfficial decides whether or not this rule belongs to the official guide.
    42  func (r SimpleRule) IsOfficial() bool {
    43  	return true
    44  }
    45  
    46  // Severity gets the rule severity
    47  func (r SimpleRule) Severity() rule.Severity {
    48  	return r.severity
    49  }
    50  
    51  // Apply applies the rule to the proto.
    52  func (r SimpleRule) Apply(proto *parser.Proto) ([]report.Failure, error) {
    53  	return []report.Failure{
    54  		report.Failuref(meta.Position{}, r.ID(), "Custom Rule, verbose=%v, fixMode=%v", r.verbose, r.fixMode),
    55  	}, nil
    56  }