- What language is this for?
C# (csharp) - Which rule?
S6966 - Awaitable method should be used
We are using SonarCloud
-
Why do you believe it’s a false-positive/false-negative?
With the FluentValidation library, we derive our validators from AbstractValidator, this means our validator classes will have a Validate method and a ValidateAsync method with the same signature.
The problem here is that validators are usually only CPU bound work, so using the async overload actually adds overhead.
Is it possible to conditionally disable this rule? I still want the rule to apply for other async overloads because it is definitely helping us there but I want to be able to let it exclude Validate methods because these are false positives for us. -
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
Validator:
public class ContractIdValidator : AbstractValidator<ContractId>
{
public ContractIdValidator()
{
this.RuleFor<string>((Expression<Func<ContractId, string>>) (model => model.Id)).Must<ContractId, string>((Func<string, bool>) (p => int.TryParse(p, out int _))).WithMessage<ContractId, string>("Id must be an int.");
}
}
Instance where rule triggers:
// method signature
var validationResult = _contractIdValidator.Validate(myId);
// rest of method
This problem is picked up in lots of places in the repo, so I would like to avoid disabling the rule in the code with comments.