-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use a new vars template implementation #19156
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
PR: (now it has a separate PR 19284) Changes:
Maybe the title of this PR could be changed accordingly: |
3a3b5ee
to
fe2f1ed
Compare
|
Why can not the refactoring of the legacy
Strict mode doesn't work here because reason 3
How about there is some And
I never hide errors, I always output them. But in some cases they should not be shown to users in the web, for example, issue URL rendering or README rendering.
Hmm .... so many PRs, then no PRs.
IIRC other maintainers have talked about we should avoid force-pushing when review starts. |
} | ||
} | ||
|
||
if len(match) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why is that an error case? I strongly disagree that not finding the corresponding variable should return an error.
- Even if I count that as an error case, it is an unnecessary one as that will already be tested down below with the
v, ok := match[template[keyStartPos+1:i]]
implicitly. - Even more so, it is implemented incorrectly as it disregards the positional arguments.
return "", err | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, there is an edge case missing, as an unclosed parentheses at the end (i.e. test {template end
as template) would not throw a syntax error.
fail: true, | ||
}, | ||
{ | ||
template: "expand }, {b} and {c}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, the other case is currently missing.
} | ||
|
||
// Expand replaces all variables like {var} to match | ||
func Expand(template string, match map[string]string, subs ...string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could save all the extra trouble with the positional arguments by using something like
func Expand(template string, match map[string]string, subs ...string) (string, error) { | |
// All positional arguments will be converted into corresponding map entries: match["x"] = subs[x]) | |
func Expand(template string, match map[string]string, subs ...string) (string, error) { | |
for index, substitution := range subs { | |
match[strconv.Itoa(index)] = substitution | |
} |
replaced by #19284 |
This PR reimplemented
Expand
inmodules/templates/vars
and replace all places.