TimeWarp.SourceGenerators ships Roslyn analyzers for C# file names, global usings, and the style rules TWA0004, TWA0023, TWA0038, TWA0053, TWA0054, and TWA0055. Rules are on by default. Opt out with dotnet_diagnostic.<id>.severity = none.
If you like or are using this project please give it a star. Thank you!
Enforces kebab-case naming for C# files, including multi-dot partials (e.g. application-state.close-modal.cs) when every segment is kebab-case.
Configure exceptions in .editorconfig:
[*.cs]
dotnet_diagnostic.TW0001.excluded_files = Program.cs;Startup.cs;*.Designer.csReports file-level using directives that should move to kebab-case global-usings.cs, including usings after a file-scoped namespace X; (the gap in BDSoftware GlobalUsingsAnalyzer 1.4.0). On by default. A file whose first two characters are #! is a runfile, so the rule skips it and the usings stay in that file. A file brought in with #:include has no shebang; list it in dotnet_diagnostic.TW0007.excluded_files.
[*.cs]
dotnet_diagnostic.TW0007.severity = none
dotnet_diagnostic.TW0007.filename = global-usings.csSee configure-global-usings-analyzer.md.
TWA0004, TWA0023, and TWA0038 keep their Architecture.Analyzers ids, so an existing .editorconfig entry still applies. TWA0053 and TWA0054 are new in this package; the ids were reserved in timewarp-architecture task 562-001. Other TWA* ids stay in TimeWarp.Architecture.Analyzers.
| ID | Rule | Default |
|---|---|---|
| TWA0004 | #region Purpose in every non-generated C# file |
Warning, enabled |
| TWA0023 | Identifier ends with its type stem | Warning, enabled |
| TWA0038 | File longer than 500 lines (max_lines overrides) |
Warning, enabled |
| TWA0053 | Comment outside Purpose, Design, or Open Questions | Warning, enabled |
| TWA0054 | Task number or dating phrase inside those regions | Warning, enabled |
| TWA0055 | Override of a virtual void, Task, or ValueTask calls its base method | Warning, enabled |
[*.cs]
dotnet_diagnostic.TWA0004.severity = none
dotnet_diagnostic.TWA0023.severity = none
dotnet_diagnostic.TWA0038.severity = none
dotnet_diagnostic.TWA0038.max_lines = 500
dotnet_diagnostic.TWA0053.severity = none
dotnet_diagnostic.TWA0054.severity = none
dotnet_diagnostic.TWA0055.severity = noneTWA0053 reports a // comment, a /* */ comment, and an XML doc comment that sits outside #region Purpose, #region Design, and #region Open Questions. A repo opts out per folder with severity = none. dotnet_diagnostic.TWA0053.allowed_prefixes is a ;- or ,-separated list of prefixes of the text after //. When the key is absent the only prefix is <auto-generated. A set value replaces that default. The code fix removes the comment and supports fix-all; an allowed prefix is not diagnosed, so the fix leaves it.
TWA0054 reports a task number or a since / until / before / from / as of phrase inside those regions. (YYYY-MM-DD, author) is not a match.
[source/**.cs]
dotnet_diagnostic.TWA0053.severity = warning
dotnet_diagnostic.TWA0054.severity = warning
dotnet_diagnostic.TWA0053.allowed_prefixes = <auto-generated;-:cnd:noEmit;+:cnd:noEmitTWA0038 reports only files the consuming repository owns. It skips a file under the NuGet package root (.cs that a package compiles in through contentFiles or a Compile item in its build props), under obj/ or goldens/, or outside both the project directory and $(RepositoryRoot) (only when both are known). The package's build/TimeWarp.SourceGenerators.props makes NuGetPackageRoot, ProjectDir, and RepositoryRoot visible to the analyzer. When a key is absent, a /.nuget/packages/ path segment still marks package content. For anything that heuristic misses, list globs (; or , separated; ** spans directories, * and ? stay in one) in exclude_paths:
[*.cs]
dotnet_diagnostic.TWA0038.exclude_paths = tools/dev-cli/vendored/**; **/third-party/*.csTWA0023 opt-out is [TypeStemIdentifier("reason")]. The attribute type stays in TimeWarp.Architecture.Attributes and is matched by simple name. The rule also skips types whose names do not name the role: Guid, DateTime, DateTimeOffset, DateOnly, TimeOnly, TimeSpan, JsonElement, and OneOf / OneOfBase (any arity). Guid? and the other nullable forms are skipped too. A property is skipped only when its type is one of those. A typed id such as TenantId still reports. A public property, and the parameters of a public method, that implicitly implement an interface member are skipped, because the interface fixes those names; the interface declaration itself still reports. Blazor EventCallback and EventCallback<T> are skipped too (@bind-Value requires ValueChanged).
| Prefix | Where it lives |
|---|---|
| TW | TimeWarp.SourceGenerators — TW0001 and TW0007 |
| TWA0004, TWA0023, TWA0038 | TimeWarp.SourceGenerators — generic style rules moved from Architecture.Analyzers. Same ids. |
| TWA0053, TWA0054 | TimeWarp.SourceGenerators — comment region and dating. Ids reserved in timewarp-architecture task 562-001. |
| TWA0055 | TimeWarp.SourceGenerators — an override calls its base method. |
| other TWA* | TimeWarp.Architecture.Analyzers — contracts, endpoints, slices, and the rest |
File-name kebab-case is TW0001 (dotnet_diagnostic.TW0001.*, #pragma warning disable TW0001). Do not configure that rule with a TWA* id.
To quickly get started I recommend reviewing the samples in this repo.
dotnet add package TimeWarp.SourceGeneratorsYou can see the latest NuGet packages from the official TimeWarp NuGet page.
The analyzer assembly targets net11.0, not netstandard2.0. It loads in a compiler that runs on .NET 11: dotnet build with the .NET 11 SDK, and editors that host that compiler. It does not load in Visual Studio, whose compiler runs on .NET Framework.
See the Release Notes
Time is of the essence. Before developing a Pull Request I recommend opening a discussion.
Please feel free to make suggestions and help out with the documentation. Please refer to Markdown for how to write markdown files.
Sometimes the github notifications get lost in the shuffle. If you file an issue and don't get a response in a timely manner feel free to ping on our Discord server.
