Skip to content

Refactor: Replace negated conditions with positive checks#3274

Merged
arkid15r merged 4 commits intoOWASP:mainfrom
saniyafatima07:san
Jan 10, 2026
Merged

Refactor: Replace negated conditions with positive checks#3274
arkid15r merged 4 commits intoOWASP:mainfrom
saniyafatima07:san

Conversation

@saniyafatima07
Copy link
Contributor

@saniyafatima07 saniyafatima07 commented Jan 10, 2026

Proposed change

Resolves #3231

Changed the negated condition checks in the files to positive conditions.

It includes:
frontend/src/components/ModuleCard.tsx
frontend/src/components/SearchPageLayout.tsx
frontend/src/app/board/[year]/candidates/page.tsx
frontend/src/components/CardDetailsPage.tsx

Checklist

  • Required: I read and followed the contributing guidelines
  • Required: I ran make check-test locally and all tests passed
  • I used AI for code, documentation, or tests in this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 10, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Fixed pluralization of labels in leadership section ("chapter"/"chapters", "project"/"projects")
    • Corrected duration pluralization display ("week"/"weeks")
    • Improved loading state behavior to properly display skeleton loader while content is loading
    • Enhanced null/undefined value handling in details display

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Rewrote several inverted conditionals in four frontend components to use positive checks: pluralization labels in candidates page and ModuleCard, a null-check-to-string expression in CardDetailsPage, and the loaded/unloaded rendering branch in SearchPageLayout. No exported signatures were changed. (49 words)

Changes

Cohort / File(s) Summary
Candidates leadership pluralization
frontend/src/app/board/[year]/candidates/page.tsx
Flipped pluralization checks to use === 1 for singular labels (chapter / project) instead of !== 1.
Module duration pluralization
frontend/src/components/ModuleCard.tsx
Adjusted suffix logic to weeks === 1 ? '' : 's' for singular/plural handling.
Detail value null-check
frontend/src/components/CardDetailsPage.tsx
Inverted null-check to detail?.value == null ? 'Unknown' : String(detail.value) (observable behavior unchanged).
Loaded-state rendering
frontend/src/components/SearchPageLayout.tsx
Reordered conditional to render main content when isLoaded is true and SkeletonBase when false (control flow clarified).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • kasya
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing negated conditions with positive checks across multiple frontend components.
Description check ✅ Passed The description clearly outlines the proposed changes, references issue #3231, lists all affected files, and confirms testing was completed.
Linked Issues check ✅ Passed All code changes in the four affected files directly address issue #3231 by converting negated conditions to positive equivalents while maintaining identical observable behavior.
Out of Scope Changes check ✅ Passed All changes are focused on the objective of replacing negated conditions with positive checks; no unrelated modifications or scope creep detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 926e8ee and 96048e4.

📒 Files selected for processing (3)
  • frontend/src/components/CardDetailsPage.tsx
  • frontend/src/components/ModuleCard.tsx
  • frontend/src/components/SearchPageLayout.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/ModuleCard.tsx
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-06-20T16:12:59.256Z
Learnt from: ahmedxgouda
Repo: OWASP/Nest PR: 1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a length check before rendering HealthMetrics: `healthMetricsData.length > 0`. This ensures that when HealthMetrics is rendered, the data array has at least one element, making accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/src/components/CardDetailsPage.tsx
📚 Learning: 2025-06-20T16:12:59.256Z
Learnt from: ahmedxgouda
Repo: OWASP/Nest PR: 1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a safety check that ensures HealthMetrics component is only rendered when healthMetricsData exists and has at least one element: `healthMetricsData && healthMetricsData.length > 0`. This makes accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/src/components/CardDetailsPage.tsx
⏰ 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). (3)
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend e2e tests
🔇 Additional comments (2)
frontend/src/components/CardDetailsPage.tsx (1)

162-162: LGTM! Condition successfully inverted to positive check.

The ternary refactoring correctly flips the null check to a positive condition, improving readability while preserving identical behavior. The use of == appropriately catches both null and undefined.

frontend/src/components/SearchPageLayout.tsx (1)

52-70: LGTM! Loading condition successfully refactored to positive check.

The conditional rendering is correctly inverted from !isLoaded to isLoaded, placing the positive case (content loaded) first. This improves readability while maintaining identical behavior—main content renders when loaded, skeleton shows when not loaded.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (2)
frontend/src/components/SearchPageLayout.tsx (1)

52-70: Conditional logic correctly inverted, but fix formatting.

The change successfully replaces the negated condition with a positive check. However, there's a minor formatting inconsistency on line 68.

✨ Formatting improvement
-      ):(
+      ) : (
         <SkeletonBase indexName={indexName} loadingImageUrl={loadingImageUrl} />

Add a space before the colon and after the closing parenthesis for consistency with standard formatting conventions.

frontend/src/components/CardDetailsPage.tsx (1)

162-162: Conditional logic correctly inverted, but fix spacing.

The change successfully inverts the condition to check for null/undefined first. However, there's a minor spacing issue in the ternary operator.

✨ Formatting improvement
-                  <LeadersList leaders={detail?.value == null ? 'Unknown': String(detail.value)} />
+                  <LeadersList leaders={detail?.value == null ? 'Unknown' : String(detail.value)} />

Add a space before the colon in the ternary operator for consistency with standard formatting conventions.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6471c8b and 4c9f77e.

📒 Files selected for processing (4)
  • frontend/src/app/board/[year]/candidates/page.tsx
  • frontend/src/components/CardDetailsPage.tsx
  • frontend/src/components/ModuleCard.tsx
  • frontend/src/components/SearchPageLayout.tsx
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-06-20T16:12:59.256Z
Learnt from: ahmedxgouda
Repo: OWASP/Nest PR: 1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a length check before rendering HealthMetrics: `healthMetricsData.length > 0`. This ensures that when HealthMetrics is rendered, the data array has at least one element, making accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/src/components/CardDetailsPage.tsx
📚 Learning: 2025-06-20T16:12:59.256Z
Learnt from: ahmedxgouda
Repo: OWASP/Nest PR: 1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a safety check that ensures HealthMetrics component is only rendered when healthMetricsData exists and has at least one element: `healthMetricsData && healthMetricsData.length > 0`. This makes accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/src/components/CardDetailsPage.tsx
🔇 Additional comments (2)
frontend/src/components/ModuleCard.tsx (1)

110-110: LGTM! Pluralization logic improved with positive condition.

The change correctly inverts the condition to check for the singular case first (weeks === 1), making the logic more readable and aligning with the PR objective of replacing negated conditions.

frontend/src/app/board/[year]/candidates/page.tsx (1)

480-480: LGTM! Pluralization logic improved with positive conditions.

Both changes correctly invert the conditions to check for the singular case first (=== 1), making the pluralization logic more readable and consistent with the PR objective.

Also applies to: 486-486

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 10, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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)
frontend/src/components/CardDetailsPage.tsx (1)

162-162: Logic is correct; minor formatting and optional modern syntax suggestion.

The refactoring successfully replaces the negated condition with a positive check, meeting the PR objectives. The logic is functionally equivalent and uses the "error-first" pattern which some find more readable.

Minor formatting issue: Missing space after 'Unknown' before the colon in the ternary operator. Standard formatting would be:

detail?.value == null ? 'Unknown' : String(detail.value)

This will likely be caught by your formatter (Prettier, ESLint, etc.) when running make check-test.

Optional modern alternative: Consider using the nullish coalescing operator for more idiomatic TypeScript:

String(detail?.value ?? 'Unknown')

This is more concise and eliminates the ternary entirely.

♻️ Optional: Modern nullish coalescing syntax
-                  <LeadersList leaders={detail?.value == null ? 'Unknown': String(detail.value)} />
+                  <LeadersList leaders={String(detail?.value ?? 'Unknown')} />
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c9f77e and 926e8ee.

📒 Files selected for processing (1)
  • frontend/src/components/CardDetailsPage.tsx
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-06-20T16:12:59.256Z
Learnt from: ahmedxgouda
Repo: OWASP/Nest PR: 1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a length check before rendering HealthMetrics: `healthMetricsData.length > 0`. This ensures that when HealthMetrics is rendered, the data array has at least one element, making accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/src/components/CardDetailsPage.tsx
📚 Learning: 2025-06-20T16:12:59.256Z
Learnt from: ahmedxgouda
Repo: OWASP/Nest PR: 1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a safety check that ensures HealthMetrics component is only rendered when healthMetricsData exists and has at least one element: `healthMetricsData && healthMetricsData.length > 0`. This makes accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/src/components/CardDetailsPage.tsx

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

You didn't run the required code quality checks. Your future issue assignment requests will be de-prioritized.

@arkid15r arkid15r enabled auto-merge January 10, 2026 18:13
@sonarqubecloud
Copy link

@arkid15r arkid15r added this pull request to the merge queue Jan 10, 2026
Merged via the queue into OWASP:main with commit 3c1138e Jan 10, 2026
27 checks passed
hussainjamal760 pushed a commit to hussainjamal760/Nest that referenced this pull request Jan 14, 2026
* Refactor: Replace negated conditions with positive checks

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>
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.

Unexpected negated condition

2 participants