fix: prefer optional chaining over logical AND guards (S6582)#3485
fix: prefer optional chaining over logical AND guards (S6582)#3485kasya merged 2 commits intoOWASP:mainfrom
Conversation
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughReplaces logical AND guards ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/src/app/chapters/page.tsx (1)
91-107: Inconsistent null-safety:chapters.lengthon line 91 vs optional chaining on line 105.If
chapterscan beundefinedornull, line 91 (chapters.length > 0) will throw aTypeErrorbefore the optional chaining on line 105 is ever reached. Conversely, ifuseSearchPagealways returns an array, the optional chaining is unnecessary (though harmless).For consistency, consider one of these approaches:
- If
chapterscan be nullish:{(chapters?.length ?? 0) > 0 && (...)}- If
chaptersis always an array: the?.on line 105 is safe but redundantAlso, the indentation on lines 106-107 appears slightly off.
Suggested fix if chapters can be nullish
- {chapters.length > 0 && ( + {(chapters?.length ?? 0) > 0 && ( <ChapterMapWrapper ... /> )} - {chapters - ?.filter((chapter) => chapter.isActive) - .map(renderChapterCard)} + {chapters?.filter((chapter) => chapter.isActive).map(renderChapterCard)}
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3485 +/- ##
==========================================
- Coverage 85.60% 85.60% -0.01%
==========================================
Files 461 461
Lines 14222 14221 -1
Branches 1894 1892 -2
==========================================
- Hits 12175 12174 -1
Misses 1678 1678
Partials 369 369
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
kasya
left a comment
There was a problem hiding this comment.
@anukalp2804 thanks for updating this!
Please run make check-test next time before pushing changes 👍🏼



Proposed change
Resolves #3472
This PR addresses SonarCloud rule
typescript:S6582by replacing logical AND guards with optional chaining in multiple components.The change improves readability and maintainability while preserving existing behavior.
Checklist