Skip to content

Commit f06c688

Browse files
committed
tuned example plugins
1 parent a508e3e commit f06c688

File tree

7 files changed

+30
-7
lines changed

7 files changed

+30
-7
lines changed

cmd/lint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func GetLintCommand() *cobra.Command {
203203
}
204204
rules = append(rules, pterm.BulletListItem{
205205
Level: 0,
206-
Text: fmt.Sprintf("%s: (%s)", rule.Id, rule.Name),
206+
Text: fmt.Sprintf("%s: (%s)", rule.Id, rule.Description),
207207
TextStyle: pterm.NewStyle(pterm.FgLightMagenta),
208208
BulletStyle: pterm.NewStyle(pterm.FgLightCyan),
209209
Bullet: fmt.Sprintf("► %s[%d]", sp, x),

plugin/plugin_loader.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ func LoadFunctions(path string, silence bool) (*Manager, error) {
8484
// register core functions with this custom function.
8585
RegisterCoreFunctions(function)
8686

87-
// register this function with the plugin manager
88-
pm.RegisterFunction(fName, function)
87+
// register this function with the plugin manager using the schema name
88+
schemaName := function.GetSchema().Name
89+
pm.RegisterFunction(schemaName, function)
8990

9091
if !silence {
91-
pterm.Info.Printf("Registered custom function: '%s' -> available for use in rulesets\n", fName)
92+
pterm.Info.Printf("Registered custom function: '%s' -> available for use in rulesets\n", schemaName)
9293
}
9394
}
9495
}

plugin/sample/js/check_for_name_and_id.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// Copyright 2023 Princess Beef Heavy Industries / Dave Shanley.
22
// SPDX-License-Identifier: MIT
33

4+
function getSchema() {
5+
return {
6+
"name": "checkForNameAndId",
7+
"description": "Checks that input has the correct name and id values"
8+
};
9+
}
10+
411
function runRule(input) {
512

613
// create an array to hold the results

plugin/sample/js/use_core_function.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// Copyright 2023 Princess Beef Heavy Industries / Dave Shanley.
22
// SPDX-License-Identifier: MIT
33

4+
function getSchema() {
5+
return {
6+
"name": "useCoreFunction",
7+
"description": "Demonstrates using a vacuum core function within a custom JavaScript function"
8+
};
9+
}
10+
411
function runRule(input) {
512

613
// create an array to hold the results

plugin/sample/js/use_function_options.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// Copyright 2023 Princess Beef Heavy Industries / Dave Shanley.
22
// SPDX-License-Identifier: MIT
33

4+
function getSchema() {
5+
return {
6+
"name": "useFunctionOptions",
7+
"description": "Demonstrates how to use function options passed from rulesets"
8+
};
9+
}
10+
411
function runRule(input) {
512
// extract function options from context
613
const functionOptions = context.ruleAction.functionOptions

plugin/sample/js/useless_func.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
function getSchema() {
55
return {
6-
"name": "useless_func_modified_name",
6+
"name": "uselessFunc",
7+
"description": "A demo function that always returns multiple messages regardless of input",
78
"properties": [
89
{
910
"name": "mickey",

rulesets/examples/sample-plugin-ruleset.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rules:
88
formats: [oas2, oas3]
99
given: $
1010
then:
11-
function: useless_func
11+
function: uselessFunc
1212
howToFix: You can't, it's just an example.
1313
sample-paths-rule:
1414
description: Load a custom function that checks for a single path
@@ -17,5 +17,5 @@ rules:
1717
formats: [ oas2, oas3 ]
1818
given: $.paths
1919
then:
20-
function: check_single_path
20+
function: checkSinglePath
2121
howToFix: use a spec with only a single path defined.

0 commit comments

Comments
 (0)