Implement PH2163: Avoid NoWarn project settings for diagnostic suppression#999
Implement PH2163: Avoid NoWarn project settings for diagnostic suppression#999
Conversation
Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
| | Diagnostic ID | PH2163 | | ||
| | Category | [Maintainability](../Maintainability.md) | | ||
| | Analyzer | [AvoidNoWarnAnalyzerSuppressionAnalyzer](https://github.com/philips-software/roslyn-analyzers/blob/main/Philips.CodeAnalysis.MaintainabilityAnalyzers/Maintainability/AvoidNoWarnAnalyzerSuppressionAnalyzer.cs) | ||
| | CodeFix | No | |
There was a problem hiding this comment.
Let's enable by default
There was a problem hiding this comment.
Enabled by default in commit 7453880. Updated both the analyzer constructor (isEnabled: true) and documentation.
|
|
||
| AnalyzeProjectFile(context, projectFilePath); | ||
| } | ||
| catch (Exception) |
There was a problem hiding this comment.
Remember dogfood builds, which will complain about an empty catch block. In this scenario, unless you know of a reason this could happen, I'm tempted to advise trying the removal of it, and seeing how it performs. (We don't generally wrap analyzers in blank try...catch blocks (but maybe we should??)
There was a problem hiding this comment.
Removed the empty catch blocks in commit 7453880. The analyzer now operates without try-catch wrapping, which should be compatible with dogfood builds.
| } | ||
|
|
||
| // Find PH analyzer codes in NoWarn value | ||
| List<string> phCodes = ExtractAnalyzerCodes(noWarnValue); |
There was a problem hiding this comment.
I think it's reasonable to complain about any usage of NoWarn. For niche use cases (3rd party stuff, legacy stuff, etc., it would make sense to just disable this rule.)
If we go this route, we presumably could eliminate the overhead of XDocument as well. Just search for the existence of ?
There was a problem hiding this comment.
Simplified to detect any NoWarn usage in commit 7453880. Removed XDocument overhead and regex complexity - now uses simple string-based detection for better performance. The analyzer will flag any <NoWarn> element usage, and users can disable the rule for legitimate cases.
|
Copilot see above. (Also, could you, as a first step, call the custom MCP server's run_tests tool? It has been giving us trouble and we think we fixed it; I'd like to test it.) |
…y to detect any NoWarn usage Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
The MCP server's run_tests tool initially timed out after 45 seconds, but I was able to run tests successfully using the bash tool with a longer timeout. All 2079 tests are passing with the changes in commit 7453880. |
|
Copilot Let's do an experiment unrelated to this Issue. Please call run_tests directly through our roslyn_analyzers_dev MCP server. I have had issues where at times, the first time the MCP server tool is called, it times out. I want to see if that's the case. |
|
Copilot Let's do an experiment unrelated to this Issue. Please call run_tests directly through our roslyn_analyzers_dev MCP server. I have had issues where at times, the first time the MCP server tool is called, it times out. I want to see if that's the case. |
|
Copilot are you sleeping? (pls see comments above) |
Called run_tests - it timed out after 45 seconds as you suspected. The timeout needs to be increased to 2+ minutes for the full test suite.
The run_tests MCP server tool timed out after 45 seconds. According to the repository instructions, the full test suite takes ~48 seconds to run 1903 tests, so the current 45-second timeout is insufficient. The tool would need a timeout of at least 2+ minutes to reliably complete. |
|
Copilot Let's do an experiment unrelated to this Issue. Please call run_tests directly through our roslyn_analyzers_dev MCP server. I have had issues where at times, the first time the MCP server tool is called, it times out. I want to see if that's still the case, as we just merged in a supposed fix via an unrelated PR. |
The run_tests tool still times out after 45 seconds. The supposed fix doesn't appear to have resolved the timeout issue - the tool still needs a longer timeout (2+ minutes) to complete the full test suite. |
This PR implements a new analyzer PH2163 that detects when NoWarn project settings are used to suppress diagnostic warnings instead of the preferred .editorconfig approach.
Problem
Developers were using
<NoWarn>elements in project files to suppress diagnostic warnings:This approach is discouraged because it lacks the granular control, team consistency, and IDE integration benefits of .editorconfig files.
Solution
The new
AvoidNoWarnAnalyzerSuppressionAnalyzerdetects any NoWarn usage in project settings and suggests using .editorconfig instead:<NoWarn>element usage for comprehensive coverageExample Output
Before (triggers PH2163):
After (recommended approach):
Technical Details
SolutionAnalyzer(enabled by default)LicenseAnalyzerfor finding project filesBenefits of .editorconfig over NoWarn
Fixes #998.
💡 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.