Skip to content

Replace String#replace() with String#replaceAll() in context-menu.js#681

Merged
manusa merged 2 commits intomainfrom
copilot/fix-replace-method-issue
Nov 6, 2025
Merged

Replace String#replace() with String#replaceAll() in context-menu.js#681
manusa merged 2 commits intomainfrom
copilot/fix-replace-method-issue

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

Sonar flagged the use of String#replace() with a global regex pattern on line 31 of src/service-manager/context-menu.js, recommending the modern String#replaceAll() for clarity.

Changes

  • Replaced .replace(/[:.]/g, '-') with .replaceAll(':', '-').replaceAll('.', '-') in the timestamp generation logic
// Before
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').split('T').join('-').split('-').slice(0, 6).join('');

// After
const timestamp = new Date().toISOString().replaceAll(':', '-').replaceAll('.', '-').split('T').join('-').split('-').slice(0, 6).join('');

Behavior is identical; all existing tests pass without modification.

Original prompt

Sonar has reported some issues in:
src/service-manager/context-menu.js

The issue is:
Prefer String#replaceAll() over String#replace().

The problem is in multiple lines: L31


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: manusa <488391+manusa@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix preference for String#replaceAll over String#replace Replace String#replace() with String#replaceAll() in context-menu.js Nov 5, 2025
Copilot AI requested a review from manusa November 5, 2025 10:18
@manusa manusa added this to the 0.1.0 milestone Nov 6, 2025
@manusa manusa marked this pull request as ready for review November 6, 2025 05:45
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 6, 2025

@manusa manusa merged commit 1c8fc86 into main Nov 6, 2025
9 of 10 checks passed
@manusa manusa deleted the copilot/fix-replace-method-issue branch November 6, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants