Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore trailing whitespace in cell comparison #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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