Skip to content

st1018: don't suggest escape sequences inside raw string literals - #1731

Draft
Eljees wants to merge 1 commit into
dominikh:masterfrom
Eljees:fix/1115-st1018-raw-strings
Draft

st1018: don't suggest escape sequences inside raw string literals#1731
Eljees wants to merge 1 commit into
dominikh:masterfrom
Eljees:fix/1115-st1018-raw-strings

Conversation

@Eljees

@Eljees Eljees commented Aug 6, 2026

Copy link
Copy Markdown

Fixes #1115.

Escape sequences are not interpreted inside raw string literals, so replacing an invisible character there with its escape sequence changes the string's value to the six literal characters of that sequence rather than removing the invisible one. The current testdata golden file records exactly that: the e = ... line holds a raw literal whose zero-width space has been "replaced" by six visible characters.

The message has the same problem: it tells the user to use an escape sequence that would not work where they are.

For raw string literals this now offers only the deletion fix, and the message points at an interpreted string literal instead. On a file with the same zero-width space in both kinds of literal:

main.go:6:17: string literal contains the Unicode format character U+200B, consider using the ... escape sequence instead
main.go:7:9:  raw string literal contains the Unicode format character U+200B, consider using an interpreted string literal and the ... escape sequence instead

The golden file loses its replace format character U+200B with ... section, which the test flags on its own: without that removal, TestTestdata fails with "golden has section for suggested fix ..., but we didn't produce any fix by that name".

I did not add testdata rows for a raw literal holding several invisible characters, since every added line rewrites all eight golden sections; happy to do it if you'd rather have the coverage.

(Edited: the first version of this description contained literal zero-width characters in the places where the escape sequence was meant to be shown, which rather made the point.)

@Eljees

Eljees commented Aug 9, 2026

Copy link
Copy Markdown
Author

Marking this ready for review. I'd been holding it as a draft while #1730 was open, in case you'd rather take contributions one at a time — say the word and I'll close one. A draft doesn't show up in your review queue at all, though, so leaving it that way seemed worse than asking.

@dominikh

dominikh commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Thanks, I'll take a look eventually.

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.

ST1018: fix and improve handling of raw string literals

2 participants