Skip to content

Commit 71cef28

Browse files
authored
Add Template Functions (#45)
1 parent 0e08516 commit 71cef28

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

cmd/codeownerslint/linter.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"path/filepath"
7+
"strings"
78
"text/template"
89

910
"github.com/fmenezes/codeowners"
@@ -38,7 +39,10 @@ func run(wr io.Writer, opt options) exitCode {
3839
format = opt.format
3940
}
4041
format = fmt.Sprintf("%s\n", format)
41-
tpl, err := template.New("main").Parse(format)
42+
tpl, err := template.New("main").Funcs(template.FuncMap{
43+
"ToLower": strings.ToLower,
44+
"ToUpper": strings.ToUpper,
45+
}).Parse(format)
4246
if err != nil {
4347
fmt.Fprintf(wr, "Unexpected error when parsing format: %v", err)
4448
return unexpectedErrorCode

cmd/codeownerslint/linter_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ func TestCustomFormat(t *testing.T) {
5050
`)
5151
}
5252

53+
func TestCustomFormatFunc(t *testing.T) {
54+
assert(t, options{
55+
directory: "../../test/data/noowners",
56+
format: "{{ToLower .Position.FilePath}}",
57+
}, errorCode, `codeowners
58+
`)
59+
}
60+
5361
func TestInvalidFormatParse(t *testing.T) {
5462
assertCode(t, options{
5563
directory: "../../test/data/noowners",

0 commit comments

Comments
 (0)