question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there an analyzer to reporting missing parentheses in IF statements?

See original GitHub issue

Hi StyleCop enthusiasts!

I wonder if there is any analyzer that would catch for me that this line is missing parentheses:

else if (httpResponse.StatusCode >= HttpStatusCode.Ambiguous && httpResponse.StatusCode < HttpStatusCode.BadRequest)

as I would like to enforce this style:

else if ((httpResponse.StatusCode >= HttpStatusCode.Ambiguous) && (httpResponse.StatusCode < HttpStatusCode.BadRequest))

Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sharwellcommented, Dec 14, 2020

This parentheses preference is not enforced because there is only one interpretation that makes sense. In other words, readers are unlikely to read the expression as follows, even if they are new to the C# language:

httpResponse.StatusCode >= (HttpStatusCode.Ambiguous && httpResponse.StatusCode) < HttpStatusCode.BadRequest
1reaction
manfred-brandscommented, Dec 14, 2020

This is built in VS parentheses preferences

You can add the following to your .editorconfig file:

dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to detect the position of a missing parenthesis, given ...
This allows you to directly analyze the inputted symbols directly. Now it would be a simple matter to count how many left parentheses...
Read more >
Missing Parenthesis in SQL IF Statement?
Hi All,. Not sure what I am missing here in my Sql Statement. I keep getting the [Error] Execution: (ORA-00907: missing right parenthesis...
Read more >
[SOLVED] IF statement missing parenthesis in formula
Message received, "your formula is missing --) or (. Check the formula and then add the parenthesis in the appropriate place.
Read more >
If statement Error(Missing right parenthesis)
Hello All! I am creating a calculated field using the below if statement to create additional column in my file if((OPSN_PLANNED_QUANTITY=1 ...
Read more >
How to properly locate unbalanced parenthesis in source ...
The parenthesis check basically reads the code and updates a counter whenever it hits a parenthesis. If it is an opening bracket, it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found