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

--line-ranges formats entire file when ranges are at EOF #4264

Closed
jvacek opened this issue Mar 4, 2024 · 2 comments · Fixed by #4273
Closed

--line-ranges formats entire file when ranges are at EOF #4264

jvacek opened this issue Mar 4, 2024 · 2 comments · Fixed by #4273
Labels
T: bug Something isn't working

Comments

@jvacek
Copy link

jvacek commented Mar 4, 2024

Line ranges seem to format an entire file when the range goes to the end of the file

microsoft/vscode-black-formatter#472

  • Take a file that is unformatted
  • Set the line ranges to any portion as long as the last line is EOF
  • The entire file is formatted

For example, take this code:

** Ensure empty last line **

abc = 'def'
ghi= 'jkl'
mno='pqr'
stu='vwx'

And run it with these arguments:

black --line-ranges 4-5 file.py

The resulting error is:

> cannot format file.py: INTERNAL ERROR: ...

Expected behavior

Only stu='vwx' being formatted, and not lines 1-3

Environment

  • Black's version: 24.2.0
  • OS and Python version: MacOS 14.3.1, Python 3.10.3

Additional context

@jvacek jvacek added the T: bug Something isn't working label Mar 4, 2024
@RedGuy12
Copy link
Contributor

RedGuy12 commented Mar 5, 2024

From my tests, the line range only fails when the range ends on the last line and the last line is empty

@jvacek
Copy link
Author

jvacek commented Mar 6, 2024

That won't play well for anyone who enforces an empty last line, and has their IDE send the line ranges to black.

sumezulike added a commit to sumezulike/black that referenced this issue Mar 12, 2024
sumezulike added a commit to sumezulike/black that referenced this issue Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants