I know some ways that can fix certain whitespace issues:
Go to File-> settings-> editor -> Code Style -> [choose the language] -> other ,check "add line feed at the end of file" (see picture 1). This ensures proper whitespace at the end of files. Moreover, you can customize the whitespace preferences for your language here; For example spaces around operators, blank lines between code blocks picture 1
go to File -> Settings -> Tools -> Action on Save . Enable "Reformat code" (see picture 2). This will run the formatter on the file every time you save and fix whitespace and other style issues based on your code style settings automatically. picture 2
I hope these ways are useful for you.
Note that, I am using pycharm 2022.2 (Professional Edition)