Fix the MA0166 message saying "available tokens"

Merged
ME
2mo ago
+46-10

What

MA0166 (Forward the TimeProvider to methods that take one) formats the list of TimeProvider expressions available in the scope into its message, but called them tokens:

MA0166: Use an overload with a TimeProvider, available tokens: this.timeProvider

The file was derived from UseAnOverloadThatHasCancellationTokenAnalyzer and the wording was never updated. It is confusing next to MA0032/MA0040, where the same wording really is about CancellationToken.

The message is now:

MA0166: Use an overload with a TimeProvider, available time providers: this.timeProvider

Also in this change

The same copy-paste left several identifiers talking about cancellation tokens; they are renamed to match what they actually hold:

  • availableCancellationTokens → availableTimeProviders
  • CreateProperties(string[] cancellationTokens, …) → timeProviders
  • IsArgumentImplicitlyDeclared(…, INamedTypeSymbol cancellationTokenSymbol, …) → timeProviderSymbol (the argument passed at the call site is already TimeProviderSymbol)

The comment above the (int)symbol.SpecialType is >= 1 and <= 45 fast path is expanded to say what the range means. Checking the Roslyn packages confirms the enum grew past 45 (System_Runtime_CompilerServices_InlineArrayAttribute and System_Runtime_CompilerServices_AsyncHelpers exist in 5.9 but not in 4.8), so the bound covers every special type of the oldest supported Roslyn version and the newer ones are simply not skipped — a missed fast path, not a correctness issue. The bound itself is left unchanged, as widening it is a behaviour change beyond this fix.

No behaviour other than the message text changes: the diagnostic properties consumed by the code fix (ParameterIndexKey, ParameterNameKey, PathsKey) are untouched.

Tests

No test asserted on the MA0166 message, so ReportsTheAvailableTimeProvidersInTheMessage is added to pin the wording, mirroring the equivalent MA0040 test.

  • UseAnOverloadThatHasTimeProviderAnalyzerTests: 18/18 passing on roslyn4.8, 4.14, 5.0, 5.6 and 5.9
  • dotnet run --project src/DocumentationGenerator: exit code 0, no markdown change (the docs surface rule titles, not message formats)