-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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: Opening statement shortcuts can only handle one issue #2186
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -47,7 +47,7 @@ const prologue = computed(() => { | |||
let result = temp | |||
for (const index in quick_question_list) { | |||
const quick_question = quick_question_list[index] | |||
result = temp.replace(quick_question, toQuickQuestion) | |||
result = result.replace(quick_question, toQuickQuestion) | |||
} | |||
return result | |||
} |
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.
The function you provided looks mostly correct and should work efficiently. Here's a couple of minor improvements:
- Use
Array.prototype.includes
Instead: This can make your loop more concise and potentially faster if there are many common values inquick_question_list
.
for (const index in quick_question_list) {
const quick_question = quick_question_list[index];
if (!toQuickQuestion[quick_question]) continue; // Only replace existing keys
result = result.replace(quick_question, toQuickQuestion);
}
-
Error Handling: Consider adding error handling, particularly checking if either
temp
,quick_question_list
, ortoQuickQuestion
is undefined. -
Performance: If
toQuickQuestion
becomes very large, creating new strings with each replacement might be inefficient. You could instead use a regular expression to construct the final string all at once.
function toFinalText(template) {
return template.split(RegExp(
quick_question_list.map(qq => qq.escapeForRegex()).join('|')
)).map(text => text || '').join('');
}
// In your setupComputed method
let final_text_temp;
computed(() => {
final_text_temp = [...quick_question_list].reduce((accumulator, key) => ({
...accumulator,
[key]: 'replace_this_with_suggested_value' // Replace with actual default value
}), {});
return toFinalText(template);
});
This approach creates an object final_text_temp
initialized with placeholders (replace_this_with_suggested_value
) for each key in quick_question_list
. The RegExp
then uses these keys to split the template and join them using empty strings when no match is found (''). After constructing this, it iterates over the keys again to perform replacements.
These suggestions aim to enhance readability and performance while maintaining correct functionality for most scenarios.
fix: Opening statement shortcuts can only handle one issue