Skip to content

match_semicolon breaks on form feed, making I002 introduce a syntax error #19310

@dscorbett

Description

@dscorbett

Summary

match_semicolon does not recognize U+000C FORM FEED as white space. That makes the fix for missing-required-import (I002) insert the required import on the next line instead of after the semicolon, which can introduce a syntax error. Example:

$ cat >i002.py <<'# EOF'
"docstring"; print(
    f"{__doc__=}",
)
# EOF

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

There is a form feed before the semicolon in that example. Some browsers hide control characters. Hopefully it’s still there if you copy and paste it.

Version

ruff 0.12.3 (5bc81f2 2025-07-11)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions