Skip to content

Commit

Permalink
Don't run naming rules on symbols with no name
Browse files Browse the repository at this point in the history
Fixes #19106
  • Loading branch information
David Poeschl committed May 3, 2017
1 parent 00a4e6b commit abfca04
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,18 @@ class D : C
internal override void [|m|]() { }
}", new TestParameters(options: MethodNamesArePascalCase));
}

[Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)]
[WorkItem(19106, "https://github.com/dotnet/roslyn/issues/19106")]
public async Task TestMissingOnSymbolsWithNoName()
{
await TestMissingInRegularAndScriptAsync(
@"
namespace Microsoft.CodeAnalysis.Host
{
internal interface
[|}|]
", new TestParameters(options: InterfaceNamesStartWithI));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ public partial class NamingStylesTests : AbstractCSharpDiagnosticProviderBasedUs
private IDictionary<OptionKey, object> ParameterNamesAreCamelCase =>
Options(new OptionKey(SimplificationOptions.NamingPreferences, LanguageNames.CSharp), ParameterNamesAreCamelCaseOption());

private IDictionary<OptionKey, object> PropertyNamesArePascalCase =>
private IDictionary<OptionKey, object> PropertyNamesArePascalCase =>
Options(new OptionKey(SimplificationOptions.NamingPreferences, LanguageNames.CSharp), PropertyNamesArePascalCaseOption());

private IDictionary<OptionKey, object> InterfaceNamesStartWithI =>
Options(new OptionKey(SimplificationOptions.NamingPreferences, LanguageNames.CSharp), InterfacesNamesStartWithIOption());

private IDictionary<OptionKey, object> Options(OptionKey option, object value)
{
var options = new Dictionary<OptionKey, object>
Expand Down Expand Up @@ -117,14 +120,14 @@ private NamingStylePreferences ParameterNamesAreCamelCaseOption()
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
};
var info = new NamingStylePreferences(

var info = new NamingStylePreferences(
ImmutableArray.Create(symbolSpecification),
ImmutableArray.Create(namingStyle),
ImmutableArray.Create(namingRule));

return info;
}
}

private NamingStylePreferences PropertyNamesArePascalCaseOption()
{
Expand Down Expand Up @@ -157,5 +160,37 @@ private NamingStylePreferences PropertyNamesArePascalCaseOption()

return info;
}

private NamingStylePreferences InterfacesNamesStartWithIOption()
{
var symbolSpecification = new SymbolSpecification(
null,
"Name",
ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(TypeKind.Interface)),
ImmutableArray<Accessibility>.Empty,
ImmutableArray<SymbolSpecification.ModifierKind>.Empty);

var namingStyle = new NamingStyle(
Guid.NewGuid(),
capitalizationScheme: Capitalization.PascalCase,
name: "Name",
prefix: "I",
suffix: "",
wordSeparator: "");

var namingRule = new SerializableNamingRule()
{
SymbolSpecificationID = symbolSpecification.ID,
NamingStyleID = namingStyle.ID,
EnforcementLevel = DiagnosticSeverity.Error
};

var info = new NamingStylePreferences(
ImmutableArray.Create(symbolSpecification),
ImmutableArray.Create(namingStyle),
ImmutableArray.Create(namingRule));

return info;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ private void SymbolAction(
SymbolAnalysisContext context,
ConcurrentDictionary<Guid, ConcurrentDictionary<string, string>> idToCachedResult)
{
if (string.IsNullOrEmpty(context.Symbol.Name))
{
return;
}

var namingPreferences = context.GetNamingStylePreferencesAsync().GetAwaiter().GetResult();
if (namingPreferences == null)
{
Expand Down

0 comments on commit abfca04

Please sign in to comment.