Skip to content

fix: remove nested template literals in exposedMetricsChallenge_3_correct.ts#26

Open
sonarqube-agent[bot] wants to merge 1 commit intomasterfrom
remediate-master-20260330-075801-f5fabd2a
Open

fix: remove nested template literals in exposedMetricsChallenge_3_correct.ts#26
sonarqube-agent[bot] wants to merge 1 commit intomasterfrom
remediate-master-20260330-075801-f5fabd2a

Conversation

@sonarqube-agent
Copy link
Copy Markdown

Refactored nested template literals in exposedMetricsChallenge_3_correct.ts to improve code readability. Extracted the bold port formatting into a separate variable to eliminate the nested template literal pattern, resolving the SonarQube code smell issue and making the code easier to maintain.

View Project in SonarCloud


Fixed Issues

typescript:S4624 - Refactor this code to not use nested template literals. • MAJORView issue

Location: data/static/codefixes/exposedMetricsChallenge_3_correct.ts:18

Why is this an issue?

Template literals, also known as template strings, allow for string interpolation and multiline strings in JavaScript. They provide a more convenient and flexible way to work with strings compared to traditional string concatenation or manipulation.

What changed

This hunk directly fixes the nested template literal code smell reported at line 18 of exposedMetricsChallenge_3_correct.ts. The original code had colors.bold(${port}) nested inside colors.cyan(Server listening on port ${...}), creating a hard-to-read nested template literal. By extracting colors.bold(String(port)) into a separate variable boldPort and then referencing it as ${boldPort} in the outer template literal, the nesting is eliminated, improving readability and resolving the rule violation against nested template literals.

--- a/data/static/codefixes/exposedMetricsChallenge_3_correct.ts
+++ b/data/static/codefixes/exposedMetricsChallenge_3_correct.ts
@@ -18,1 +18,2 @@ export async function start (readyCallback: any) {
-    logger.info(colors.cyan(`Server listening on port ${colors.bold(`${port}`)}`))
+    const boldPort = colors.bold(String(port))
+    logger.info(colors.cyan(`Server listening on port ${boldPort}`))

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZWU-tYxYJSZqVQVbSdV for typescript:S4624 rule

Generated by SonarQube Agent (task: b01349c2-dd28-4008-8d48-a4ca06937306)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants