Skip to content

Add MA0188: Use System.TimeProvider instead of a custom time abstraction#1055

Merged
meziantou merged 7 commits intomainfrom
copilot/add-timeprovider-interface-rule
Mar 9, 2026
Merged

Add MA0188: Use System.TimeProvider instead of a custom time abstraction#1055
meziantou merged 7 commits intomainfrom
copilot/add-timeprovider-interface-rule

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

  • Add UseTimeProviderInsteadOfInterface = "MA0188" to RuleIdentifiers.cs
  • Create UseTimeProviderInsteadOfInterfaceAnalyzer.cs analyzer (enabled by default, DiagnosticSeverity.Info)
  • Create docs/Rules/MA0188.md documentation
  • Create test file UseTimeProviderInsteadOfInterfaceAnalyzerTests.cs (14 tests, all passing)
  • Run dotnet run --project src/DocumentationGenerator to update generated docs
  • Remove redundant hasAtLeastOneTimeMember tracking
  • Use the same name list for both properties and methods: Now, UtcNow, GetNow, GetUtcNow, CurrentTime
  • CurrentTime now reports a diagnostic; test updated accordingly
  • Mention Microsoft.Bcl.TimeProvider NuGet package in docs for older TFM support
  • Rule enabled by default (isEnabledByDefault: true)
  • Ensure member is not static before flagging as time-provider-like
  • Simplify IsDateTimeOrDateTimeOffset — rely on IsEqualTo's built-in null handling
  • Remove configuration section from docs/Rules/MA0188.md

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copilot AI changed the title [WIP] Add rule to check for specific time-related interfaces Add MA0188: Use System.TimeProvider instead of a custom time abstraction Mar 9, 2026
Comment thread src/Meziantou.Analyzer/Rules/UseTimeProviderInsteadOfInterfaceAnalyzer.cs Outdated
Comment thread src/Meziantou.Analyzer/Rules/UseTimeProviderInsteadOfInterfaceAnalyzer.cs Outdated
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Comment thread docs/Rules/MA0188.md
Comment thread docs/Rules/MA0188.md Outdated
… docs

Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Comment thread src/Meziantou.Analyzer/Rules/UseTimeProviderInsteadOfInterfaceAnalyzer.cs Outdated
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
…et null checks

Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Comment thread docs/Rules/MA0188.md Outdated
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
@meziantou meziantou marked this pull request as ready for review March 9, 2026 22:31
@meziantou meziantou merged commit 1379741 into main Mar 9, 2026
13 checks passed
This was referenced Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants