Skip to content

Analyzers & Source Generator

Cocoar.Configuration includes Roslyn analyzers and a source generator out of the box — no separate package install needed. They ship as part of the Cocoar.Configuration NuGet package.

The analyzers catch configuration mistakes at compile time. The source generator produces descriptor metadata for feature flags and entitlements — it's required for flags to work (expiry tracking, health reporting, REST endpoint generation all depend on the generated descriptors).

Both run during compilation — in your IDE and in CI. No runtime cost.

Diagnostics at a Glance

Configuration (COCFG)

IDSeverityWhat It Catches
COCFG001WarningSecret path conflicts — non-secret property shadows a Secret<T>
COCFG002ErrorRule dependency ordering — rule uses config that isn't loaded yet
COCFG003WarningRequired rule references a resource that may not exist
COCFG005InfoDuplicate unconditional rules for the same type
COCFG006InfoStatic provider after dynamic providers (ordering suggestion)

Feature Flags (COCFLAG)

IDSeverityWhat It Catches
COCFLAG001WarningExpiresAt is not a static DateTimeOffset literal
COCFLAG002WarningAbstract type passed to Register<T>()
COCFLAG003InfoFlag or entitlement property missing <summary> XML doc

Source Generator

The package also includes a source generator that produces descriptor metadata for registered feature flags and entitlements. See Flags Diagnostics for details.

Suppressing Diagnostics

Standard C# suppression mechanisms work:

In code:

csharp
#pragma warning disable COCFG005
rules.For<AppSettings>().FromFile("a.json"),
rules.For<AppSettings>().FromFile("b.json")
#pragma warning restore COCFG005

Via attribute:

csharp
[SuppressMessage("Cocoar.Configuration", "COCFG005")]

Via .editorconfig:

ini
[*.cs]
dotnet_diagnostic.COCFG005.severity = none

Released under the Apache-2.0 License.