Skip to content

Add missing code fixers for 10 analyzer rules#1073

Merged
meziantou merged 7 commits intomainfrom
meziantou/add-missing-code-fixers
Mar 30, 2026
Merged

Add missing code fixers for 10 analyzer rules#1073
meziantou merged 7 commits intomainfrom
meziantou/add-missing-code-fixers

Conversation

@meziantou
Copy link
Copy Markdown
Owner

Summary

This PR adds missing code fix support for a set of existing analyzer rules so users can apply fixes directly from diagnostics instead of addressing them manually.

It implements code fix providers for the requested rules, extends an existing LINQ fixer for MA0063, and updates rule tests and generated documentation accordingly.

What changed

  • Added new code fixers:
    • UseIFormatProviderFixer (MA0011)
    • UseRegexExplicitCaptureOptionsFixer (MA0023)
    • EmbedCaughtExceptionAsInnerExceptionFixer (MA0054)
    • TypeNameShouldEndWithSuffixFixer (MA0057, MA0058, MA0059)
    • NonFlagsEnumsShouldNotBeMarkedWithFlagsAttributeFixer (MA0062)
    • DoNotNaNInComparisonsFixer (MA0082)
  • Extended OptimizeLinqUsageFixer to support MA0063 (reorder Where before ordering operations).
  • Updated OptionalParametersAttributeFixer to support both optional-attribute diagnostics paths (MA0087 and MA0088) after merging with latest main changes.
  • Added/updated tests for each requested rule in existing analyzer test files.
  • Regenerated docs (README.md, docs/README.md, and affected docs/Rules/MAxxxx.md files).
  • Updated DocumentationGenerator root detection to work in git worktrees by accepting .git as directory or file.

Validation

  • dotnet build Meziantou.Analyzer.slnx
  • dotnet test Meziantou.Analyzer.slnx
  • dotnet test Meziantou.Analyzer.slnx --filter "FullyQualifiedName~OptionalParametersAttributeAnalyzerMA0087Tests|FullyQualifiedName~OptionalParametersAttributeAnalyzerMA0088Tests"
  • dotnet run --project src/DocumentationGenerator (re-run until clean)

Notes for reviewers

  • MA0063 support was added to an existing shared LINQ fixer rather than a separate provider to keep behavior aligned with existing LINQ transforms.
  • OptionalParametersAttributeFixer now handles both MA0087 and MA0088 so both diagnostic paths have matching fixes after recent upstream changes.

meziantou and others added 3 commits March 30, 2026 16:22
…A0059, MA0062, MA0063, MA0082, and MA0087

Implement missing code fix providers for the requested diagnostics, extend OptimizeLinqUsageFixer for MA0063, and add tests/docs updates for the new fixes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove dead helper and simplify operand selection logic to avoid IDE0051/IDE0059 failures in CI.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use attribute constructor symbol to map GeneratedRegex attribute arguments by parameter so the RegexOptions argument is correctly identified with roslyn4.2/4.4.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meziantou meziantou marked this pull request as ready for review March 30, 2026 21:09
Add DoNotNaN tests for double/float/Half, update Half handling in the fixer, and update MA0023 fixer to produce simplifiable RegexOptions.ExplicitCapture output with corresponding test expectations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/DocumentationGenerator/Program.cs Outdated
meziantou and others added 3 commits March 30, 2026 18:34
Allow MA0011 analyzer/fixer to use overloads with optional parameters, add tests for non-last IFormatProvider and named argument insertion, and resolve Half via compilation metadata in the NaN fixer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Show InvariantCulture first in UseIFormatProviderFixer and update MA0011 code-fix tests to validate both offered fixes by index while keeping the default fix aligned with the first suggestion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meziantou meziantou merged commit e8e19b7 into main Mar 30, 2026
13 checks passed
@meziantou meziantou deleted the meziantou/add-missing-code-fixers branch March 30, 2026 23:52
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