Skip to content
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

Fix S3900 FP: assigned parameters #7044

Merged
merged 43 commits into from
Apr 19, 2023

Conversation

zsolt-kolbay-sonarsource
Copy link
Contributor

@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource commented Apr 6, 2023

Fixes #6972
Fixes #3400

Copy link

@MaStr11 MaStr11 left a comment

Choose a reason for hiding this comment

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

More tests are needed.

Copy link
Contributor

@antonioaversa antonioaversa left a comment

Choose a reason for hiding this comment

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

Very good improvement for S3900, solves quite a few FP!
I have just some minor remarks, mostly cosmetics.
@martin-strecker-sonarsource already identified pretty much all the interesting scenarios which would be good to have here.

Copy link
Contributor

Choose a reason for hiding this comment

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

You accidentally delete some code after re-basing which caused a lot of changes in the ITs. You need to revert the line and re-create the ITs.
Test coverage looks good now.

Copy link
Contributor

@antonioaversa antonioaversa left a comment

Choose a reason for hiding this comment

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

LGTM: all my remarks have been addressed.
Martin's ones to be addressed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Some more corrections.

"location": {
"uri": "sources\Ember-MM\Ember%20Media%20Manager\clsTheming.vb",
"region": {
"startLine": 169,

Choose a reason for hiding this comment

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

"location": {
"uri": "sources\Ember-MM\Ember.Plugins\Utility.cs",
"region": {
"startLine": 46,

Choose a reason for hiding this comment

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

Both are TN:

public static string SanitiseIMDbId(string imdbId)
{
if (string.IsNullOrEmpty(imdbId) || imdbId.Trim().Length == 0)
return string.Empty;
imdbId = imdbId.Trim();
if ("tt".Equals(imdbId))
imdbId = string.Empty;
else
{
if (!imdbId.StartsWith("tt"))
imdbId = string.Concat("tt", imdbId);
if (imdbId.Length != 9)
imdbId = string.Empty;
}
return imdbId;
}

"location": {
"uri": "sources\Ember-MM\EmberAPI\clsAPIFileUtils.vb",
"region": {
"startLine": 113,

Choose a reason for hiding this comment

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

All issues are gone except the first one on line 112

Public Shared Function MakeValidFilename(ByVal filename As String) As String
filename = filename.Replace(":", " -")
filename = filename.Replace("/", String.Empty)
'pattern = pattern.Replace("\", String.Empty)
filename = filename.Replace("|", String.Empty)
filename = filename.Replace("<", String.Empty)
filename = filename.Replace(">", String.Empty)
filename = filename.Replace("?", String.Empty)
filename = filename.Replace("*", String.Empty)
filename = filename.Replace(" ", " ")
Return filename
End Function

"location": {
"uri": "sources\Ember-MM\Addons\scraper.EmberCore.XML\XMLScraper\Utilities\Util.vb",
"region": {
"startLine": 188,

Choose a reason for hiding this comment

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

Here too:

Public Shared Function FixParse(ByVal value As String) As String
value = value.Replace("&", "&amp;")
value = value.Replace("&amp;amp;", "&amp;")
value = value.Replace("&amp;amp;amp;", "&amp;&amp;")
value = value.Replace("&amp;#", "&#")
value = value.Replace("&amp;quot;", "&quot;")
value = value.Replace("&amp;lt;", "&lt;")
value = value.Replace("&amp;gt;", "&gt;")
value = value.Replace("&amp;apos;", "&apos;")
Return value
End Function

"location": {
"uri": "sources\Nancy\src\Nancy\Helpers\HttpUtility.cs",
"region": {
"startLine": 192,

Choose a reason for hiding this comment

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

TN (reassign in line 148)

"location": {
"uri": "sources\akka.net\src\core\Akka.Remote.TestKit\MultiNodeSpec.cs",
"region": {
"startLine": 549,

Choose a reason for hiding this comment

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

TN:

public void MuteDeadLetters(ActorSystem system = null, params Type[] messageClasses)
{
if (system == null) system = Sys;
if (!system.Log.IsDebugEnabled)

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM. Please fix the comment if appropriate and create a follow-up issue for the remaining operations or reuse an existing issue for the tracking.

@@ -67,4 +83,10 @@ private static IOperation NullDereferenceCandidate(IOperation operation)
};
return candidate?.UnwrapConversion();
}

private static IOperation AssignmentTarget(IOperation operation) =>
// Missing operation types: DeconstructionAssignment, CoalesceAssignment, CompoundAssignment, ThrowExpression

Choose a reason for hiding this comment

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

I think "assignment with flow capture" is missing here, right?

Suggested change
// Missing operation types: DeconstructionAssignment, CoalesceAssignment, CompoundAssignment, ThrowExpression
// Missing operation types: DeconstructionAssignment, CoalesceAssignment, CompoundAssignment, ThrowExpression, assignment with flow capture

@@ -67,4 +83,10 @@ private static IOperation NullDereferenceCandidate(IOperation operation)
};
return candidate?.UnwrapConversion();
}

private static IOperation AssignmentTarget(IOperation operation) =>
// Missing operation types: DeconstructionAssignment, CoalesceAssignment, CompoundAssignment, ThrowExpression
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have an issue that tracks all the missing operations? If not, create one and link any other issues that mentions parts of it. Add a checklist with all the missing operations to that issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#7091
I did not add for compound assignment - as it doesn't make much sense here -, nor for ThrowExpression. This seems to work fine:

public void ThrowExpression(object o)
{
    _ = o ?? throw new NullReferenceException(nameof(o));
    o.ToString();
}

Choose a reason for hiding this comment

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

Please link to #7039 in the issue as well. Please add all cases we discussed so far. Even if they are working already, we need to make sure we have all cases under test. "This seems to work fine." is not enough.

@sonarcloud
Copy link

sonarcloud bot commented Apr 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Apr 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource merged commit 6f7cdab into master Apr 19, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource deleted the Zsolt/S3900-parameter-assignment branch April 19, 2023 08:52
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.

S3900 FP: Ignore parameters with assigned values S3900 FP: when parameter reassigned from a method
5 participants