Skip to content

Add configurable SQLite special cases for MA0042 and MA0045#1128

Merged
meziantou merged 2 commits intomainfrom
meziantou/sqlite-createcommand
May 5, 2026
Merged

Add configurable SQLite special cases for MA0042 and MA0045#1128
meziantou merged 2 commits intomainfrom
meziantou/sqlite-createcommand

Conversation

@meziantou
Copy link
Copy Markdown
Owner

@meziantou meziantou commented May 5, 2026

SQLite async recommendations in MA0042/MA0045 were previously hardcoded for SqliteConnection.CreateCommand(). Because SQLite types are not sealed and derived implementations may provide meaningful async behavior, this change makes SQLite exceptions configurable and extends the coverage to the commonly reported command execution methods.

What changed

  • Added a new analyzer option: MA0042.enable_sqlite_special_cases (default: true).
  • Gated all SQLite-specific behavior behind this option for both MA0042 and MA0045.
  • Expanded SQLite special-case method coverage to:
    • SqliteConnection.CreateCommand()
    • SqliteCommand.ExecuteNonQuery()
    • SqliteCommand.ExecuteScalar()
    • SqliteCommand.ExecuteReader()
  • Updated MA0042 and MA0045 documentation with the expanded SQLite behavior and configuration.
  • Added regression tests for:
    • MA0042 and MA0045 no-diagnostic behavior when special cases are enabled.
    • MA0042 and MA0045 diagnostics when MA0042.enable_sqlite_special_cases = false.
    • Metadata-based API contract validation that SqliteConnection.CreateCommand() returns SqliteCommand.

Notable implementation detail

Invocation-level method caching in DoNotUseBlockingCallInAsyncContextAnalyzer was adjusted so SQLite-special-case methods are not cached as permanently "no async equivalent". This avoids stale behavior when the new configuration is toggled.

Validation

  • Ran targeted SQLite MA0042/MA0045 tests (including option-disabled scenarios and PEReader contract test).
  • Regenerated documentation with DocumentationGenerator.
  • Ran full solution tests (Meziantou.Analyzer.slnx).

Fix #1121

meziantou and others added 2 commits May 5, 2026 13:59
Add opt-out config (MA0042.enable_sqlite_special_cases), extend SQLite method coverage, update docs, and add regression tests for MA0042/MA0045 including option-disabled behavior and API contract validation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meziantou meziantou merged commit ed8da2e into main May 5, 2026
13 checks passed
@meziantou meziantou deleted the meziantou/sqlite-createcommand branch May 5, 2026 18:54
This was referenced May 5, 2026
This was referenced May 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.

MA0045 shouldn't trigger on ADO.NET SQLite

1 participant