Merged
Conversation
- apply WTG1001 fix that removes 'private' keyword if the method is 'partial' and 'void' - keep 'private' keyword if a partial method is non-void or having 'out' keyword
yaakov-h
requested changes
Jul 8, 2024
| case SyntaxKind.ProtectedKeyword: | ||
| case SyntaxKind.PublicKeyword: | ||
| case SyntaxKind.PartialKeyword when (context.Node.IsKind(SyntaxKind.MethodDeclaration)): | ||
| case SyntaxKind.PartialKeyword when (DoesMethodHaveReturnValueOrOutKeyword(currentNode)): |
Member
There was a problem hiding this comment.
Suggested change
| case SyntaxKind.PartialKeyword when (DoesMethodHaveReturnValueOrOutKeyword(currentNode)): | |
| case SyntaxKind.PartialKeyword when (PartialMethodRequiresAccessibilityModifier(currentNode)): |
Contributor
Author
There was a problem hiding this comment.
I'll apply the name as suggested.
| } | ||
|
|
||
| var methodNode = (MethodDeclarationSyntax)node; | ||
| if (methodNode.ReturnType is PredefinedTypeSyntax predefinedTypeSyntax |
Member
There was a problem hiding this comment.
Is there a Kind check we can perform on methodNode.ReturnType before turning to runtime type casts?
Contributor
Author
There was a problem hiding this comment.
I suppose the same as Kind check for var methodNode = (MethodDeclarationSyntax)node;, e.g.
if (methodNode.ReturnType.IsKind(SyntaxKind.PredefinedType))
{
var returnType = (PredefinedTypeSyntax)methodNode.ReturnType;
if (!returnType.Keyword.IsKind(SyntaxKind.VoidKeyword))
{
return true;
}
}| return true; | ||
| } | ||
|
|
||
| if (methodNode.ParameterList?.Parameters.Any(c => c.Modifiers.Any(SyntaxKind.OutKeyword)) == true) |
Member
There was a problem hiding this comment.
Suggested change
| if (methodNode.ParameterList?.Parameters.Any(c => c.Modifiers.Any(SyntaxKind.OutKeyword)) == true) | |
| if (methodNode.ParameterList?.Parameters.Any(static c => c.Modifiers.Any(SyntaxKind.OutKeyword)) == true) |
src/WTG.Analyzers.Test/TestData/VisibilityAnalyzer/Partial/Diagnostics.xml
Outdated
Show resolved
Hide resolved
| { | ||
| private partial int Bar() { return default; } | ||
| public partial void FooBar() { } | ||
| private partial int FooBarBaz(out int value) { value = default; return default; } |
Member
There was a problem hiding this comment.
Another option for methods that we don't care about:
Suggested change
| private partial int FooBarBaz(out int value) { value = default; return default; } | |
| private partial int FooBarBaz(out int value) => throw null; |
yaakov-h
approved these changes
Jul 17, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #224
Tracked by WI00764889
A method with default access modifier, partial, return value
e.g. private partial int Bar(); // no error as it returns value
A partial method with non-default access modifier, void
e.g. public partial void Bar(); // no error as it returns value
A partial method with default access modifier, void
e.g. private partial void Bar(); // trigger WTG1001 and remove 'private' when code-fix run
A partial method with default access modifier, void, out value
e.g. private partial void Bar(out int value); // no error as it 'out' a value
A partial method with default access modifier, return value, out value
e.g. private partial int Bar(out int value); // no error as it returns and 'out' a value