SonarSource/sonar-dotnet

New Rule T0034: Do not embed var into this condition

pavel-mikula-sonarsource opened this issue · 0 comments

Coding style:

Var pattern is var o can be used only where variable declarations would require additional nesting.

if(something.Something() is var value // Noncompliant, can be extracted to var value=
    && value.Name == name
    && value.Count > min) 


if(someting.Prerequisite() is { } prerequisite
   && something.Something() is var value // Compliant
   && value.Name == name
   && value.Count > min) 


var value = something.Something(); // Compliant
if(value.Name == name
   && value.Count > min) 

public object Method() =>
    something.Something() is var value // Compliant
    && value.Name == name
    && value.Count > min)