Repository navigation
Description
Summary
no-dynamic-string-replacement's isDynamic() helper (eslint-factory/src/rules/no-dynamic-string-replacement.ts:137-164) treats every bare Identifier replacement argument as dynamic:
case "Identifier":
return expression.name !== "undefined";It never resolves the identifier back to its declaration the way the rule's own sibling helpers already do. isKnownFunction (lines 81-135) and isDefinitelyNonFunction (lines 166-197) both call resolveVariable/getVariableInitializer to trace a single-definition const binding back to its initializer before deciding — isDynamic has no equivalent step for its Identifier case, so a const bound to a plain string literal is indistinguishable from a genuinely runtime-computed value.
Live grounding (1 site, actions/setup/js/send_otlp_span.cjs)
// send_otlp_span.cjs:1062
const REDACTED = "[REDACTED]";
...
// send_otlp_span.cjs:1141
.replace((bhttps/redacted)?:\/\/[^\s"'`<>]+/gi, REDACTED)REDACTED is a single-definition module-scope const whose initializer is the literal "[REDACTED]" (no $ characters at all, so there is zero actual replacement-pattern risk). The pattern argument is a regex literal (isRegexLiteral is true), so the call passes the rule's method/argument-count/pattern gates, then isDynamic(replacement) returns true purely because REDACTED is an Identifier, not "undefined" — a false positive on a provably-safe, non-varying constant.
Because isDefinitelyNonFunction does resolve the same identifier back to a Literal initializer and returns true, and hasStaticReplacementToken has no Identifier case (defaults to false), the rule also offers a "wrap in a replacer function" suggestion here — busywork that doesn't change behavior, since the value is a fixed, $-free string.
Suggested fix
Give isDynamic's Identifier branch the same one-hop (or resolving-guarded recursive) initializer resolution already used by isKnownFunction/isDefinitelyNonFunction: if the identifier resolves to a single-definition const whose initializer is itself non-dynamic per isDynamic (e.g. a Literal/static TemplateLiteral), treat it as non-dynamic instead of unconditionally dynamic.
Acceptance criteria
-
const REDACTED = "[REDACTED]"; s.replace(/x/g, REDACTED);is not flagged. - Reassigned bindings remain flagged:
let value = "ok"; value = input; s.replace(/x/g, value);(existing invalid test case atno-dynamic-string-replacement.test.ts:64-67) must still fire. - A
constwhose initializer does contain$(e.g.const R = "$1";) still fires, since the risk is in the literal's content, not just its mutability. - A
constinitialized from a non-literal expression (e.g.const x = foo();) remains flagged as dynamic. - New test cases added to
no-dynamic-string-replacement.test.tscovering the traceable-literal-constant shape (valid) alongside the existing reassigned-binding shape (invalid).
Generated by 🤖 ESLint Refiner · claude · agent · ~122 AIC · ⌖ ~1 AIC · ⊞ 4.2K · ◷
Claim finished
- expires on Nov 13, 2026, 7:34 PM UTC-08:00
Activity
github-actions commentedon Nov 7, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, Copilot will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪