Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use sprig functions in analyzer templates #1745

Merged
merged 3 commits into from
Feb 21, 2025

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
Member

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.

3 participants