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 S3254 FN: primary constructors #8222

Merged
merged 13 commits into from
Oct 26, 2023

Conversation

martin-strecker-sonarsource
Copy link
Contributor

@martin-strecker-sonarsource martin-strecker-sonarsource commented Oct 18, 2023

Fixes #8096
Also reverts #4620
Blocked by #8238

@martin-strecker-sonarsource martin-strecker-sonarsource changed the title Add object creation expression support Fix S3254 FN: primary constructors Oct 18, 2023
@@ -2,6 +2,58 @@
"issues": [
{
"id": "S3254",
"message": "Remove this default value assigned to parameter 'lifetime'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/Nancy/src/Nancy/Bootstrapper/NancyBootstrapperWithRequestContainerBase.cs#L125",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TP: Constructor:

.Select(tr => new TypeRegistration(tr.RegistrationType, tr.ImplementationType, Lifetime.Singleton)))

"id": "S3254",
"message": "Remove this default value assigned to parameter 'lifetime'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/Nancy/src/Nancy/Bootstrapper/NancyBootstrapperWithRequestContainerBase.cs#L134",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TP: Constructor

.Select(tr => new CollectionTypeRegistration(tr.RegistrationType, tr.ImplementationTypes, Lifetime.Singleton)))

"id": "S3254",
"message": "Remove this default value assigned to parameter 'disableMethodNotAllowedResponses'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/Nancy/src/Nancy/RouteConfiguration.cs#L12",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TP: Constructor:

public static readonly RouteConfiguration Default = new RouteConfiguration(
disableMethodNotAllowedResponses: false,

"id": "S3254",
"message": "Remove this default value assigned to parameter 'explicitHeadRouting'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/Nancy/src/Nancy/RouteConfiguration.cs#L13",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TP: Constructor

public static readonly RouteConfiguration Default = new RouteConfiguration(
disableMethodNotAllowedResponses: false,
explicitHeadRouting: false);

"id": "S3254",
"message": "Remove this default value assigned to parameter 'runtimeViewDiscovery'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/Nancy/src/Nancy/ViewConfiguration.cs#L12",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TP: Constructor

public static readonly ViewConfiguration Default = new ViewConfiguration(
runtimeViewDiscovery: false,
runtimeViewUpdates: false);

"id": "S3254",
"message": "Remove this default value assigned to parameter 'redeliveryBurstLimit'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/akka.net/src/core/Akka.Persistence/Persistence.cs#L464",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above:

return Copy(null, null, null, maxUnconfirmedMessages);

"id": "S3254",
"message": "Remove this default value assigned to parameter 'unconfirmedAttemptsToWarn'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/akka.net/src/core/Akka.Persistence/Persistence.cs#L464",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

return Copy(null, null, null, maxUnconfirmedMessages);

"id": "S3254",
"message": "Remove this default value assigned to parameter 'redeliverInterval'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/akka.net/src/core/Akka.Persistence/Persistence.cs#L474",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

"id": "S3254",
"message": "Remove this default value assigned to parameter 'redeliverInterval'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/akka.net/src/core/Akka.Persistence/Persistence.cs#L484",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two TPs:

return Copy(null, null, unconfirmedAttemptsToWarn);

@@ -54,6 +54,32 @@
},
{
"id": "S3254",
"message": "Remove this default value assigned to parameter 'writerGuid'.",
"location": {
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/akka.net/src/contrib/persistence/Akka.Persistence.Sql.Common/Journal/BatchingSqlJournal.cs#L1361",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I stopped here:
TP

return new Persistent(deserialized, sequenceNr, persistenceId, manifest, isDeleted, ActorRefs.NoSender, null, timestamp);

{
var hasDefaultValue = ArgumentHasDefaultValue(argumentMapping, c.SemanticModel);

Choose a reason for hiding this comment

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

I'm still not 100% sure about reverting a PR that we are not sure about why it was introduced in the first place. I suggest asking @pavel-mikula-sonarsource and if he's ok we can move on. With the current information, I think you are right, and even with methods with lengthy parameters, we should raise and suggest to use named arguments (see my other comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We got no feedback from @pavel-mikula-sonarsource until now. We either merge today before peach deployment or the PR will not be part of the release. There are only a few new issues in the ITs related to this change and the new issues are TPs (e.g. https://github.com/SonarSource/sonar-dotnet/pull/8222/files#r1365174847).

Copy link
Contributor

Choose a reason for hiding this comment

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

This line was introduced as a fix to #4620, because it was fixing annoying FP in the rule.

@sonarcloud
Copy link

sonarcloud bot commented Oct 25, 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 Oct 25, 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

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM!

@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource merged commit 9ff001d into master Oct 26, 2023
28 checks passed
@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource deleted the Martin/CS12_S3254 branch October 26, 2023 12:44
@martin-strecker-sonarsource
Copy link
Contributor Author

Peach validation:

New issues: 1215 all TPs

The distribution of new issues is about:

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.

Fix S3254 FN: primary constructors
3 participants