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 S1144: Nested type constructor accessibility is wrong in the rule message #9108

Merged
merged 7 commits into from
Apr 17, 2024

Conversation

CristianAmbrosini
Copy link
Contributor

Fixes #7774

Copy link
Contributor

@Tim-Pohlmann Tim-Pohlmann left a comment

Choose a reason for hiding this comment

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

Nicely done!

Comment on lines +149 to +161
public void UnusedPrivateMember_NonPrivateConstructorInPrivateClass(string accessModifier, string expectedMessage) =>
builder.AddSnippet($$$"""
public class Some
{
private class Foo // Noncompliant
{
{{{accessModifier}}} Foo() // Noncompliant {{{{{expectedMessage}}}}}
{
var a = 1;
}
}
}
""").Verify();
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation can be improved.

Suggested change
public void UnusedPrivateMember_NonPrivateConstructorInPrivateClass(string accessModifier, string expectedMessage) =>
builder.AddSnippet($$$"""
public class Some
{
private class Foo // Noncompliant
{
{{{accessModifier}}} Foo() // Noncompliant {{{{{expectedMessage}}}}}
{
var a = 1;
}
}
}
""").Verify();
public void UnusedPrivateMember_NonPrivateConstructorInPrivateClass(string accessModifier, string expectedMessage) =>
builder.AddSnippet($$$"""
public class Some
{
private class Foo // Noncompliant
{
{{{accessModifier}}} Foo() // Noncompliant {{{{{expectedMessage}}}}}
{
var a = 1;
}
}
}
""").Verify();

Copy link
Contributor Author

@CristianAmbrosini CristianAmbrosini Apr 17, 2024

Choose a reason for hiding this comment

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

All the test classes:

  • UnusedPrivateMemberTest.Constructors.cs
  • UnusedPrivateMemberTest.Fields.cs
  • UnusedPrivateMemberTest.Methods.cs
  • UnusedPrivateMemberTest.Properties.cs
  • UnusedPrivateMemberTest.Types.cs

are following this indentation, I don't like it either, but I like it even less refactoring all the above :D.
Given this context, are you ok with merging as is?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are three options:

  1. Leave as is
  2. Refactor everything
  3. Clean as you code

I'd go with 3, but if you think it's too much of a sore on the eye, sticking with 1 is also fine.

@Tim-Pohlmann
Copy link
Contributor

Ah... one of my comments did not make it from my brain to the keyboard:
Add a UT with an internal class as well.

@CristianAmbrosini CristianAmbrosini enabled auto-merge (squash) April 17, 2024 10:39
Comment on lines +413 to +419
internal class MyClass
{
protected MyClass() // Compliant
{
var a = 1;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Good test! I actually meant one with a private constructor (should be Noncompliant with a slightly different message).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The message will be the same (the default) as the first DataRow in UnusedPrivateMember_NonPrivateConstructorInPrivateClass: Remove the unused private constructor 'blabla'.
I'll add this as well anyway 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

You are absolutely right, of course. Still a good case to test!

@CristianAmbrosini CristianAmbrosini enabled auto-merge (squash) April 17, 2024 10:48
Copy link

sonarcloud bot commented Apr 17, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

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

See analysis details on SonarCloud

Copy link

sonarcloud bot commented Apr 17, 2024

@CristianAmbrosini CristianAmbrosini merged commit b7e3e9e into master Apr 17, 2024
29 checks passed
@CristianAmbrosini CristianAmbrosini deleted the cristian/S1144-ctor-accessibility-message branch April 17, 2024 11:04
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 S1144: Nested type constructor accessibility is wrong in the rule message
2 participants