pythonnewlinepycharm

Automatically add newline on save in PyCharm?


PyCharm 5 complains of a missing newline at the end of the file:

PEP 8: No newline at end of file

How do I tell PyCharm to add the newline (if missing) automatically whenever I save a file?


Solution

  • This can be enabled in the Editor > General settings:

    From the File menu under ☰, pick Settings..., then select Editor > General. Under the On Save section in the right-hand pane, check the Ensure every saved file ends with a line break checkbox.

    Ensure every saved file ends with a line break (PyCharm 2023.1.2)


    For older versions of PyCharm:

    From the File pick Settings, then select Editor > General. Under the Other section in the right-hand pane, check the Ensure an empty line at the end of a file on Save checkbox.

    Ensure an empty line at the end of a file on Save (PyCharm 2020.1.3)