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

Update S927: C#: parameter names should match base declaration and other partial definitions #534

Merged
merged 2 commits into from
Jul 6, 2017

Conversation

valhristov
Copy link
Contributor

Fix #516

Copy link
Contributor

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

It seems like you are not covering interfaces definitions.

Copy link
Contributor

@michalb-sonar michalb-sonar left a comment

Choose a reason for hiding this comment

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

Some comments to consider, but LGTM (assuming you address Amaury's comment).

"issues": [
{
"id": "S927",
"message": "Rename parameter 'pipelineItem' to 'syncDelegate'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

While we're at the rule - perhaps tweak the message to give some context:
"Rename parameter '{0}' to '{1}' to match the inhertited parameter name."
(or something similar)
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
else
{
// do nothing
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 need that empty else? I know this is there intentionally to make point, but do we need that?

Perhaps rewrite to somethig like that - WDYT?

var parameters = methodSymbol?.PartialDefinitionPart?.Parameters ?? methodSymbol?.OverriddenMethod?.Parameters;
VerifyParameters(c, methodSyntax, expectedParameters: parameters);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion, but with the message argument I cannot do it nicely... See the updated code.

private static void VerifyParameters(SyntaxNodeAnalysisContext context,
MethodDeclarationSyntax methodSyntax, IList<IParameterSymbol> expectedParameters)
{
var implementationParameters = methodSyntax.ParameterList.Parameters;
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 know the collections are always the same length?
[Optional] you could try using Zip the way we did in MethodOverloadOptionalParameter.cs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, otherwise the methods will not be matched as overrides... I replaced the loop with Zip.

@Evangelink Evangelink changed the base branch from bump-version to master July 6, 2017 11:36
Copy link
Contributor

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

LGTM

@valhristov valhristov merged commit a362bb5 into master Jul 6, 2017
@valhristov valhristov deleted the s927-parameter-names branch July 6, 2017 12:19
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.

3 participants