Skip to content

Ignore trailing whitespace in cell comparison#25

Open
Iain-S wants to merge 1 commit intodnanhkhoa:masterfrom
Iain-S:trailing_whitespace
Open

Ignore trailing whitespace in cell comparison#25
Iain-S wants to merge 1 commit intodnanhkhoa:masterfrom
Iain-S:trailing_whitespace

Conversation

@Iain-S
Copy link

@Iain-S Iain-S commented Aug 19, 2020

Issue
If you have trailing whitespace in a Jupyter notebook cell, nb-black won't format it. For example (note the newline):

a=1

 

I have tested it with newlines and spaces.

Fix
It happens because nbb_unformatted_code (which comes from self.shell.user_ns["_i" + str(cell_id)]) is stripped of whitespace (not sure why but it is out of our control). Therefore, we should strip whitespace from nbb_cells[i].get_text() before we compare it to nbb_unformatted_code.

@dnanhkhoa
Copy link
Owner

Hi @Iain-S , thank you for the PR

Actually I haven't tested this yet. Do you have any problem so far with your fix?

@Iain-S
Copy link
Author

Iain-S commented Aug 24, 2020

Hi @dnanhkhoa , I haven't noticed any issues thus far.

A minor problem is that if the user has started to add new blank lines after submission but before completion of the cell, those new lines will be deleted. I suspect that this will be only a minor annoyance but an alternative solution would be to work out why the self.shell.user_ns[] code is stripped of whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants