How to deal with ugly code formatter output? (Black) [closed]












2














I'm currently experimenting with the Black code formatter for Python.
In >90% of the cases I am happy with the output (with default configs), but it regularly happens, that it formats some lines in a way that seems rather ugly to me.



Here an example, before and after formatting with black.



Before:
Before formatting



After:
After formatting



The syntax of these two lines is originally identical (same function, same number of arguments...), so it makes sense to format them in the same way. However, as the first line is slightly longer, Black formats it differently, which makes it much more difficult to read and interpret the code.



Of course, in this particular case, you could just increase the linelength parameter of Black, but that doesn't really solve the problem in general, and I would like to stick with the default configuration.



I have come across many such situations, also using other formatters such as Prettier for JavaScript.
How do you handle these situations? Is there for example a way to tell Black, to ignore these particular lines and not format them?










share|improve this question















closed as off-topic by Bill the Lizard, martineau, david, Billal Begueradj, Edric Dec 28 '18 at 7:47


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – martineau, Billal Begueradj, Edric

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    "I would like to stick with the default configuration" - well you're going to have to reconfigure something if you want different output.
    – user2357112
    Dec 27 '18 at 20:29






  • 1




    I don't think there is a configuration that prevents 100% of these cases, where the output is formatted in a suboptimal way. One of the main objectives of these tools is to guarantee uniform code formatting styles among different developers. This objective can clearly not be met if every developer uses another configuration. resulting in another format.
    – nkaenzig
    Dec 27 '18 at 20:32








  • 2




    @roganjosh: surely a code prettyfier is a tool commonly used by programmers!
    – usr2564301
    Dec 27 '18 at 20:37










  • @usr2564301 fair enough, I'll retract.
    – roganjosh
    Dec 27 '18 at 20:39






  • 1




    @nkaenzig: Possibly. Maybe its good rating is because it works most of the time. ;¬)
    – martineau
    Dec 27 '18 at 21:45


















2














I'm currently experimenting with the Black code formatter for Python.
In >90% of the cases I am happy with the output (with default configs), but it regularly happens, that it formats some lines in a way that seems rather ugly to me.



Here an example, before and after formatting with black.



Before:
Before formatting



After:
After formatting



The syntax of these two lines is originally identical (same function, same number of arguments...), so it makes sense to format them in the same way. However, as the first line is slightly longer, Black formats it differently, which makes it much more difficult to read and interpret the code.



Of course, in this particular case, you could just increase the linelength parameter of Black, but that doesn't really solve the problem in general, and I would like to stick with the default configuration.



I have come across many such situations, also using other formatters such as Prettier for JavaScript.
How do you handle these situations? Is there for example a way to tell Black, to ignore these particular lines and not format them?










share|improve this question















closed as off-topic by Bill the Lizard, martineau, david, Billal Begueradj, Edric Dec 28 '18 at 7:47


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – martineau, Billal Begueradj, Edric

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    "I would like to stick with the default configuration" - well you're going to have to reconfigure something if you want different output.
    – user2357112
    Dec 27 '18 at 20:29






  • 1




    I don't think there is a configuration that prevents 100% of these cases, where the output is formatted in a suboptimal way. One of the main objectives of these tools is to guarantee uniform code formatting styles among different developers. This objective can clearly not be met if every developer uses another configuration. resulting in another format.
    – nkaenzig
    Dec 27 '18 at 20:32








  • 2




    @roganjosh: surely a code prettyfier is a tool commonly used by programmers!
    – usr2564301
    Dec 27 '18 at 20:37










  • @usr2564301 fair enough, I'll retract.
    – roganjosh
    Dec 27 '18 at 20:39






  • 1




    @nkaenzig: Possibly. Maybe its good rating is because it works most of the time. ;¬)
    – martineau
    Dec 27 '18 at 21:45
















2












2








2







I'm currently experimenting with the Black code formatter for Python.
In >90% of the cases I am happy with the output (with default configs), but it regularly happens, that it formats some lines in a way that seems rather ugly to me.



Here an example, before and after formatting with black.



Before:
Before formatting



After:
After formatting



The syntax of these two lines is originally identical (same function, same number of arguments...), so it makes sense to format them in the same way. However, as the first line is slightly longer, Black formats it differently, which makes it much more difficult to read and interpret the code.



Of course, in this particular case, you could just increase the linelength parameter of Black, but that doesn't really solve the problem in general, and I would like to stick with the default configuration.



I have come across many such situations, also using other formatters such as Prettier for JavaScript.
How do you handle these situations? Is there for example a way to tell Black, to ignore these particular lines and not format them?










share|improve this question















I'm currently experimenting with the Black code formatter for Python.
In >90% of the cases I am happy with the output (with default configs), but it regularly happens, that it formats some lines in a way that seems rather ugly to me.



Here an example, before and after formatting with black.



Before:
Before formatting



After:
After formatting



The syntax of these two lines is originally identical (same function, same number of arguments...), so it makes sense to format them in the same way. However, as the first line is slightly longer, Black formats it differently, which makes it much more difficult to read and interpret the code.



Of course, in this particular case, you could just increase the linelength parameter of Black, but that doesn't really solve the problem in general, and I would like to stick with the default configuration.



I have come across many such situations, also using other formatters such as Prettier for JavaScript.
How do you handle these situations? Is there for example a way to tell Black, to ignore these particular lines and not format them?







python visual-studio-code code-formatting python-black






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 20:52









martineau

65.9k989178




65.9k989178










asked Dec 27 '18 at 20:22









nkaenzig

385




385




closed as off-topic by Bill the Lizard, martineau, david, Billal Begueradj, Edric Dec 28 '18 at 7:47


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – martineau, Billal Begueradj, Edric

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Bill the Lizard, martineau, david, Billal Begueradj, Edric Dec 28 '18 at 7:47


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – martineau, Billal Begueradj, Edric

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    "I would like to stick with the default configuration" - well you're going to have to reconfigure something if you want different output.
    – user2357112
    Dec 27 '18 at 20:29






  • 1




    I don't think there is a configuration that prevents 100% of these cases, where the output is formatted in a suboptimal way. One of the main objectives of these tools is to guarantee uniform code formatting styles among different developers. This objective can clearly not be met if every developer uses another configuration. resulting in another format.
    – nkaenzig
    Dec 27 '18 at 20:32








  • 2




    @roganjosh: surely a code prettyfier is a tool commonly used by programmers!
    – usr2564301
    Dec 27 '18 at 20:37










  • @usr2564301 fair enough, I'll retract.
    – roganjosh
    Dec 27 '18 at 20:39






  • 1




    @nkaenzig: Possibly. Maybe its good rating is because it works most of the time. ;¬)
    – martineau
    Dec 27 '18 at 21:45
















  • 1




    "I would like to stick with the default configuration" - well you're going to have to reconfigure something if you want different output.
    – user2357112
    Dec 27 '18 at 20:29






  • 1




    I don't think there is a configuration that prevents 100% of these cases, where the output is formatted in a suboptimal way. One of the main objectives of these tools is to guarantee uniform code formatting styles among different developers. This objective can clearly not be met if every developer uses another configuration. resulting in another format.
    – nkaenzig
    Dec 27 '18 at 20:32








  • 2




    @roganjosh: surely a code prettyfier is a tool commonly used by programmers!
    – usr2564301
    Dec 27 '18 at 20:37










  • @usr2564301 fair enough, I'll retract.
    – roganjosh
    Dec 27 '18 at 20:39






  • 1




    @nkaenzig: Possibly. Maybe its good rating is because it works most of the time. ;¬)
    – martineau
    Dec 27 '18 at 21:45










1




1




"I would like to stick with the default configuration" - well you're going to have to reconfigure something if you want different output.
– user2357112
Dec 27 '18 at 20:29




"I would like to stick with the default configuration" - well you're going to have to reconfigure something if you want different output.
– user2357112
Dec 27 '18 at 20:29




1




1




I don't think there is a configuration that prevents 100% of these cases, where the output is formatted in a suboptimal way. One of the main objectives of these tools is to guarantee uniform code formatting styles among different developers. This objective can clearly not be met if every developer uses another configuration. resulting in another format.
– nkaenzig
Dec 27 '18 at 20:32






I don't think there is a configuration that prevents 100% of these cases, where the output is formatted in a suboptimal way. One of the main objectives of these tools is to guarantee uniform code formatting styles among different developers. This objective can clearly not be met if every developer uses another configuration. resulting in another format.
– nkaenzig
Dec 27 '18 at 20:32






2




2




@roganjosh: surely a code prettyfier is a tool commonly used by programmers!
– usr2564301
Dec 27 '18 at 20:37




@roganjosh: surely a code prettyfier is a tool commonly used by programmers!
– usr2564301
Dec 27 '18 at 20:37












@usr2564301 fair enough, I'll retract.
– roganjosh
Dec 27 '18 at 20:39




@usr2564301 fair enough, I'll retract.
– roganjosh
Dec 27 '18 at 20:39




1




1




@nkaenzig: Possibly. Maybe its good rating is because it works most of the time. ;¬)
– martineau
Dec 27 '18 at 21:45






@nkaenzig: Possibly. Maybe its good rating is because it works most of the time. ;¬)
– martineau
Dec 27 '18 at 21:45














0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Mossoró

Cannot access a disposed object : DataContext

Can't read property showImagePicker of undefined in react native iOS