Skip to content

fix: refactor nested template literals in exposedMetricsChallenge#20

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

fix: refactor nested template literals in exposedMetricsChallenge#20
sonarqube-agent[bot] wants to merge 1 commit intomasterfrom
remediate-master-20260330-075801-b94d8683

Conversation

@sonarqube-agent
Copy link
Copy Markdown

Removed nested template literals in the metrics challenge code to improve readability and comply with SonarQube best practices. The fix extracts the inner expression into a separate variable, making the code cleaner and 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:21

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 fixes the nested template literals code smell. The original code had a nested template literal (${process.env.BASE_PATH}) inside the outer template literal passed to colors.cyan(...). The fix extracts the inner expression into a separate variable basePath using colors.bold(String(process.env.BASE_PATH)), and then references that variable in the outer template literal. This eliminates the nesting of template literals, improving readability as recommended by the rule.

--- a/data/static/codefixes/exposedMetricsChallenge_3_correct.ts
+++ b/data/static/codefixes/exposedMetricsChallenge_3_correct.ts
@@ -21,1 +21,2 @@ export async function start (readyCallback: any) {
-      logger.info(colors.cyan(`Server using proxy base path ${colors.bold(`${process.env.BASE_PATH}`)} for redirects`))
+      const basePath = colors.bold(String(process.env.BASE_PATH))
+      logger.info(colors.cyan(`Server using proxy base path ${basePath} for redirects`))

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


SonarQube Remediation Agent uses AI. Check for mistakes.

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

Generated by SonarQube Agent (task: 2eb5178a-4182-40d3-913f-3ebb86ef47d2)
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