-
Couldn't load subscription status.
- Fork 6.1k
Document code analysis rules CA1873, CA1874, CA1875, CA2023 #49492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Added complete documentation for: - CA1873: Avoid potentially expensive logging - CA1874: Use 'Regex.IsMatch' - CA1875: Use 'Regex.Count' - CA2023: Invalid braces in message template Each documentation includes: - Rule description and cause - How to fix violations with code examples in both C# and VB - When to suppress warnings - Related links and API references - Updated index.md with all four rules in correct sequence Co-authored-by: gewarren <[email protected]>
Added missing metadata fields to match existing rule documentation: - ms.topic: reference - author: gewarren Co-authored-by: gewarren <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR documents four previously undocumented code analysis rules from the .NET SDK repository. The changes add comprehensive documentation for CA1873 (expensive logging operations), CA1874 (Regex.IsMatch optimization), CA1875 (Regex.Count optimization), and CA2023 (invalid message template braces). Each new documentation page includes rule metadata, violation examples in both C# and Visual Basic, fix examples, suppression guidance, and relevant API references.
Key Changes
- Added four new rule documentation files with complete examples and guidance
- Updated index and category pages to include the new rules
- Updated table of contents to link to the new rule pages
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| ca1873.md | Documents CA1873 rule for avoiding expensive logging operations with IsEnabled guards |
| ca1874.md | Documents CA1874 rule for preferring Regex.IsMatch over Match().Success |
| ca1875.md | Documents CA1875 rule for preferring Regex.Count over Matches().Count |
| ca2023.md | Documents CA2023 rule for detecting invalid braces in logging message templates |
| index.md | Adds entries for the four new rules in the main rules index table |
| performance-warnings.md | Adds CA1873, CA1874, and CA1875 to the performance rules listing |
| reliability-warnings.md | Adds CA2023 to the reliability rules listing |
| toc.yml | Adds table of contents entries for all four new rule pages |
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes LGTM
The SDK repository lists four code analysis rules without corresponding documentation.
Changes
Added complete documentation for:
CA1873: Avoid potentially expensive logging - Flags expensive operations (object creation, invocations, string joins) in logging arguments that execute regardless of log level. Recommends
ILogger.IsEnabledguards.CA1874: Use 'Regex.IsMatch' - Suggests replacing
Regex.Match(...).Successwith the more efficientRegex.IsMatch(...).CA1875: Use 'Regex.Count' - Suggests replacing
Regex.Matches(...).Countwith the more efficientRegex.Count(...).CA2023: Invalid braces in message template - Detects malformed braces in logging templates that cause runtime errors (unmatched, improperly nested).
Each includes rule metadata, violation/fix examples in C# and VB, suppression guidance, and API references. Updated
index.mdwith entries in correct sequence.Example
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/dotnet/roslyn-analyzers/contents/src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.mdcurl -s REDACTED(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Internal previews