fix(eslint): skip autofix on ${} in string literal#8627
Merged
Conversation
For literal operands, `buildAutofixMessage` embeds the source text
verbatim into the synthesised template's static segments. When that
text contains `${...}`, it turns into a real interpolation —
silently changing the message, or throwing `ReferenceError` if the
identifier isn't in scope before `assert.ok` even runs.
Bail out (return null) in that case rather than try to escape, and
drop the now-obsolete comment about backslashes — the broader
literal check supersedes it. Includes regression tests for `==`,
`>`, and the escaped `\${...}` variant.
Follow-up to #8537.
|
Contributor
Overall package sizeSelf size: 5.86 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.1 | 82.56 kB | 817.39 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
BenchmarksBenchmark execution time: 2026-05-25 08:16:40 Comparing candidate commit 57da6fa in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 1489 metrics, 104 unstable metrics. |
BridgeAR
approved these changes
May 25, 2026
BridgeAR
left a comment
Member
There was a problem hiding this comment.
LGTM
We should likely limit the rule quite a bit to where it applies. I deactivated it for now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does this PR do?
Fixes a bug in the
eslint-require-boolean-assert-messageautofixer (introduced in #8537): when a boolean assertion has a string-literal operand that contains${...}, the autofixer silently produces a broken message — or, worse, code that throwsReferenceErrorbefore the assertion runs.buildAutofixMessageembeds the source text ofLiteraloperands verbatim into the static segments of the synthesised template literal (non-literal operands are wrapped in${...}and are expression text, so they're unaffected). For example:was being autofixed to:
…where the literal's
${expected}becomes a real interpolation against whateverexpectedhappens to mean in scope. This PR adds an early bail-out (return null) when aLiteraloperand's source text contains${, leaving the violation flagged but unfixed so the author can write the message themselves. The companion comment about backslashes — now subsumed by the broader literal-level check — is dropped.Three regression tests cover the cases that motivated the fix:
==with an interpolation-shaped RHS,>with the same, and the escaped\${...}variant (the escape is normalised away by the parser, so the synthesised template still sees${).Motivation
The original autofixer in #8537 protected against one hazard — a literal backtick in an operand, which would terminate the synthesised template early — but missed the symmetric case of
${...}syntax appearing inside a string literal. The window is narrow but real: any test asserting against a string that happens to contain template-literal syntax (error messages, snapshots, codegen output, fixture strings) would hit it on the first--fix.Additional Notes
#8620 proposes deactivating
eslint-require-boolean-assert-messageoutright and reworking it before re-enabling. This PR is independent of that decision: the autofixer source still ships either way, the bug is real, and the fix is part of the hardening #8620 references. Happy to sequence behind it if reviewers prefer.