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

Modify S3247: Improve description and update example #4019

Merged
merged 2 commits into from
Jul 1, 2024

Conversation

sebastien-marichal
Copy link
Contributor

@sebastien-marichal sebastien-marichal commented Jun 28, 2024

Copy link
Contributor

@mary-georgiou-sonarsource mary-georgiou-sonarsource left a comment

Choose a reason for hiding this comment

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

LGTM - minor polishing

@@ -1,11 +1,21 @@
== Why is this an issue?

Because the ``++is++`` operator performs a cast if the object is not null, using ``++is++`` to check type and then casting the same argument to that type, necessarily performs two casts. The same result can be achieved more efficiently with a single cast using ``++as++``, followed by a null-check.
In C#, the https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#is-operator[`is` type testing operator] can be used to check if the run-time type of an object is compatible with a given type. If the check is successful, it means the code performed a cast. Performing another cast following the check result into a duplicate cast.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In C#, the https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#is-operator[`is` type testing operator] can be used to check if the run-time type of an object is compatible with a given type. If the check is successful, it means the code performed a cast. Performing another cast following the check result into a duplicate cast.
In C#, the https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#is-operator[`is` type testing operator] can be used to check if the run-time type of an object is compatible with a given type. If the object is not null, then the `is` operator performs a cast, and so performing another cast following the check result is redundant.


=== Message

Primary: Replace this type-check-and-cast sequence with an "as" and a null check.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Primary: Replace this type-check-and-cast sequence with an "as" and a null check.
Primary: "Replace this type-check-and-cast sequence to use pattern matching."

@sebastien-marichal sebastien-marichal enabled auto-merge (squash) July 1, 2024 13:34
Copy link

sonarqube-next bot commented Jul 1, 2024

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@sebastien-marichal sebastien-marichal merged commit fee05d9 into master Jul 1, 2024
9 of 11 checks passed
@sebastien-marichal sebastien-marichal deleted the sma/modify-s3247 branch July 1, 2024 13:37
Copy link

sonarqube-next bot commented Jul 1, 2024

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants