-
-
Notifications
You must be signed in to change notification settings - Fork 63
Fix MA0011 not reported for types with ToString(IFormatProvider) but no IFormattable #910
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
…ut implementing IFormattable Co-authored-by: meziantou <[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 refactors the OverloadFinder API to use new structured types (OverloadOptions and OverloadParameterType) for better encapsulation and extensibility. It also enhances the culture-sensitive type detection to recognize types with ToString(IFormatProvider) methods even when they don't implement IFormattable.
- Introduced
OverloadOptionsrecord struct to consolidate multiple boolean and nullable parameters into a single options object - Introduced
OverloadParameterTyperecord struct to support inheritance-based type matching for overload parameters - Enhanced
IsCultureSensitiveTypelogic to detect types withToString(IFormatProvider)overloads that don't implementIFormattable
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Meziantou.Analyzer/Internals/OverloadParameterType.cs | New record struct for parameter type specification with optional inheritance support |
| src/Meziantou.Analyzer/Internals/OverloadOptions.cs | New record struct to consolidate overload finder options |
| src/Meziantou.Analyzer/Internals/OverloadFinder.cs | Refactored to use new option types, added overloads for IOperation types, and improved type matching logic |
| src/Meziantou.Analyzer/Internals/CultureSensitiveFormattingContext.cs | Enhanced to detect formattable types without IFormattable interface; moved format provider check earlier |
| src/Meziantou.Analyzer/Rules/UseIFormatProviderAnalyzer.cs | Updated to use new OverloadFinder API with OverloadOptions |
| src/Meziantou.Analyzer/Rules/UseStringComparisonAnalyzer.cs | Updated to use new OverloadFinder API with OverloadOptions |
| src/Meziantou.Analyzer/Rules/UseStringComparerAnalyzer.cs | Updated to use new OverloadFinder API with OverloadOptions |
| src/Meziantou.Analyzer/Rules/UseAnOverloadThatHasTimeProviderAnalyzer.cs | Updated to use new OverloadFinder API with OverloadOptions |
| src/Meziantou.Analyzer/Rules/UseAnOverloadThatHasCancellationTokenAnalyzer.cs | Updated to use new OverloadFinder API with OverloadOptions |
| src/Meziantou.Analyzer/Rules/EmbedCaughtExceptionAsInnerExceptionAnalyzer.cs | Updated to use new OverloadFinder API with OverloadOptions |
| src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs | Updated to use new static HasSimilarParameters API |
| tests/Meziantou.Analyzer.Test/Rules/UseIFormatProviderAnalyzerTests.cs | Added test for types with ToString(IFormatProvider) overload without IFormattable |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
MA0011 was not reported when a type declares both
ToString()andToString(IFormatProvider)but does not implementIFormattable. The analyzer's culture-sensitivity check would exit early for non-IFormattabletypes before checking for the overload.Changes
ToString()calls withIFormatProvideroverload before culture-sensitive type validationToString_WithIFormatProviderOverload_WithoutIFormattabletest caseWarning
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:
www.nuget.org/usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/Meziantou.Analyzer.Test.runtimeconfig.json --depsfile /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/Meziantou.Analyzer.Test.deps.json /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/testhost.dll --port 44033 --endpoint 127.0.0.1:044033 --role client --parentprocessid 4755 --datacollectionport 38543 --telemetryoptedin false(dns block)/usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/Meziantou.Analyzer.Test.runtimeconfig.json --depsfile /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/Meziantou.Analyzer.Test.deps.json /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/testhost.dll --port 38109 --endpoint 127.0.0.1:038109 --role client --parentprocessid 5088 --datacollectionport 45743 --telemetryoptedin false(dns block)/usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/Meziantou.Analyzer.Test.runtimeconfig.json --depsfile /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/Meziantou.Analyzer.Test.deps.json /home/REDACTED/work/Meziantou.Analyzer/Meziantou.Analyzer/tests/Meziantou.Analyzer.Test/bin/Debug/net10.0/testhost.dll --port 46211 --endpoint 127.0.0.1:046211 --role client --parentprocessid 5480 --datacollectionport 45673 --telemetryoptedin false(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.