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

fix(30216): Add more docs for must version of functions #1698

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DerekTBrown
Copy link

Copy link
Contributor

@TerryHowe TerryHowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a maintainer, but there are some changes that need to happen here, thanks!

@@ -857,18 +857,38 @@ Helm includes the following regular expression functions: [regexFind
(mustRegexReplaceAllLiteral)](#regexreplaceallliteral-mustregexreplaceallliteral),
[regexSplit (mustRegexSplit)](#regexsplit-mustregexsplit).

### regexMatch, mustRegexMatch
### regexMatch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are links above and this change breaks that. I don't think you should change the headers or add the ### mustRegexMatch header here.

Comment on lines +871 to +882
`regexMatch` will ignore regex compilation errors, and simply return `false` ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L7))

```
{{- if regexMatch "[" "abc" -}}
valid: true
{{- end -}}
```
The above produces nothing.

### mustRegexMatch

Similar to `regexMatch`, but will return an error to the templating engine if the regex fails to compile:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`regexMatch` will ignore regex compilation errors, and simply return `false` ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L7))
```
{{- if regexMatch "[" "abc" -}}
valid: true
{{- end -}}
```
The above produces nothing.
### mustRegexMatch
Similar to `regexMatch`, but will return an error to the templating engine if the regex fails to compile:
In the event of regex compilation errors, `regexMatch` will simply return `false`.
Use `mustRegexMatch` to fail in the event of regex compilation errors.

@@ -885,7 +905,7 @@ The above produces `[2 4 6 8]`
`regexFindAll` panics if there is a problem and `mustRegexFindAll` returns an
error to the template engine if there is a problem.

### regexFind, mustRegexFind
### regexFind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### regexFind
### regexFind, mustRegexFind

Comment on lines +918 to +919
`regexFind` will result in a panic if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L30)), whereas
`mustRegexFind` will return an error to the templating engine if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L34)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these references are going to be brittle

Suggested change
`regexFind` will result in a panic if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L30)), whereas
`mustRegexFind` will return an error to the templating engine if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L34)).
The `regexFind` function will result in a panic if the regex fails to compile, whereas
`mustRegexFind` will return an error to the templating engine if the regex fails to compile.

`regexFind` will result in a panic if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L30)), whereas
`mustRegexFind` will return an error to the templating engine if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L34)).

Note that neither function will panic/return an error if the input string does not match the regex. Both functions return an empty string in this case:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project doesn't strictly use semantic line breaks, but I think it helps.

Suggested change
Note that neither function will panic/return an error if the input string does not match the regex. Both functions return an empty string in this case:
Note that neither function will panic/return an error if the input string does not match the regex.
Both functions return an empty string in this case:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants