◐ Shell
clean mode source ↗

Message 107856 - Python tracker

Sorry to be nitpicky, but:

(a) the line[-2] produces "IndexError: string index out of range" on empty
lines, and

(b) this won't detect trailing whitespace on the last line of a file, if there's no newline at the end of the file.  Actually, it might also be worth checking that there *is* a newline at the end of the file;  this is actually required by the C standards.  (E.g., C99 5.1.1.2p2: "A source file that is not empty shall end in a new-line character".)