AV0017: Remove unnecessary default value
| Value | |
|---|---|
| Rule ID | AV0017 |
| Category | Usage |
| Fix is | Non-breaking |
Cause
An option is assigned the value it already has.
Rule Description
Most options already hold a usable value before any configuration runs. Assigning that same value restates the default without changing anything.
Consider the following code:
builder.Services.AddApiVersioning(
options =>
{
options.ReportApiVersions = false;
options.RouteConstraintName = "apiVersion";
} );
Both assignments state what the options already hold.
The default of a property is matched by the type declaring it rather than by name alone, because the same name can carry a different default on a different set of options. The default API version is reported by AV0011 instead, because it can be spelled more than one way, and a value the API explorer takes from the API versioning options is reported by AV0024.
How to Fix Violations
Remove the assignment.
builder.Services.AddApiVersioning();
When to Suppress Warnings
It is safe to suppress this rule if you prefer options to be stated explicitly so that a future change to a default is deliberate rather than inherited.