Skip to content

start_of_file handles at most one backslash, making I002 introduce a syntax error #19815

@dscorbett

Description

@dscorbett

Summary

#19505 made start_of_file handle a backslash after a docstring, but it only handles one backslash. If the next line has a backslash too, the original bug appears. Example:

$ cat >i002.py <<'# EOF'
"docstring"\
\

print(f"{__doc__=}")
# EOF

$ ruff --isolated check i002.py --select I002 --config 'lint.isort.required-imports=["import sys"]' --diff 2>&1 | grep error:
error: Fix introduced a syntax error. Reverting all changes.

Version

ruff 0.12.8 (f51a228 2025-08-07)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions