Skip to content

Resolve static replacement constants in no-dynamic-string-replacement - #75760

Merged
pelikhan merged 2 commits into
mainfrom
copilot/fix-no-dynamic-string-replacement
Nov 7, 2026
Merged

pelikhan merged 2 commits into
mainfrom
copilot/fix-no-dynamic-string-replacement

Conversation

Copilot AI commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

The rule treated every replacement identifier as dynamic, even when it referred to a fixed string constant. It now resolves eligible const bindings while preserving reports for dynamic values and constants containing replacement tokens.

  • Static constants: Dollar-free literals such as REDACTED no longer trigger a warning.
  • Risk detection: $-containing constants, computed initializers, and reassigned bindings remain flagged.
const REDACTED = "[REDACTED]";
s.replace(/x/g, REDACTED); // not flagged

const R = "$1";
s.replace(/x/g, R); // flagged

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bare-identifier replacement not resolving to literal initializer Resolve static replacement constants in no-dynamic-string-replacement Nov 7, 2026
Copilot AI requested a review from gh-aw-bot November 7, 2026 22:57
@pelikhan
pelikhan marked this pull request as ready for review November 7, 2026 23:03
Copilot AI dynamic review requested due to automatic review settings November 7, 2026 23:03
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: opus55 medium · ~11 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #75760

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: gpt56 max · ~2 AIC · ⌖ ~2 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-07T23:06:53Z
review_event: REQUEST_CHANGES
top_themes: [static replacement-token tracking, destructured const resolution]
files_reviewed: [eslint-factory/src/rules/no-dynamic-string-replacement.ts, eslint-factory/src/rules/no-dynamic-string-replacement.test.ts]
comment_count: 2

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

Request changes: the new const-resolution path can miss replacement tokens that are assembled through static bindings and can incorrectly accept destructured bindings without resolving their actual value.

Details
  • Static $ tokens split across const bindings can bypass the rule.
  • Destructured const values such as { replacement: "$1" } are not inspected precisely.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

}
resolving.add(variable);
const result = isDynamic(initializer, resolving) || hasStaticReplacementToken(initializer);
resolving.delete(variable);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resolution misses replacement tokens assembled from multiple static const bindings, so const a = "$"; const b = "1"; s.replace(/x/g, a + b) is accepted even though it evaluates to $1 and remains replacement syntax at runtime.

💡 Preserve token tracking across resolved constants

When analyzing a binary/template expression, resolve static identifier initializers while checking the resulting concatenated expression for replacement tokens, or conservatively retain the dynamic warning whenever the resolved value cannot be proven token-free. Add a regression test for the split-token example.

return true;
}
const definition = variable.defs[0];
if (definition?.type !== "Variable" || definition.parent.type !== "VariableDeclaration" || definition.parent.kind !== "const") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accepts destructured const bindings without proving the identifier refers to a static token-free value; for example, const { replacement } = { replacement: "$1" }; s.replace(/x/g, replacement) resolves through the declaration but the object initializer is treated as non-dynamic and its property value is never inspected. That silently regresses the rule's protection.

💡 Reject or precisely resolve destructured definitions

Require a direct Identifier variable declarator before applying this const-resolution path, or implement property-aware destructuring resolution. Otherwise return dynamic for destructured bindings and add object/array destructuring regression tests.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this change does: The rule now follows eligible const identifiers to their initializers, while still reporting dynamic values and static replacement tokens. The tests cover direct static constants, dynamic initializers, and reassigned bindings.

Should fix:

  1. Binding resolution is duplicated (eslint-factory/src/rules/no-dynamic-string-replacement.ts:L147-L161)

    • What this is: The new identifier branch repeats the scope, write, cycle, initializer, and cleanup logic already used by isKnownFunction and isDefinitelyNonFunction.
    • Problem: A reported alias such as const R = get(); s.replace(/x/, R) can run through all three recursive classifiers, so one binding policy is implemented in three places.
    • Fix: Extract one helper that returns an eligible initializer, then keep the replacement-token check in isDynamic.
    • If we skip it: Future changes to binding eligibility must be kept synchronized across three walkers.

Not checked: The targeted Vitest test could not run because the vitest binary is absent in this checkout.

Verdict: fix 1 first.
Lean: -8 lines possible.

Generated by ✂️ Ponytail Reviewer for #75760 · codex · routed: gpt56 max · ~4 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again

return false;
}
const variable = resolveVariable(expression);
if (!variable || variable.defs.length !== 1 || resolving.has(variable) || hasNonInitializingWrite(variable)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: This repeats the variable-resolution and initializer lifecycle already implemented in isKnownFunction and isDefinitelyNonFunction; the rule now has three recursive copies of the scope, write, cycle, and cleanup policy. A reported binding such as const R = get(); s.replace(/x/, R) can pass through all three classifiers, so a later binding-policy change must be kept in sync in three places. Extract one helper that returns an eligible initializer, then keep the replacement-token check here; that removes the duplicated guard logic without adding another abstraction.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The constant exemption incorrectly suppresses warnings for destructured and runtime-dependent initializers and misses replacement tokens encoded with escaped dollar signs.

3 open issues
What changed in this PR

This PR addresses #75595 by resolving constant replacement identifiers in the ESLint rule, reducing false positives for fixed, dollar-free strings.

Changes:

  • Adds recursive const initializer resolution with cycle and reassignment guards.
  • Carries resolution state through nested expressions.
  • Adds tests for safe constants, token-containing constants, computed values, and reassigned bindings.
File Description
eslint-factory/​src/​rules/​no-dynamic-string-replacement.ts Resolves constant bindings when classifying replacement arguments.
eslint-factory/​src/​rules/​no-dynamic-string-replacement.test.ts Adds valid and invalid cases for replacement bindings.

Review effort: Balanced (auto)

return true;
}
const definition = variable.defs[0];
if (definition?.type !== "Variable" || definition.parent.type !== "VariableDeclaration" || definition.parent.kind !== "const") {
Comment on lines +155 to +158
const initializer = getVariableInitializer(variable);
if (!initializer) {
return true;
}
return true;
}
resolving.add(variable);
const result = isDynamic(initializer, resolving) || hasStaticReplacementToken(initializer);
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (eslint-factory/src/rules/no-dynamic-string-replacement.ts:161): This resolution misses replacement tokens assembled from multiple static const bindings, so const a = "$"; const b = "1"; s.replace(/x/g, a + b) is accepted even though it evaluates to $1 and remains replacement syntax at runtime. - Resolve static replacement constants in no-dynamic-string-replacement #75760 (comment)
  3. Review (eslint-factory/src/rules/no-dynamic-string-replacement.ts:152): This accepts destructured const bindings without proving the identifier refers to a static token-free value; for example, const { replacement } = { replacement: "$1" }; s.replace(/x/g, replacement) resolves through the declaration but the object initializer is treated as non-dynamic and its property value is never inspected. That silently regresses the rule's protection. - Resolve static replacement constants in no-dynamic-string-replacement #75760 (comment)
  4. Review (eslint-factory/src/rules/no-dynamic-string-replacement.ts:148): Should fix: This repeats the variable-resolution and initializer lifecycle already implemented in isKnownFunction and isDefinitelyNonFunction; the rule now has three recursive copies of the scope, write, cycle, and cleanup policy. A reported binding such as const R = get(); s.replace(/x/, R) can pass through all three classifiers, so a later binding-policy change must be kept in sync in three places. Extract one helper that returns an eligible initializer, then keep the replacement-token check here; that removes the duplicated guard logic without adding another abstraction. - Resolve static replacement constants in no-dynamic-string-replacement #75760 (comment)
  5. Fix failing check conclusion (FAILURE): https://github.com/github/gh-aw/actions/runs/42423497584/job/128559991846.

Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI.

Sous-chef requested-head: bec9695
Sous-chef requested-work: 51e2287c3d1ee41b7e13769862add61dcd292a623cf943abc5968c984e246bcf 5981a49fadfac7724694f48aa1836d56612f595616fa4fa037beb191ffeed870 65df8fc40e9dfb7d955344507663aa7d62f6e11eb2048a9e499e1ce8d4348f08 785652afeea22b6e971e2ca0bb226bbd52af46d343fe3a688c4b3b66ef707cd0
Sous-chef requested-state: 141b4fa172e613c21b6c82f23a8e9f5de93b0a0c4ac21123521ab69a67f8c827

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~10 AIC · ⌖ ~13 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Copilot assignment requested for the following outstanding work:...

Work is running: update this branch from main, address the three linked review threads, and investigate the failed conclusion check. I will not merge the PR or trigger CI.

Sous-chef requested-head: bec9695
Sous-chef requested-work: 51e2287c3d1ee41b7e13769862add61dcd292a623cf943abc5968c984e246bcf 5981a49fadfac7724694f48aa1836d56612f595616fa4fa037beb191ffeed870 65df8fc40e9dfb7d955344507663aa7d62f6e11eb2048a9e499e1ce8d4348f08 785652afeea22b6e971e2ca0bb226bbd52af46d343fe3a688c4b3b66ef707cd0
Sous-chef requested-state: 141b4fa172e613c21b6c82f23a8e9f5de93b0a0c4ac21123521ab69a67f8c827

@pelikhan
pelikhan merged commit 71dda80 into main Nov 7, 2026
55 of 57 checks passed
@pelikhan
pelikhan deleted the copilot/fix-no-dynamic-string-replacement branch November 7, 2026 23:45
Copilot stopped work on behalf of gh-aw-bot due to an error November 7, 2026 23:45
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.2

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.

no-dynamic-string-replacement: bare-identifier replacement isn't resolved to its literal initializer (FP on send_otlp_span.cjs R

4 participants