dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.04k stars 4.03k forks source link

C# Refactor actions missing for removing redundant else statements #60385

Open vsfeedback opened 2 years ago

vsfeedback commented 2 years ago

This issue has been moved from a ticket on Developer Community.


ReSharper has a refactor action to identify and allow quick removal of redundant else statements in code.

For instance if you have code like this:

if (foo)
{
  return true;
}
else
{
  return false
}

It will identify the 'else' statement is redundant and offer a refactor where you can end up with:

if (foo)
{
  return true;
}

return false;

There is no matching quick action in Visual Studio to do the same thing. Depending on scoping considerations, VS may offer to club things into a ternary operation but that may not be desirable in all cases. This is definitely a missed feature.


Original Comments

Feedback Bot on 3/23/2022, 07:56 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

jinujoseph commented 2 years ago

Related to #30522

dibarbet commented 2 years ago

Design review conclusion:

This suggestion makes sense and we would take a PR that adds this codestyle (with editorconfig) option. The analyzer would be off by default to match what we generally do with new code style rules until we come up with an overarching plan to enable more analyzers by default (cc @mikadumont ).