Rule proposal: Readability rule - Operator placement for wrapped expressions
See original GitHub issue(EOL = End of Line, BOL = Beginning of Line)
I think StyleCop should dictate (or at least try to dictate) the position of operators. An example:
this is on one line, and it’s ok…
if (true && false)
{
}
But on two lines?
if (true &&
false)
or
if (true
&& false)
the same for +, -, *, /
And then there are ? (with 😃 and ??.
I think that these operators should be put at End of Line, so that if the second operand is a brace the line begins with the brace.
last but not least is the “.” operator. Here I think it’s easier. It should go on the new line for the same reason as the “this” that is necessary. When you press “.” the vs shows you the list of the properties/methods/fields of the object.
So it should be:
var temp3 = new int[5]
.Cast<long>()
.Cast<int>();
Originally posted by xanatos http://stylecop.codeplex.com/workitem/6791
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Rules.md - nicklockwood/SwiftFormat
Wrap braces in accordance with selected style (K&R or Allman). Option, Description. --allman, Use allman indentation style: "true" or "false" (default) ...
Read more >Chapter 16. DRL (Drools Rule Language) rules
This tag determines the position of a declared fact type attribute or field in a positional argument, overriding the default declared order of...
Read more >Proposed rule: Outsourcing by Investment Advisers
ACTION: Proposed rule. SUMMARY: The Securities and Exchange Commission (“Commission” or “SEC”) is proposing a new rule under the Investment ...
Read more >Python Style Guide — CSCI 134: Introduction to Computer Science
Rule 2.3: Use “camel case” to improve readability of multiword identifiers. Rule 2.4: Only use underscores to indicate privacy or special variables. Rule...
Read more >PEP 8 – Style Guide for Python Code
The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In our team we ran in to this issue due to assignment operator. Half of the legacy code has it placed on the next line like so:
We would definitely like to invest in StyleCop to have a rule (+auto-fix for this), so that we can quickly clean in up. Was there ever a consensus on a particular set of operators and how majority of people would want them to be formatted?
From what I understand current preference is:
Maybe we can start with this set and expand it later, once/if we reach an agreement?
As to the name, since we want some operators on the previous line and some on the next - I think we have two options:
Binary operators should be placed correctly
(or removebinary
, as Elvis, aka ?:, is not binary and we may include it in the future)Binary operators should be placed on the line with first operand
Binary operators should be placed on the line with second operand
My vote is for
Operators should be placed correctly
.I understand people may have different preferences, but I thinking allowing people to choose how it should be formatted is defeating the purpose of common coding styles. Yeah, it works if you only care about your project, but if you work on multiple projects it doesn’t help much with readability. Another problem is when you want to integrate two different code-bases together and they use different styles.
In my opinion, we want coding styles to be attached to the language, rather than the project.
Why does
look wrong to you? It immediately gives you proper info that
Baz
andBlech
are called conditionally. No need to scan end of previous line to see this.