Skip to content

Commit

Permalink
Bugfix for object id usage in Permissions properties #4 #18
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanMaron committed Sep 24, 2021
1 parent 367e22e commit f060287
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions Design/Rule0003DoNotUseObjectIDsInVariablesOrProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public class Rule0003DoNotUseObjectIDsInVariablesOrProperties : DiagnosticAnalyz

public override void Initialize(AnalysisContext context)
{
context.RegisterSyntaxNodeAction(new Action<SyntaxNodeAnalysisContext>(this.CheckForObjectIDsInVariablesOrProperties), SyntaxKind.ObjectReference);
context.RegisterSyntaxNodeAction(new Action<SyntaxNodeAnalysisContext>(this.CheckForObjectIDsInVariablesOrProperties), new SyntaxKind[] {
SyntaxKind.ObjectReference,
SyntaxKind.PermissionValue
});

}
private void CheckForObjectIDsInVariablesOrProperties(SyntaxNodeAnalysisContext ctx)
Expand All @@ -30,7 +33,28 @@ private void CheckForObjectIDsInVariablesOrProperties(SyntaxNodeAnalysisContext
if (ctx.ContainingSymbol.Kind == SymbolKind.Property)
{
IPropertySymbol property = (IPropertySymbol)ctx.ContainingSymbol;
if (ctx.Node.ToString().Trim('"') != property.ValueText)

if (ctx.Node.Kind == SyntaxKind.PermissionValue)
{
var nodes = ctx.Node.ChildNodesAndTokens().GetEnumerator();

while (nodes.MoveNext())
{
if (nodes.Current.IsNode)
{
var subnodes = nodes.Current.ChildNodesAndTokens().GetEnumerator();

while (subnodes.MoveNext())
{
if (subnodes.Current.Kind == SyntaxKind.ObjectId)
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0003DoNotUseObjectIDsInVariablesOrProperties, nodes.Current.GetLocation(), new object[] { "", "the object name" }));
};
}

};
}

if (ctx.Node.ToString().Trim('"') != property.ValueText && property.PropertyKind != PropertyKind.Permissions)
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0003DoNotUseObjectIDsInVariablesOrProperties, ctx.Node.GetLocation(), new object[] { ctx.Node.ToString().Trim('"'), property.ValueText }));
}

Expand Down
2 changes: 1 addition & 1 deletion LinterCopAnalyzers.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<value>Do not use an Object ID for properties or variables declaration.</value>
</data>
<data name="Rule0003DoNotUseObjectIDsInVariablesOrPropertiesFormat" xml:space="preserve">
<value>Do not use an Object ID for properties or variables declaration. Use "{1}" instead.</value>
<value>Do not use an Object ID for properties or variables declaration. Use {1} instead.</value>
</data>
<data name="Rule0003DoNotUseObjectIDsInVariablesOrPropertiesTitle" xml:space="preserve">
<value>Do not use an Object ID for properties or variables declaration.</value>
Expand Down

0 comments on commit f060287

Please sign in to comment.