Clean up assorted analyzer warnings (S1066, S1192, S6444, CA1309, CA1825)#88
Merged
Merged
Conversation
…825)
A focused batch of safe, valuable analyzer fixes. No behavior change;
both .NET Framework 4.8 projects build and all 96 tests pass.
- S6444 (InformationBoxForm.cs): the auto-close label Regex
`new Regex(@".*?\(\d+\)")` now passes a 1-second timeout, hardening
against pathological matching (matches the timeout convention already
used in TextHelper).
- CA1309 (InformationBoxForm.cs): the "Help" button-name check uses
StringComparison.Ordinal. The Name is a programmatic identifier, so
ordinal is both correct and faster than the implicit culture-aware
comparison.
- S1192 (InformationBoxForm.cs): the auto-close countdown format string
"{0} ({1})", repeated 4x, is extracted to a ButtonCountdownFormat const.
- S1066 (InformationBoxDesigner.cs): two nested `if` statements in
GetAutoClose() are merged into single conditions with `&&`.
- CA1825 (InformationBoxArgsParserTests.cs): two `new T[0]` allocations
replaced with Array.Empty<T>().
Deliberately left untouched (with reasons):
- S2342 (rename InformationBoxCheckBox): would break the public API.
- S1450 (definedParameters -> local): false positive; the field is read
cross-instance via InformationBoxScope.Current.definedParameters.
- S3878 (PaintingEngine AddLines): false positive; GraphicsPath.AddLines
has no params overload, so the array is required.
- S3011 (reflection on OnHelpRequested): intentional and necessary to
trigger help on an arbitrary parent form; review-only warning.
- S1075 (hardcoded lorem-api URL), S3267 (loop->LINQ): low value /
would reduce clarity.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extracting the auto-close format string to a const (previous commit) made the analyzer surface CA1863, which suggests caching a System.Text.CompositeFormat. CompositeFormat only exists on .NET 8+, but the shared source also compiles on .NET Framework 4.8, so the suggested fix is unavailable - the same dual-build constraint that already applies to CA2263. Suppressed in .editorconfig with the same rationale, keeping the readability win of the named const without trading it for four unfixable warnings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
Author
|
Follow-up commit on this branch: extracting the format string to a const surfaced CA1863 ×4 (suggests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A focused batch of safe, valuable analyzer fixes — and an explicit list of what I deliberately left alone and why. No behavior change; both .NET Framework 4.8 projects build and all 96 tests pass.
Fixed (7 warnings)
InformationBoxForm.csRegexnow passes a 1-second timeout (new Regex(@"…", RegexOptions.None, TimeSpan.FromSeconds(1))), hardening against pathological matching. Matches the timeout convention already used inTextHelper.InformationBoxForm.csName.Equals("Help")→Equals("Help", StringComparison.Ordinal). The controlNameis a programmatic identifier — ordinal is both correct and faster.InformationBoxForm.cs"{0} ({1})"(used 4×) extracted to aButtonCountdownFormatconst.InformationBoxDesigner.csifblocks inGetAutoClose()merged into single&&conditions.InformationBoxArgsParserTests.csnew T[0]→Array.Empty<T>().Deliberately NOT changed (with reasons)
InformationBoxCheckBox)definedParameters→ local)InformationBoxScope.Current.definedParameters, so it can't be a local.PaintingEngine.AddLines)GraphicsPath.AddLineshas noparamsoverload, so the explicit array is required.OnHelpRequested)This leaves the remaining warnings as the genuinely "design-level" ones (S3776 cognitive complexity ×10, S107 too-many-params ×4) that touch the public API shape and warrant separate discussion rather than a mechanical fix.
Test plan
msbuild InfoBox.csproj+InfoBox.Designer.csproj(.NET 4.8) — builddotnet test— InfoBoxCore.Tests 88/88, InfoBoxCore.Designer.Tests 8/8🤖 Generated with Claude Code