Prevent trailing whitespace?

PyCharm is generally pretty good about not leaving trailing whiltespace behind, but I do notice that every once in a while I end up with a line containing only whitespace.  Can this be prevented?

Thanks,

-Roberto.

trailing_whitespace.png



Attachment(s):
trailing_whitespace.png
2 comments

Thanks for the response.  I have the whitespace setting to modified lines only, but I still get whitespace under the following condition.

The line that the cursor is on will save a trailing whitespace; when there is text on the line or even if it's an empty line.  For example, say you had the following function:

def whitespace test(request):

    return HttpResponse('hello')

Then you decided to add "user = request.user" and leave a blank line between your variable definitions and the return statement to end up with:

def whitespace test(request):

    user = request.user

   

    return HttpResponse('hello')


Now the cursor is blinking between the "u" in user and "r" in return:

pycharm_whitespace_in_ide.png

Hit save, then run "git diff" on the command line and you'll see:

pycharm_whitespace_in_git_diff.png

This scenario will continue happening and if I go elsewhere in the code and resave.  The trailing whitespace above will persist even though it's on a "modified line".  I'm interpreting a "modified" line to be content that shows up as changed when running "git diff".  As mentioned, my settings are configured to strip whitespace on modified lines.

Thanks,

-Roberto.



Attachment(s):
pycharm_whitespace_in_ide.png
pycharm_whitespace_in_git_diff.png
0

Please sign in to leave a comment.