astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
28.59k stars 925 forks source link

Avoid consuming newline for unterminated string #12067

Closed dhruvmanila closed 4 days ago

dhruvmanila commented 4 days ago

Summary

This PR fixes the lexer logic to not consume the newline character for an unterminated string literal.

Currently, the lexer would consume it to be part of the string itself but that would be bad for recovery because then the lexer wouldn't emit the newline token ever. This PR fixes that to avoid consuming the newline character in that case.

This was discovered during https://github.com/astral-sh/ruff/pull/12060.

Test Plan

Update the snapshots and validate them.

github-actions[bot] commented 4 days ago

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.