This repository was archived by the owner on May 27, 2026. It is now read-only.
fix: resolve 5 SonarQube code quality issues#4
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Conversation
Fixed issues: - AYfoIk2_8V9JdHvWDELx for csharpsquid:S3220 rule - AYfoIk2U8V9JdHvWDELv for csharpsquid:S3963 rule - AYfoIk1e8V9JdHvWDELr for csharpsquid:S3963 rule - AYfoIk_48V9JdHvWDEMU for csharpsquid:S3963 rule - AYfoIk0Y8V9JdHvWDELp for csharpsquid:S3963 rule Generated by SonarQube Agent (task: 3eb622f9-1f5b-4626-ade5-b4cfd26e6011)
|
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.



Eliminates ambiguous method overload resolution and removes unnecessary static constructors by inlining static field initializations. These changes improve code clarity and reduce unnecessary performance overhead from compiler-generated static constructor checks.
View Project in SonarCloud
Fixed Issues
csharpsquid:S3220 - Review this call, which partially matches an overload without 'params'. The partial match is 'string[] string.Split(char separator, int count, StringSplitOptions options = StringSplitOptions.None)'. • MINOR • View issue
Location:
src/Cake.Common/Tools/NuGet/List/NuGetList.cs:77Why is this an issue?
The rules for method resolution are complex and perhaps not properly understood by all coders. The
paramskeyword can make method declarations overlap in non-obvious ways, so that slight changes in the argument types of an invocation can resolve to different methods.What changed
This hunk fixes the ambiguous method resolution warning on
string.Split. The original callline.Split(' ', '\t')with twochararguments partially matches the overloadstring.Split(char separator, int count, StringSplitOptions options)because the secondcharcould be implicitly converted toint. By changing the call toline.Split(new[] { ' ', '\t' }, StringSplitOptions.None), the invocation now explicitly targets theSplit(char[], StringSplitOptions)overload, eliminating the ambiguity between theparams-based overload and the non-paramsoverload.csharpsquid:S3963 - Initialize all 'static fields' inline and remove the 'static constructor'. • MINOR • View issue
Location:
src/Cake.Common/Tools/Cake/CakeRunner.cs:34Why is this an issue?
When a
staticconstructor serves no other purpose that initializingstaticfields, it comes with an unnecessary performance cost because the compiler generates a check before eachstaticmethod or instance constructor invocation.What changed
This hunk inlines the initialization of the static field
_executingAssemblyToolPathsby assigning it directly at the declaration site via a helper methodGetExecutingAssemblyToolPaths(). This eliminates the need for a static constructor whose sole purpose was to initialize this static field, addressing the code smell about unnecessary static constructors that only initialize static fields.csharpsquid:S3963 - Initialize all 'static fields' inline and remove the 'static constructor'. • MINOR • View issue
Location:
src/Cake.Common/Build/MyGet/MyGetProvider.cs:24Why is this an issue?
When a
staticconstructor serves no other purpose that initializingstaticfields, it comes with an unnecessary performance cost because the compiler generates a check before eachstaticmethod or instance constructor invocation.What changed
This hunk removes the static constructor and inlines the initialization of the
_sanitizationTokensstatic field directly at its declaration. The static analysis rule flags static constructors that only initialize static fields, since they introduce unnecessary performance overhead (the compiler adds a beforefieldinit check before each static method or instance constructor call). By convertingprivate static readonly Dictionary<string, string> _sanitizationTokens;with a separatestatic MyGetProvider() { _sanitizationTokens = new Dictionary<string, string> ... }into a single inline initializationprivate static readonly Dictionary<string, string> _sanitizationTokens = new Dictionary<string, string> ..., the static constructor is eliminated and the performance cost is avoided.csharpsquid:S3963 - Initialize all 'static fields' inline and remove the 'static constructor'. • MINOR • View issue
Location:
src/Cake.Common/Tools/Chocolatey/Pack/ChocolateyNuSpecTransformer.cs:21Why is this an issue?
When a
staticconstructor serves no other purpose that initializingstaticfields, it comes with an unnecessary performance cost because the compiler generates a check before eachstaticmethod or instance constructor invocation.What changed
This hunk removes the static constructor and the separate field declarations for
_mappingsand_cdataElements, replacing the_mappingsfield with an inline initialization. The static analysis warning flagged the static constructor as unnecessary since it only initializes static fields. By inlining the initialization of_mappingsdirectly at the field declaration, this hunk eliminates part of the static constructor, addressing the performance cost associated with having a static constructor that only initializes static fields.csharpsquid:S3963 - Initialize all 'static fields' inline and remove the 'static constructor'. • MINOR • View issue
Location:
src/Cake.Common/Tools/NuGet/Pack/NuspecTransformer.cs:21Why is this an issue?
When a
staticconstructor serves no other purpose that initializingstaticfields, it comes with an unnecessary performance cost because the compiler generates a check before eachstaticmethod or instance constructor invocation.What changed
This hunk removes the static constructor and the separate field declarations for
_mappingsand_cdataElements, replacing the_mappingsfield with an inline initialization. The static analysis rule flags static constructors that only initialize static fields, recommending inline initialization instead to avoid the performance cost of compiler-generated checks before each static method or instance constructor invocation. By converting_mappingsfrom being assigned in the static constructor to being initialized inline at declaration, this hunk directly addresses the recommendation to remove the static constructor.SonarQube Remediation Agent uses AI. Check for mistakes.