Skip to content

Commit

Permalink
- apply review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mj-wtg committed Jul 10, 2024
1 parent e0bd5dd commit 273aa78
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<diagnostics severity="Hidden">
<languageVersion>9.0</languageVersion>
<suppressId justtification="To ignore when only one method in one class have the code fix removing 'private' applied.">CS8799</suppressId>
<suppressId>CS8799</suppressId>
<diagnostic id="WTG1001" message="Our convention is to omit the 'private' modifier where it is already the default.">
<location>Test0.cs: (9,3-10)</location>
</diagnostic>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ partial class Foo
{
private partial int Bar() { return default; }
public partial void FooBar() { }
private partial int FooBarBaz(out int value) { value = default; return default; }
private partial int FooBarBaz(out int value) => throw null;

partial void Qux() { }
private partial void Quux(out int value) { value = default; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ partial class Foo
{
private partial int Bar() { return default; }
public partial void FooBar() { }
private partial int FooBarBaz(out int value) { value = default; return default; }
private partial int FooBarBaz(out int value) => throw null;

private partial void Qux() { }
private partial void Quux(out int value) { value = default; }
Expand Down
15 changes: 9 additions & 6 deletions src/WTG.Analyzers/Analyzers/Visibility/VisibilityAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void Analyze(SyntaxNodeAnalysisContext context, FileDetailCache cache)

case SyntaxKind.ProtectedKeyword:
case SyntaxKind.PublicKeyword:
case SyntaxKind.PartialKeyword when (DoesMethodHaveReturnValueOrOutKeyword(currentNode)):
case SyntaxKind.PartialKeyword when (PartialMethodRequiresAccessibilityModifier(currentNode)):
return;
case SyntaxKind.InternalKeyword:
if (IsTopLevel(currentNode))
Expand All @@ -67,21 +67,24 @@ static void Analyze(SyntaxNodeAnalysisContext context, FileDetailCache cache)
}
}

static bool DoesMethodHaveReturnValueOrOutKeyword(SyntaxNode node)
static bool PartialMethodRequiresAccessibilityModifier(SyntaxNode node)
{
if (!node.IsKind(SyntaxKind.MethodDeclaration))
{
return false;
}

var methodNode = (MethodDeclarationSyntax)node;
if (methodNode.ReturnType is PredefinedTypeSyntax predefinedTypeSyntax
&& !predefinedTypeSyntax.Keyword.IsKind(SyntaxKind.VoidKeyword))
if (methodNode.ReturnType.IsKind(SyntaxKind.PredefinedType))
{
return true;
var returnType = (PredefinedTypeSyntax)methodNode.ReturnType;
if (!returnType.Keyword.IsKind(SyntaxKind.VoidKeyword))
{
return true;
}
}

if (methodNode.ParameterList?.Parameters.Any(c => c.Modifiers.Any(SyntaxKind.OutKeyword)) == true)
if (methodNode.ParameterList?.Parameters.Any(static p => p.Modifiers.Any(SyntaxKind.OutKeyword)) == true)
{
return true;
}
Expand Down

0 comments on commit 273aa78

Please sign in to comment.