-
-
Notifications
You must be signed in to change notification settings - Fork 395
refactor-replace-with-replaceAll #2526
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
Conversation
Summary by CodeRabbit
WalkthroughReplaced uses of String.prototype.replace() that applied global regexes with String.prototype.replaceAll() across tests, components, utilities, and a page; no public API or behavior-introducing logic changes were made. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 (9)
frontend/src/utils/slugify.ts (1)
4-5: Consider removing redundant global flags.The changes correctly migrate to
replaceAll(), but thegflag is now redundant sincereplaceAll()always replaces all occurrences by default.Apply this diff to remove the redundant flags:
- .replaceAll(/[\u0300-\u036F]/g, '') // Remove diacritics - .replaceAll(/[^a-zA-Z0-9]+/g, '-') // Replace non-alphanumeric with hyphens + .replaceAll(/[\u0300-\u036F]/, '') // Remove diacritics + .replaceAll(/[^a-zA-Z0-9]+/, '-') // Replace non-alphanumeric with hyphensfrontend/src/components/BreadCrumbs.tsx (1)
46-46: Consider removing redundant global flag.The migration to
replaceAll()is correct, but thegflag is redundant.Apply this diff:
- const label = upperFirst(segment).replaceAll(/-/g, ' ') + const label = upperFirst(segment).replaceAll(/-/, ' ')frontend/src/components/Badges.tsx (1)
19-19: Consider removing redundant global flag.The refactor to
replaceAll()is correct, but thegflag is redundant.Apply this diff:
- return cssClass.trim().replaceAll(/_([a-z])/g, (_, letter) => letter.toUpperCase()) + return cssClass.trim().replaceAll(/_([a-z])/, (_, letter) => letter.toUpperCase())frontend/__tests__/unit/pages/UserDetails.test.tsx (1)
44-44: Consider removing redundant global flag.The migration to
replaceAll()is correct, but thegflag is redundant.Apply this diff:
- data-testid={`badge-${name.toLowerCase().replaceAll(/\s+/g, '-')}`} + data-testid={`badge-${name.toLowerCase().replaceAll(/\s+/, '-')}`}frontend/__tests__/unit/components/MarkdownWrapper.test.tsx (1)
14-15: Consider removing redundant global flags.The migration to
replaceAll()is correct, but thegflags are redundant.Apply this diff:
return content - .replaceAll(/\*\*(.*?)\*\*/g, '<strong>$1</strong>') - .replaceAll(/\[(.*?)\]\((.*?)\)/g, '<a href="$2">$1</a>') + .replaceAll(/\*\*(.*?)\*\*/, '<strong>$1</strong>') + .replaceAll(/\[(.*?)\]\((.*?)\\)/, '<a href="$2">$1</a>')frontend/src/app/board/[year]/candidates/page.tsx (2)
192-192: Consider removing redundant global flag.The migration to
replaceAll()is correct, but thegflag is redundant.Apply this diff:
- const nameSlug = candidate.memberName.toLowerCase().replaceAll(/\s+/g, '_') + const nameSlug = candidate.memberName.toLowerCase().replaceAll(/\s+/, '_')
298-298: Consider removing redundant global flags.The migration to
replaceAll()is correct, but thegflags are redundant.Apply this diff:
- {candidate.member.bio.replaceAll(/\n+/g, ' ').replaceAll(/\s+/g, ' ').trim()} + {candidate.member.bio.replaceAll(/\n+/, ' ').replaceAll(/\s+/, ' ').trim()}frontend/__tests__/unit/components/AnchorTitle.test.tsx (2)
14-16: Consider removing redundant global flags.The migration to
replaceAll()is correct, but thegflags are redundant.Apply this diff:
str .toLowerCase() - .replaceAll(/[^a-z0-9]/g, '-') - .replaceAll(/-{2,10}/g, '-') - .replaceAll(/(^-{1,10}|-{1,10}$)/g, '') + .replaceAll(/[^a-z0-9]/, '-') + .replaceAll(/-{2,10}/, '-') + .replaceAll(/(^-{1,10}|-{1,10}$)/, '')
655-657: Consider removing redundant global flags.The migration to
replaceAll()is correct, but thegflags are redundant (consistent with the mock at lines 14-16).Apply this diff:
str .toLowerCase() - .replaceAll(/[^a-z0-9]/g, '-') - .replaceAll(/-{2,10}/g, '-') - .replaceAll(/(^-{1,10}|-{1,10}$)/g, '') + .replaceAll(/[^a-z0-9]/, '-') + .replaceAll(/-{2,10}/, '-') + .replaceAll(/(^-{1,10}|-{1,10}$)/, '')
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
frontend/__tests__/unit/components/AnchorTitle.test.tsx(2 hunks)frontend/__tests__/unit/components/MarkdownWrapper.test.tsx(1 hunks)frontend/__tests__/unit/pages/UserDetails.test.tsx(1 hunks)frontend/src/app/board/[year]/candidates/page.tsx(2 hunks)frontend/src/components/Badges.tsx(1 hunks)frontend/src/components/BreadCrumbs.tsx(1 hunks)frontend/src/utils/slugify.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-07-12T17:36:57.255Z
Learnt from: Rajgupta36
Repo: OWASP/Nest PR: 1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.
Applied to files:
frontend/__tests__/unit/pages/UserDetails.test.tsx
📚 Learning: 2025-09-17T02:42:41.928Z
Learnt from: Rajgupta36
Repo: OWASP/Nest PR: 2288
File: frontend/src/components/ActionButton.tsx:0-0
Timestamp: 2025-09-17T02:42:41.928Z
Learning: In frontend/src/components/ActionButton.tsx, the user Rajgupta36 intentionally changed text-blue-600 to text-[#1D7BD7] to align the text color with the border color (#1D7BD7) for visual consistency, prioritizing design alignment over theme tokens.
Applied to files:
frontend/src/components/Badges.tsx
kasya
left a 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.
@kart-u thanks for working on this! 👍🏼 Looks good!
p.s. Pushed tiny update to get rid of regex with global flag in one place.
|



Proposed change
Resolves #2519
Refactored
string#replace()withstring#replaceAll()at places wherereplacewas used with global regex ensuring compliance with the corresponding SonarQube rule S7781Checklist
make check-testlocally; all checks and tests passed.