Skip to content

Commit

Permalink
LC0003 False positive on AccessByPermission #53
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanMaron committed Oct 11, 2021
1 parent 436a375 commit 5b2e7f4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Design/Rule0003DoNotUseObjectIDsInVariablesOrProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void CheckForObjectIDsInVariablesOrProperties(SyntaxNodeAnalysisContext
if (ctx.Node.Kind == SyntaxKind.PermissionValue)
{
var nodes = ctx.Node.ChildNodesAndTokens().GetEnumerator();

while (nodes.MoveNext())
{
if (nodes.Current.IsNode)
Expand All @@ -65,11 +65,14 @@ private void CheckForObjectIDsInVariablesOrProperties(SyntaxNodeAnalysisContext
};
}

if (ctx.Node.ToString().Trim('"').ToUpper() != property.ValueText.ToUpper() && property.PropertyKind != PropertyKind.Permissions && property.PropertyKind != PropertyKind.AccessByPermission)
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0003DoNotUseObjectIDsInVariablesOrProperties, ctx.Node.GetLocation(), new object[] { ctx.Node.ToString().Trim('"'), property.ValueText }));
if (property.PropertyKind != PropertyKind.Permissions && property.PropertyKind.ToString() != "AccessByPermission") //seems like there was a breaking change in some version of the compiler where internal ids moved. Using text to be save
{
if (ctx.Node.ToString().Trim('"').ToUpper() != property.ValueText.ToUpper())
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0003DoNotUseObjectIDsInVariablesOrProperties, ctx.Node.GetLocation(), new object[] { ctx.Node.ToString().Trim('"'), property.ValueText }));

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

if (ctx.ContainingSymbol.Kind == SymbolKind.Method)
Expand Down

0 comments on commit 5b2e7f4

Please sign in to comment.