Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.

Commit 2383f4d

Browse files
sapientpantsclaude
andauthored
refactor: improve code quality by addressing SonarQube code smells (#336)
* refactor: improve code quality by addressing SonarQube code smells This commit addresses 7 code smell issues identified by SonarQube: - src/domains/base.ts:48: Use String#replaceAll() instead of replace() - src/domains/system.ts:46: Use for...of instead of forEach() for better performance - src/utils/pattern-matcher.ts:35-37: Use String#replaceAll() and String.raw for cleaner code Changes: - Replaced regex-based replace() calls with replaceAll() for better readability - Converted forEach() to for...of loop for improved performance - Used String.raw template literal to avoid unnecessary escaping All tests passing (1012/1012). Technical debt reduced by 30 minutes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * chore: add changeset for code quality improvements * fix: use string literals instead of regex for simple character replacements SonarCloud flagged that replaceAll() with simple character patterns should use string literals instead of regex for better performance and readability. Changes: - src/utils/pattern-matcher.ts:36: Changed /\*/g to '*' - src/utils/pattern-matcher.ts:37: Changed /\?/g to '?' This resolves 2 new code smells introduced in the previous commit and should improve the SonarCloud quality gate status. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: use conventional string escaping instead of String.raw Addressed Copilot review feedback. While both String.raw and conventional escaping produce identical results, using '\$&' is more conventional and clearer for replacement patterns in replaceAll(). This improves code maintainability without changing functionality. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 161452d commit 2383f4d

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'sonarqube-mcp-server': patch
3+
---
4+
5+
refactor: improve code quality by addressing SonarQube code smells
6+
7+
Improved code readability and maintainability by addressing 7 code smell issues:
8+
9+
- Use `String#replaceAll()` instead of `replace()` with global regex for better clarity
10+
- Convert `forEach()` to `for...of` loop for improved performance and readability
11+
- Use `String.raw` template literal to avoid unnecessary escaping in regex patterns
12+
13+
These changes follow modern JavaScript/TypeScript best practices and reduce technical debt by 30 minutes. No functional changes or breaking changes introduced.

src/domains/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export abstract class BaseDomain {
4545
});
4646

4747
// Wrap operation with circuit breaker
48-
const breakerName = `sonarqube.${endpoint.replace(/\//g, '.')}`;
48+
const breakerName = `sonarqube.${endpoint.replaceAll('/', '.')}`;
4949
const wrappedOperation = wrapWithCircuitBreaker(breakerName, retryableOperation, {
5050
timeout: 30000, // 30 seconds
5151
errorThresholdPercentage: 50,

src/domains/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ export class SystemDomain extends BaseDomain {
4343
}
4444

4545
const causes: string[] = [];
46-
nodes.forEach((node) => {
46+
for (const node of nodes) {
4747
if (node.causes) {
4848
causes.push(...node.causes);
4949
}
50-
});
50+
}
5151

5252
return causes;
5353
}

src/utils/pattern-matcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export class PatternMatcher {
3232
private globToRegex(pattern: string): RegExp {
3333
// Escape all regex special characters except * and ?
3434
const escaped = pattern
35-
.replace(/[\\^$.()|[\]{}+]/g, '\\$&') // Escape regex special chars
36-
.replace(/\*/g, '.*') // * matches any sequence
37-
.replace(/\?/g, '.'); // ? matches any single character
35+
.replaceAll(/[\\^$.()|[\]{}+]/g, '\\$&') // Escape regex special chars
36+
.replaceAll('*', '.*') // * matches any sequence
37+
.replaceAll('?', '.'); // ? matches any single character
3838

3939
// Create regex with anchors for full string matching
4040
return new RegExp(`^${escaped}$`);

0 commit comments

Comments
 (0)