Refuse DateTime.UtcNow, regions and a homemade FakeTimeProvider in the build - #568
Merged
kirill-abblix merged 3 commits intoSep 24, 2026
Merged
Conversation
…e build Three house rules were kept by an editor hook that matched source text. They now sit where the compiler or a test that asks it decides: - DateTime.UtcNow and DateTimeOffset.UtcNow are banned through Microsoft.CodeAnalysis.BannedApiAnalyzers and BannedSymbols.txt, as error RS0030 in every project. Every existing use is replaced: tests and the static licensing code read TimeProvider.System, and the CIBA doc sample takes an injected TimeProvider. - #region is refused by NoRegionsTests, which reads directives from the syntax tree. StyleCop's SA1124 would have done this at build time, but no StyleCop version loads into the .NET 11 compiler (CS8032 for every rule). Every existing region is removed; where a region title named the specification a group of members comes from, the title stays as a comment. - A type named FakeTimeProvider declared in any assembly built here is refused by NoHomemadeFakeTimeProviderTests, over the built assemblies. The loader it shares with ResultArmsMustBeDistinguishableTests moves to TestInfrastructure/BuiltAssemblies.
Removing the regions dropped three specification titles in IanaClaimTypes (ETSI GS NFV-SEC 022, OAuth JWT Introspection, OAuth Rich Authorization Requests), and left the error codes that no region covered under the Dynamic Client Registration header. The titles are back as comments, and those codes now sit above the first header. DateTime.Now, DateTimeOffset.Now and DateTime.Today join the banned list; nothing here used them. The Abblix.Jwt README sample reads its expiry from a TimeProvider. The blank lines left beside braces where a region ended are gone. The FakeTimeProvider test also recognizes the names the compiler emits for a generic or file-local type, and the loader's comment says that an assembly which fails to load is skipped rather than reported.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Three house rules were enforced by an editor hook that matched source text. This moves them into the build, or into tests that ask the compiler, and fixes every existing violation instead of suppressing it.
DateTime.UtcNowandDateTimeOffset.UtcNow, and with themDateTime.Now,DateTimeOffset.NowandDateTime.Today, are banned throughMicrosoft.CodeAnalysis.BannedApiAnalyzersandBannedSymbols.txt, as error RS0030 in every project. The existing uses were almost all in tests. They now readTimeProvider.System, and so does the static licensing code, which has no injected clock. The CIBA handler sample in the docs takes an injectedTimeProvider, since hosts copy it.#regionis refused byNoRegionsTests, which reads the directives from the syntax tree. StyleCop's SA1124 would have done this at build time, but no StyleCop version loads into the .NET 11 compiler: every rule fails with CS8032. All existing regions are removed. Where a region title named the specification a group of constants comes from, the title stays as a plain comment.FakeTimeProvideris refused byNoHomemadeFakeTimeProviderTests, which looks through the assemblies this repository builds for net11.0 (the two source generators build for netstandard2.0 and are not walked). An analyzer can ban using an API but not declaring a type. The assembly loader it shares withResultArmsMustBeDistinguishableTestsmoves toTestInfrastructure/BuiltAssemblies.The analyzer package is
PrivateAssets="all", so it does not reach the published packages.