Skip to content

Implement PH2163: Avoid NoWarn project settings for diagnostic suppression#999

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-998
Draft

Implement PH2163: Avoid NoWarn project settings for diagnostic suppression#999
Copilot wants to merge 4 commits intomainfrom
copilot/fix-998

Conversation

Copy link
Contributor

Copilot AI commented Sep 9, 2025

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:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <NoWarn>$(NoWarn);CS8002;PH2071</NoWarn>
  </PropertyGroup>
</Project>

This approach is discouraged because it lacks the granular control, team consistency, and IDE integration benefits of .editorconfig files.

Solution

The new AvoidNoWarnAnalyzerSuppressionAnalyzer detects any NoWarn usage in project settings and suggests using .editorconfig instead:

  • Detection: Scans project files (.csproj, .vbproj) found via source directory traversal
  • Simplified Logic: Detects any <NoWarn> element usage for comprehensive coverage
  • Performance: Lightweight string-based detection without XML parsing overhead
  • Error Handling: No try-catch blocks for dogfood build compliance
  • Diagnostic Message: Provides clear guidance with .editorconfig syntax

Example Output

Before (triggers PH2163):

<NoWarn>$(NoWarn);CS8002;PH2071</NoWarn>

After (recommended approach):

# .editorconfig
[*.cs]
dotnet_diagnostic.CS8002.severity = none
dotnet_diagnostic.PH2071.severity = none

Technical Details

  • Base Class: SolutionAnalyzer (enabled by default)
  • File Discovery: Uses proven pattern from LicenseAnalyzer for finding project files
  • String Detection: Simple case-insensitive string matching for performance
  • Dogfood Compliant: No empty catch blocks or analyzer violations

Benefits of .editorconfig over NoWarn

  1. Granular control: Configure different severities (none, suggestion, warning, error)
  2. File-specific configuration: Apply rules to specific file patterns
  3. Team consistency: Shared configuration across different IDEs and tools
  4. Version control friendly: Easy to track and review analyzer configuration changes
  5. IDE integration: Better support in Visual Studio and other editors

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.

Copilot AI and others added 2 commits September 9, 2025 16:39
Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
Copilot AI changed the title [WIP] PH2163: Avoid <NoWarn> Implement PH2163: Avoid NoWarn project settings for analyzer suppression Sep 9, 2025
| 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 |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's enable by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabled by default in commit 7453880. Updated both the analyzer constructor (isEnabled: true) and documentation.


AnalyzeProjectFile(context, projectFilePath);
}
catch (Exception)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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??)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bcollamore
Copy link
Member

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>
Copy link
Contributor Author

Copilot AI commented Sep 10, 2025

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.)

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 AI changed the title Implement PH2163: Avoid NoWarn project settings for analyzer suppression Implement PH2163: Avoid NoWarn project settings for diagnostic suppression Sep 10, 2025
@bcollamore
Copy link
Member

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.

@bcollamore
Copy link
Member

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.

@bcollamore
Copy link
Member

Copilot are you sleeping? (pls see comments above)

Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

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.

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 too...

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.

@bcollamore
Copy link
Member

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.

Copy link
Contributor Author

Copilot AI commented Oct 13, 2025

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 to...

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.

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.

PH2163: Avoid <NoWarn>

2 participants