-
Notifications
You must be signed in to change notification settings - Fork 509
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
SA1500 fires for the while clause of do/while statement #2801
Comments
The behaviour is by design. I've marked this |
What's the equivalent option in the Visual Studio formatting settings (and the corresponding .editorconfig setting)? If a clear option exists there and we decide to add an option to StyleCop Analyzers, we should use a name that shows a link between the two. |
👍 Note: I assume that the spacing inside and around condition parantheses are non-intentional in the @smaillet's sample code. |
I'd second this being an odd case. I've always learned that the while should be on the same line as the end of the loop for a do while on the few cases where they are actually useful. I could see the argument that front loaded conditions are on a separate line so why wouldn't the follower, but given how rarely one sees a do/while, the difference in formatting is probably helpful for highlighting the difference. |
@vweijsters Are we still discussing it? This issues is really annoying, I want to keep this inspection, but additionally want to keep while on the same line with closing bracket. I can prepare fix to ignore this for Do we need separate inspection, or separate setting in |
Hi all. Any news on this one? It would be really great to have it fixed since currently because of this I cannot enable SA1500. Thanks! |
@sharwell there is no config option for this in .editorconfig, but I'm willing to allow someone else to pick this up and make it configurable. What are your thoughts on it? |
…hile statement Provide new configuration setting, `layoutRules.allowDoWhileOnClosingBrace` such that when enabled, the following will be allowed: do { Console.WriteLine("test"); } while (false);
…hile statement Provide new configuration setting, `layoutRules.allowDoWhileOnClosingBrace` such that when enabled, the following will be allowed: do { Console.WriteLine("test"); } while (false);
@vweijsters, I have implemented a new configuration setting to support this. I called it When the setting is
I believe this is the simplest solution to the issue and would address most people's concerns. However, when the setting is
I think most people would be okay with this behavior in order to get what they are really after and that is just allowing the An alternative that could address the above would be to instead change the new setting such that it has discrete values, similar to the
However, if this were implemented with respect to SA1500, and someone configures the setting to So, the last thing I can think of would be to create an entire new layout rule. Unfortunately, I'm not very familiar with how this might be implemented. But I'm guessing we'd have a create a rule called something like SA1521 DoWhileLoopExpressionPlacement, with a default configuration setting value of say In the implementation, if rule SA1500 is enabled, then this new rule wouldn't have to do anything by default. But if the rule's configuration setting was set to As I mentioned, I have code and unit tests completed for the first solution that I described above. Please advise as to the next steps. Would you like me to just submit a Pull Request and continue any discussion there? Or should I create a new Issue first? I've read the page on Contributing, but I'm not sure how much of what is mentioned in the section header "Implementing a diagnostic", is applicable here. Thanks. |
@sharwell , I haven't heard a response to my above post in 10 days. Is anyone around that could review it and if OK with just adding the proposed configuration property, is there someone that would be able to approve a PR if I submit one? |
…hile statement Provide new configuration setting, `layoutRules.allowDoWhileOnClosingBrace` such that when enabled, the following will be allowed: ``` do { Console.WriteLine("test"); } while (false); ```
@zvonimir , @werwolfby , @AJH16 @zahirtezcan-bugs, @smaillet Any one interested in reviewing my above comments and the Pull Request that I opened? Do you think it would be sufficient and satisfy your needs here? |
Is there any follow up on this issue? Having the closing |
I don't believe there are any plans to make this configurable. |
@sharwell, can you elaborate on what you mean by:
|
It looks like the Visual Studio formatter silently accepts both of these, without exposing a preference via a user option: do
{
} while (true); do
{
}
while (true); With that said, there are many places where StyleCop Analyzers is more opinionated than Visual Studio about specific formatting rules, with this being one of the cases. Since each added option incurs substantial long-term maintenance and testing considerations, I don't believe we need to add this specific case. Note that teams could either implement a separate analyzer for brace placement, or could implement a |
I'm looking to include this because it takes the simpler approach of "ignoring" this location, as opposed to requiring the |
I think I understand you. The proposed PR introduces a new setting, But if you enable this new setting, it will allow either syntax to be used throughout the code. So correct, in that it does not force you to place the
and
will be allowed. Perhaps we should add an additional Unit Test for the latter in which the setting is explicitly enabled. |
Issue #2801: SA1500 fires for the while clause of do/while statement
The following generates an SA1500 error when it shouldn't:
Forcing placement of while onto a separate line is counter to common code style practices. At the very least there should be a configuration option to set how this rule should handle the placement of the while clause.
The text was updated successfully, but these errors were encountered: