-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add "preview" and "skip-magic-trailing-comma" options, and version bump to v0.2.5 #48
Conversation
Do you use this then?
|
Correct. There are a few other options that seem to be missing (I think). Not sure if there were existing plans to add them, but adding at least this specific option would be very helpful for us. |
Yes, as I recall black started with no options (except the line length - notes on that in the I think now that they have dropped the beta tag, it is worthwhile looking at the |
You're welcome to take a look at that approach - although waiting on psf/black#779 might be wiser. |
I don't think the options will change that often anymore, since the aim of Black is to be as opiniated as possible. Especially now that it is becoming more and more stable. Using a config parser from Black (official API or not) would be nice, but a bit out of scope for me to pick up. Instead what I did now is add an additional option in this PR, "skip_magic_trailing_comma", which seems to be a highly debated issue. When you set this option to true, magic commas will be turned off. Without magic commas, Black won't look at existing formatting and will try to put arguments/collections as much one 1 line as possible. Check psf/black#1288 I believe with this current set of flags most users will be provided for. But feel free to decide however you see fit. |
That is pragmatic, and I'm OK with merging this with the hope of switching to the planned black API in future which will (hopefully) let us drop this part of the flake8-black code. Can you do a version bump and change log entry for this too? That would save me some time making the release with these changes. Thanks! |
Done! I hope I did this right. |
I renamed the option in the messages to "skip-magic-trailing-comma", since that is what the actual option in the config file is named. And I tested and verified that it actually works (just like "preview"). |
Do you happen to already have a couple of short examples where these settings come into play? |
If you mean a short explanation, here you go (assume a line-length = 79 for the first example): With def foo():
print(
"hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo world"
)
print("hello " "world") With def foo():
print(
"hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
" world"
)
print("hello world") As you can see it will concatenate and split strings to accomodate Black's styling. With def foo():
SomeClass(
foo=1,
bar=2, # remove this trailing comma to instruct black to put all args on a single line
) With def foo():
SomeClass(foo=1, bar=2) So without the magic trailing comma (skip-magic-trailing-comma = true), if it fits on a single line, Black will format it that way. No matter if the last arg contained a trailing comma or not. |
Functionality added in pull request #48
Lovely - I made something similar with commas, but reminding myself how I setup the test folders took me longer than I expected. I'll use your preview example now... |
Functionality added in pull request #48, test case suggested by @ferdynice
Curious - adding |
Ah indeed. Any comment starting with |
That's up on PyPI now https://pypi.org/project/flake8-black/0.2.5/ - conda-forge to follow. |
I forgot this would need the latest black, see #49. Fixed as v0.3.0 |
Add the "preview" option.