-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 lines outside of range
#4430
Comments
This is clearly mentioned in the comments, Line 306 in c204232
|
I'm not sure I understand what the effect is. If I try to use
If the answer is (2), I can provide a direct counterexample that would presumably demonstrate a bug. If (3) or (4), can more clarification be given? I don't know what a "prefix" is. |
@afontenot Black will first parse all the file contents, respecting the given line length. The prefix indicates the start of the first node/line. If the first node starts with # or whitespace, it will be reformatted according to the correct indentation level, based on the syntax in the preceding line. If you provide the whole file to Black or specify a line length, it will ensure the correct indentation is used throughout the entire file. Since Black first parses the entire file, maintaining correct indentation is particularly important. Please correct me if I'm wrong. |
Describe the bug
Black's
--line-ranges
option does not completely prevent reformatting of code outside of the specified line ranges.To Reproduce
For example, take this code:
And run it with these arguments:
The result is:
Expected behavior
The expected result would be the formatting constrains itself to lines 1 through 9, and does not modify whitespace outside of this line range:
Note both the three-line separation as well as the indentation would be preserved as they are outside of the line range 1-9.
Environment
Additional context
It would be useful for
--line-ranges
to only format what is contained within the specified line ranges, as much as possible, to allow for incremental adoption of formatting in larger code bases.The text was updated successfully, but these errors were encountered: