astral-sh / ruff

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

New rule: Validate form feeds in leading white space #12321

Open dscorbett opened 1 month ago

dscorbett commented 1 month ago

A form feed has an undefined effect in leading white space except at the start of the line. A rule to validate that a form feed does not appear after indentation could be useful. A related rule is E113, but that doesn’t handle form feeds.

In practice, a form feed resets the indentation, which can be very misleading.

$ printf 'if False:\n    print("F")\n    \fprint("T")\n' >form-feed.py
$ cat form-feed.py
if False:
    print("F")

    print("T")
$ python form-feed.py
T
MichaReiser commented 1 month ago

This seems reasonable and should be very cheap to implement with memfind.