Skip to content

Commit

Permalink
Merge pull request #51728 from huoyaoyuan/naming-extern
Browse files Browse the repository at this point in the history
Ignore extern methods in naming style
  • Loading branch information
sharwell authored Mar 20, 2021
2 parents 717c48d + dd0807b commit 9f2d705
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ protected override bool ShouldIgnore(ISymbol symbol)
return true;
}

if (symbol.IsExtern)
{
// Extern symbols are mainly P/Invoke and runtime invoke, probably requiring their name
// to match external definition exactly.
// Simply ignoring them.
return true;
}

return false;
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/Analyzers/CSharp/Tests/NamingStyles/NamingStylesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,5 +1382,17 @@ class C : I
int [|global::I.X|] => 0;
}", new TestParameters(options: s_options.PropertyNamesArePascalCase));
}

[Fact]
[WorkItem(51727, "https://github.com/dotnet/roslyn/issues/51727")]
public async Task TestExternAsync()
{
await TestMissingInRegularAndScriptAsync(
@"
class C
{
static extern void [|some_p_invoke()|];
}", new TestParameters(options: s_options.MethodNamesArePascalCase));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Diagnostics.Analyzers
SyntaxKind.TypeParameter)

Protected Overrides Function ShouldIgnore(symbol As ISymbol) As Boolean
If symbol.IsExtern Then
' Extern symbols are mainly P/Invoke And runtime invoke, probably requiring their name
' to match external definition exactly.
' Simply ignoring them.
Return True
End If

Return False
End Function
End Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,5 +497,14 @@ End Class",
options:=s_options.TypeParameterNamesStartWithT)
End Function

<Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)>
<WorkItem(51727, "https://github.com/dotnet/roslyn/issues/51727")>
Public Async Function TestExternMethod() As Task
Await TestMissingInRegularAndScriptAsync(
"Public Class C
Declare Sub [|some_p_invoke|] Lib ""some""()
End Class",
New TestParameters(options:=s_options.MethodNamesArePascalCase))
End Function
End Class
End Namespace

0 comments on commit 9f2d705

Please sign in to comment.