Skip to content

Commit

Permalink
Modifed the sample plugins names
Browse files Browse the repository at this point in the history
The names of the functions and the names of the structs are not connected, they don't need to align at all - however this is a little confusing when trying to understand the relationship and how a plugin works. mhanson's feedback here helped to fine tune the learning experience, Even though the names of the files, the structs and the function names are not connected - it makes sence to keep them aligned when being used as a sample, to make things easy to understand.
  • Loading branch information
daveshanley committed Jul 15, 2022
1 parent 42a39fb commit 789fb83
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions plugin/sample/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import "github.com/daveshanley/vacuum/plugin"
// all custom functions should be registered here.
func Boot(pm *plugin.Manager) {

sampleA := SampleRuleFunction_A{}
sampleB := SampleRuleFunction_B{}
useless := uselessFunc{}
checkSinglePath := checkSinglePathExists{}

// register custom functions with vacuum plugin manager.
pm.RegisterFunction(sampleA.GetSchema().Name, sampleA)
pm.RegisterFunction(sampleB.GetSchema().Name, sampleB)
pm.RegisterFunction(useless.GetSchema().Name, useless)
pm.RegisterFunction(checkSinglePath.GetSchema().Name, checkSinglePath)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
"gopkg.in/yaml.v3"
)

// SampleRuleFunction_B is an example custom rule that checks only a single path exists.
type SampleRuleFunction_B struct {
// checkSinglePathExists is an example custom rule that checks only a single path exists.
type checkSinglePathExists struct {
}

// GetSchema returns a model.RuleFunctionSchema defining the schema of the Defined rule.
func (s SampleRuleFunction_B) GetSchema() model.RuleFunctionSchema {
func (s checkSinglePathExists) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{
Name: "checkSinglePathExists",
}
}

// RunRule will execute the Sample rule, based on supplied context and a supplied []*yaml.Node slice.
func (s SampleRuleFunction_B) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {
func (s checkSinglePathExists) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

// get the index https://quobix.com/vacuum/api/spec-index/
index := context.Index
Expand Down
8 changes: 4 additions & 4 deletions plugin/sample/sample_a.go → plugin/sample/useless_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"gopkg.in/yaml.v3"
)

// SampleRuleFunction_A is an example custom rule that does nothing.
type SampleRuleFunction_A struct {
// uselessFunc is an example custom rule that does nothing.
type uselessFunc struct {
}

// GetSchema returns a model.RuleFunctionSchema defining the schema of the Defined rule.
func (s SampleRuleFunction_A) GetSchema() model.RuleFunctionSchema {
func (s uselessFunc) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{
Name: "uselessFunc",
}
}

// RunRule will execute the Sample rule, based on supplied context and a supplied []*yaml.Node slice.
func (s SampleRuleFunction_A) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {
func (s uselessFunc) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {

// return a single result, for a made up linting failure.
return []model.RuleFunctionResult{
Expand Down

0 comments on commit 789fb83

Please sign in to comment.