-
-
Notifications
You must be signed in to change notification settings - Fork 211
Refactor common logic in core.ts #928
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
base: develop
Are you sure you want to change the base?
Conversation
β Deploy Preview for livecodes ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
WalkthroughIntroduces Changes
Estimated code review effortπ― 2 (Simple) | β±οΈ ~10 minutes
Pre-merge checks and finishing touchesβ Passed checks (3 passed)
β¨ Finishing touches
π§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
π§Ή Nitpick comments (1)
src/livecodes/core.ts (1)
3133-3168: Excellent refactoring!The extraction of common menu setup logic into
setupAppMenu()successfully reduces code duplication and centralizes the menu initialization pattern. The function signature is clear, the default parametershouldAdjustFontSize = falsecorrectly maintains existing behavior, and the early null-check prevents errors.Optional: Consider using
replaceAll()for clarity.On line 3158, you could modernize the keyboard shortcut replacement:
- const html = isMac() ? menuHTML.replace(/<kbd>Ctrl<\/kbd>/g, '<kbd>β</kbd>') : menuHTML; + const html = isMac() ? menuHTML.replaceAll('<kbd>Ctrl</kbd>', '<kbd>β</kbd>') : menuHTML;This is clearer and avoids regex escaping, though the current implementation works correctly.
Note: The static analysis warning about
innerHTML(line 3160) is a false positiveβthe HTML content originates from trusted internal constants (menuProjectHTML,menuSettingsHTML,menuHelpHTML) imported from./html, not user input.
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (1)
src/livecodes/core.ts(1 hunks)
π§° Additional context used
𧬠Code graph analysis (1)
src/livecodes/core.ts (2)
src/livecodes/html/index.ts (3)
menuProjectHTML(128-128)menuSettingsHTML(129-129)menuHelpHTML(127-127)src/livecodes/utils/utils.ts (1)
isMac(70-71)
πͺ ast-grep (0.40.0)
src/livecodes/core.ts
[warning] 3159-3159: Direct modification of innerHTML or outerHTML properties detected. Modifying these properties with unsanitized user input can lead to XSS vulnerabilities. Use safe alternatives or sanitize content first.
Context: container.innerHTML = html
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://owasp.org/www-community/xss-filter-evasion-cheatsheet
- https://cwe.mitre.org/data/definitions/79.html
(dom-content-modification)
[warning] 3159-3159: Direct HTML content assignment detected. Modifying innerHTML, outerHTML, or using document.write with unsanitized content can lead to XSS vulnerabilities. Use secure alternatives like textContent or sanitize HTML with libraries like DOMPurify.
Context: container.innerHTML = html
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://www.dhairyashah.dev/posts/why-innerhtml-is-a-bad-idea-and-how-to-avoid-it/
- https://cwe.mitre.org/data/definitions/79.html
(unsafe-html-content-assignment)
πͺ GitHub Check: SonarCloud Code Analysis
src/livecodes/core.ts
[warning] 3158-3158: Prefer String#replaceAll() over String#replace().
β° Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Redirect rules - livecodes
- GitHub Check: Header rules - livecodes
- GitHub Check: Pages changed - livecodes
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: tests (24.x, 4)
- GitHub Check: tests (24.x, 5)
- GitHub Check: tests (24.x, 2)
- GitHub Check: tests (24.x, 3)
- GitHub Check: tests (24.x, 1)
- GitHub Check: build (24.x)
- GitHub Check: build
|



What type of PR is this? (check all applicable)
Description
handleAppMenuProject,handleAppMenuSettings,handleAppMenuHelpintosetupAppMenu()handleResultPopup,handleResultZoomandhandleBroadcastStatusThis is a very small change (it only reduced line count by 1 :) ) but it's a first step towards refactoring core.ts
Related Tickets & Documents
Mobile & Desktop Screenshots/Recordings
Added tests?
Added to documentations?
[optional] Are there any post-deployment tasks we need to perform?
[optional] What gif best describes this PR or how it makes you feel?
Summary by CodeRabbit
βοΈ Tip: You can customize this high-level summary in your review settings.