Skip to content

Conversation

@sgalsaleh
Copy link
Member

@sgalsaleh sgalsaleh commented Feb 21, 2025

Description, Motivation and Context

This change adds support for using Sprig template functions in analyzer templates. The Sprig library provides a comprehensive set of template functions that are commonly used in Go templating, which will give users more flexibility and power when writing analyzer templates.

Checklist

  • New and existing tests pass locally with introduced changes.
  • Tests for the changes have been added (for bug fixes / features)
  • The commit message(s) are informative and highlight any breaking changes
  • Any documentation required has been added/updated.

Does this PR introduce a breaking change?

  • Yes
  • No

@sgalsaleh sgalsaleh added the type::feature New feature or request label Feb 21, 2025
@sgalsaleh sgalsaleh requested a review from laverya February 21, 2025 00:10
@sgalsaleh sgalsaleh requested a review from a team as a code owner February 21, 2025 00:10
@jtuchscherer
Copy link

jtuchscherer commented Feb 21, 2025

I am always going to advocate for adding a unit :-)
Something like this in util_test.go:

		{
			name:    "template with sprig function works",
			tpl:     "{{ \"hello \" | upper }}{{ .Name }}",
			data:    map[string]string{"Name": "World"},
			want:    "HELLO World",
			wantErr: false,
		},
		{
			name:    "template with undefined sprig function errors",
			tpl:     "{{ \"hello \" | upp }}{{ .Name }}",
			data:    map[string]string{"Name": "World"},
			want:    "",
			wantErr: true,
		},

(I tried this locally)

@sgalsaleh sgalsaleh merged commit 97dcae9 into main Feb 21, 2025
22 checks passed
@sgalsaleh sgalsaleh deleted the ability-to-use-sprig-funcs-in-analyzer-templates branch February 21, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type::feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants