-
Notifications
You must be signed in to change notification settings - Fork 509
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
Implement SA1315 #2015
Implement SA1315 #2015
Conversation
Current coverage is
|
I think this needs to be SA1315 (see #1925). |
|
||
## Rule description | ||
|
||
A violation of this rule occurs when the name of a parameter does not begin with a lower-case letter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a copy-paste error.
💭 It would be nice to have a few test cases that would cover multiple levels of inheritance. Like: public class TopLevelBaseClass
{
public void Method(int baseArg);
}
public class IntermediateBaseClass : TopLevelBaseClass
{
}
public class TestClass : IntermediateBaseClass
{
public void override Method(int arg);
} |
❓ How would the scenario above work when the |
💭 I think a test is when a sub class redefines a method declaration with the |
if (!symbol.IsOverride && !NamedTypeHelpers.IsImplementingAnInterfaceMember(symbol)) | ||
{ | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Is it possible that context.Symbol is null because the method declaration is incomplete? -> If so, the statement above needs a null check as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. It should work like it does with syntax node actions. I register for a method symbol and I should get one.
❓ The code fix currently can offer multiple rename options based on the original definitions found. Is this a good way address this? I would expect that the root declaration will determine the name and that there will be no alternatives. |
The following code can produce this: interface IInterface
{
void Method(string p1);
}
class BaseClass
{
public abstract void Method(string p2);
}
class Derived : BaseClass, IInterface
{
public override void Method(string p)
{
}
} The parameter void IInterface.Method(string p1)
{
this.Method(p1);
} In the case of multiple overloads in a chain of base classes, the analyzer and code fix should only consider the method which would be called using the |
What if there are multiple interfaces with parameter names that do not match? |
@pdelvo @sharwell Would you consider also submitting this code to the dotnet/roslyn-analyzers repo as the implementation of rule CA1725, ParameterNamesShouldMatchBaseDeclaration? This is issue dotnet/roslyn-analyzers#457. @srivatsn FYI |
Hi Vincent, We'd be delighted if you would contribute your work on this analyzer SA1315 to the roslyn-analyzers repo as rule CA1725. The roslyn-analyzers repo includes skeleton code for all the analyzers we haven't yet implemented. The skeleton code for the CA1725 analyzer is here, and the skeleton code for the fixer is here. If you search the roslyn-analyzers repo for "CA1725" you'll see that for both the analyzer and the fixer, there is a base class, and then there are derived classes for C# and VB versions. In your case, you have written a symbol analyzer, which works for both languages, so you would simply remove the C# and VB analyzers, declare the "core" analyzer to handle both C# and VB, and paste your implementation in there. I see that your fixer works at the syntax level, so you would paste your implementation into the C# version. You are welcome to contribute a VB fixer, but you certainly don't have to. At the moment, we are concentrating on analyzers and deferring work on fixers until we have a sufficient set of analyzers completed. Feel free to email me with any questions (email in my profile). Best regards, |
Do we still want this analyzer in stylecop analyzers? |
Good question, I have no real preference. |
I close this for now. @vweijsters maybe you can create a new PR with the changes you made |
Fixes #1949.