Skip to content

Add code fixers for MA0118, MA0161, and MA0186#1079

Merged
meziantou merged 5 commits intomainfrom
add-ma0118-ma0161-ma0186-fixers
Mar 31, 2026
Merged

Add code fixers for MA0118, MA0161, and MA0186#1079
meziantou merged 5 commits intomainfrom
add-ma0118-ma0161-ma0186-fixers

Conversation

@meziantou
Copy link
Copy Markdown
Owner

Why

These three analyzers already reported useful diagnostics but lacked automatic remediation, which made adoption slower and more manual. This change adds code fixers so developers can apply safe, consistent fixes directly from the IDE.

What changed

  • Added a new code fixer for MA0118 ([JSInvokable] methods must be public) that updates method accessibility to public while preserving other modifiers (for example static).
  • Added a new code fixer for MA0161 (UseShellExecute must be explicitly set) that offers both actions:
    • Set UseShellExecute to false
    • Set UseShellExecute to true
      and handles both new ProcessStartInfo() and object initializers with existing members.
  • Added a new code fixer for MA0186 (Equals/TryGetValue nullable attributes) that:
    • adds or updates [NotNullWhen(true)] on Equals parameters
    • adds or updates [MaybeNullWhen(false)] on TryGetValue out value parameters
  • Extended rule tests to validate the new fixers and fix-all behavior patterns for these rules.
  • Regenerated documentation with src/DocumentationGenerator, which updated rule source links and the README/docs fixer support matrix.

Notes for reviewers

  • MA0161 intentionally exposes two code actions (true/false) because both are semantically valid depending on caller intent.
  • The MA0118 tests were split into targeted code-fix cases to align with the test harness behavior that applies one fix option at a time.
  • A Roslyn 4.2 targeted run could not be used due to unrelated baseline repository incompatibilities with older APIs; targeted validation was completed on default and Roslyn 4.14.

Validation

  • dotnet test tests\Meziantou.Analyzer.Test\Meziantou.Analyzer.Test.csproj --filter "FullyQualifiedName~ProcessStartAnalyzerTests|FullyQualifiedName~MissingNotNullWhenAttributeOnEqualsAnalyzerTests|FullyQualifiedName~JSInvokableMethodsMustBePublicAnalyzerTests" --nologo
  • dotnet test tests\Meziantou.Analyzer.Test\Meziantou.Analyzer.Test.csproj /p:RoslynVersion=roslyn4.14 --filter "FullyQualifiedName~ProcessStartAnalyzerTests|FullyQualifiedName~MissingNotNullWhenAttributeOnEqualsAnalyzerTests|FullyQualifiedName~JSInvokableMethodsMustBePublicAnalyzerTests" --nologo
  • dotnet run --project src\DocumentationGenerator

meziantou and others added 4 commits March 30, 2026 22:35
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meziantou meziantou marked this pull request as ready for review March 31, 2026 03:00
@meziantou meziantou enabled auto-merge (squash) March 31, 2026 03:00
@meziantou meziantou merged commit 770d2f6 into main Mar 31, 2026
13 checks passed
@meziantou meziantou deleted the add-ma0118-ma0161-ma0186-fixers branch March 31, 2026 03:06
This was referenced Mar 31, 2026
This was referenced Apr 12, 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.

1 participant