nunit.analyzers
nunit.analyzers copied to clipboard
Add a rule informing that .Within is not valid for non-numeric types.
See https://github.com/nunit/nunit/issues/3736
The nunit syntax allows:
[Test]
public void RecordsEqualsMismatch()
{
var a = new Data(1, 1.0);
var b = new Data(1, 1.1);
Assert.That(a, Is.EqualTo(b).Within(0.2), $"{a} != {b}");
}
private sealed record Data(int number, double Value);
But the .Within
part is completely ignored. Only the NumericEquals and TupleEquals will use it.
Add a rule warning the user when the .Within
constraint is not valid.
Add a CodeFix to remove the constraint.
I'll try to take care of this
@Antash How are you going with this, need any help? You can raise a draft PR for us if you would like us to look at your work.
@manfred-brands thanks for giving me a hand. I have almost zero experience with Roslyn and stuck a bit on the CodeFix. Most likely it will be very easy for you to advise how can I remove 'Within' node from the syntax tree. Also, need to add more test cases and documentation