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

Black doesn't add newline when formatting #13692

Closed
ghost opened this issue Aug 31, 2020 · 6 comments
Closed

Black doesn't add newline when formatting #13692

ghost opened this issue Aug 31, 2020 · 6 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@ghost
Copy link

ghost commented Aug 31, 2020

Issue Type: Bug

Whenever I format with black, it doesn't add a newline at the end of my file.

Steps to Reproduce:

  1. Set black as Python formatting provider
  2. Format file

If I switch to autopep8, it adds the newline at the end of the file as per the conventions of python formatting. Black used to add newlines but not anymore. I am also using a virtual environment.

Extension version: 2020.8.105045
VS Code version: Code 1.48.2 (a0479759d6e9ea56afa657e454193f72aef85bd0, 2020-08-25T10:09:08.021Z)
OS version: Darwin x64 19.6.0

System Info
Item Value
CPUs Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz (8 x 1400)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 16.00GB (0.08GB free)
Process Argv
Screen Reader no
VM 0%
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Aug 31, 2020
@karthiknadig karthiknadig added triage bug Issue identified by VS Code Team member as probable bug labels Aug 31, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Aug 31, 2020
@kimadeline
Copy link

kimadeline commented Aug 31, 2020

Hi @SyntaxErr0rr, thank you for reaching out.

Does Black add a newline if you run it directly from the terminal using the same command as the Python extension (which you can see in the Python output channel)? If not this is an issue on Black itself, which you should report on their repo.

If it adds a newline when run directly in the terminal, which version of Black are you using?

Note: you can also use the files.insertFinalNewline setting as a workaround as well.

Thanks!

@kimadeline kimadeline added the info-needed Issue requires more information from poster label Aug 31, 2020
@ghost
Copy link
Author

ghost commented Aug 31, 2020

Hi @SyntaxErr0rr, thank you for reaching out.

Does Black add a newline if you run it directly from the terminal using the same command as the Python extension (which you can see in the Python output channel)? If not this is an issue on Black itself, which you should report on their repo.

If it adds a newline when run directly in the terminal, which version of Black are you using?

Note: you can also use the files.insertFinalNewline setting as a workaround as well.

Thanks!

Thanks for your response! When I run Black from the command line, it adds the newline to my file. Currently I am using Black, version 20.8b1. An additional note if I didn't mention it when I opened this issue, I have format on save turned on (hope this is useful in solving the problem).

@ghost
Copy link
Author

ghost commented Aug 31, 2020

Thank you for the newline setting as well!

@kimadeline
Copy link

Could you copy here the output from running black --diff on one of your files? And does downgrading to 19.10 show the expected behaviour?

@ghost
Copy link
Author

ghost commented Aug 31, 2020

Could you copy here the output from running black --diff on one of your files? And does downgrading to 19.10 show the expected behaviour?

I believe downgrading to 19.10 shows the expected behavior. The output for black --diff on version 20.8b1 is as follows

would reformat basics.py
All done! ✨ 🍰 ✨
1 file would be reformatted.

When I run black --diff on version 19.10b0, the output is different:
Screen Shot 2020-08-31 at 4 21 47 PM

@kimadeline
Copy link

kimadeline commented Aug 31, 2020

We use the --diff option in the extension to format files using Black, and it looks like 20.8b1 does not add a newline at the end of the file when using this option, while 19.10 does. This is an issue on Black itself, which I've reported here, feel free to comment on it and add more details!

Closing since this is an issue caused by Black, and not the extension.

@ghost ghost removed the triage label Aug 31, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants