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

Ignore extern methods in naming style #51728

Merged
merged 2 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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