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

ShimLayer: Add Sonar directory with our changes #9612

Merged
merged 11 commits into from
Aug 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static class ISymbolExtensions
{
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static string GetDeclarationTypeName(this SyntaxNode node) =>
SyntaxKindEx.LocalFunctionStatement => "local function",
SyntaxKind.MethodDeclaration => "method",
SyntaxKind.PropertyDeclaration => "property",
SyntaxKindEx.RecordClassDeclaration => "record",
SyntaxKindEx.RecordDeclaration => "record",
SyntaxKindEx.RecordStructDeclaration => "record struct",
SyntaxKind.StructDeclaration => "struct",
#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static ParameterListSyntax ParameterList(this TypeDeclarationSyntax typeD
{
SyntaxKind.ClassDeclaration => ((ClassDeclarationSyntaxWrapper)typeDeclaration).ParameterList,
SyntaxKind.StructDeclaration => ((StructDeclarationSyntaxWrapper)typeDeclaration).ParameterList,
SyntaxKindEx.RecordClassDeclaration or SyntaxKindEx.RecordStructDeclaration => ((RecordDeclarationSyntaxWrapper)typeDeclaration).ParameterList,
SyntaxKindEx.RecordDeclaration or SyntaxKindEx.RecordStructDeclaration => ((RecordDeclarationSyntaxWrapper)typeDeclaration).ParameterList,
_ => default,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ internal sealed class CSharpSyntaxKindFacade : ISyntaxKindFacade<SyntaxKind>
public SyntaxKind Attribute => SyntaxKind.Attribute;
public SyntaxKind[] CastExpressions => new[] {SyntaxKind.CastExpression };
public SyntaxKind ClassDeclaration => SyntaxKind.ClassDeclaration;
public SyntaxKind[] ClassAndRecordClassDeclarations => new[]
public SyntaxKind[] ClassAndRecordDeclarations => new[]
{
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
};
public SyntaxKind[] ClassAndModuleDeclarations => new[] { SyntaxKind.ClassDeclaration };
public SyntaxKind[] CommentTrivia => new[]
Expand Down Expand Up @@ -79,7 +79,7 @@ internal sealed class CSharpSyntaxKindFacade : ISyntaxKindFacade<SyntaxKind>
SyntaxKind.StructDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKind.EnumDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
};
public SyntaxKind VariableDeclarator => SyntaxKind.VariableDeclarator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public static bool IsNodeContainerTypeDeclaration(SyntaxNode node) =>
IsNodeStructOrClassOrRecordDeclaration(node) || node.IsKind(SyntaxKind.InterfaceDeclaration);

private static bool IsNodeStructOrClassOrRecordDeclaration(SyntaxNode node) =>
node.IsAnyKind(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKindEx.RecordClassDeclaration, SyntaxKindEx.RecordStructDeclaration);
node.IsAnyKind(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKindEx.RecordDeclaration, SyntaxKindEx.RecordStructDeclaration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private bool FindExecutableLines(SyntaxNode node)

case SyntaxKind.StructDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKindEx.RecordClassDeclaration:
case SyntaxKindEx.RecordDeclaration:
case SyntaxKindEx.RecordStructDeclaration:
return !HasExcludedCodeAttribute(node, ((BaseTypeDeclarationSyntax)node).AttributeLists, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override bool IsClass(SyntaxNode node)
switch (node.Kind())
{
case SyntaxKind.ClassDeclaration:
case SyntaxKindEx.RecordClassDeclaration:
case SyntaxKindEx.RecordDeclaration:
case SyntaxKind.StructDeclaration:
case SyntaxKindEx.RecordStructDeclaration:
case SyntaxKind.InterfaceDeclaration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public sealed class AsyncVoidMethod : SonarDiagnosticAnalyzer
{
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.InterfaceDeclaration
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) =>
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration);

private static bool IsTrackedType(INamedTypeSymbol namedType) =>
Expand Down Expand Up @@ -162,7 +162,7 @@ public TypeDependencyCollector(SemanticModel model, TypeDeclarationSyntax origin
// This override is needed because VisitRecordDeclaration is not available due to the Roslyn version.
public override void Visit(SyntaxNode node)
{
if (node.IsKind(SyntaxKindEx.RecordClassDeclaration))
if (node.IsKind(SyntaxKindEx.RecordDeclaration))
{
if (node == originalTypeDeclaration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) =>
}
},
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration);
SyntaxKindEx.RecordDeclaration);

private static string GetRootNamespace(ISymbol symbol)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected override void Initialize(SonarAnalysisContext context)
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration);

context.RegisterNodeAction(c =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
},
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration);

private static string SuggestGenericCollectionType(ITypeSymbol typeSymbol) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed class DeclareTypesInNamespaces : DeclareTypesInNamespacesBase<Synt
SyntaxKind.StructDeclaration,
SyntaxKind.EnumDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
};

Expand All @@ -44,7 +44,7 @@ protected override bool IsInnerTypeOrWithinNamespace(SyntaxNode declaration, Sem
SyntaxKind.StructDeclaration,
SyntaxKind.NamespaceDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKindEx.FileScopedNamespaceDeclaration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
}
},
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration);
SyntaxKindEx.RecordDeclaration);

private static bool HasNativeHandleFields(TypeDeclarationSyntax classDeclaration, SemanticModel semanticModel) =>
classDeclaration.Members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
}
},
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration);
SyntaxKindEx.RecordDeclaration);

private sealed class IssueReporter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
}
},
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration);
SyntaxKindEx.RecordDeclaration);

private sealed class IssueReporter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed class GenericInheritanceShouldNotBeRecursive : GenericInheritanceS
{
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
};

protected override SyntaxToken GetKeyword(TypeDeclarationSyntax declaration) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override void Initialize(SonarAnalysisContext context)
},
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.StructDeclaration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
}
},
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.StructDeclaration);

Expand Down Expand Up @@ -165,7 +165,7 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)

public override void Visit(SyntaxNode node)
{
if (node.IsAnyKind(SyntaxKindEx.RecordClassDeclaration, SyntaxKindEx.RecordStructDeclaration))
if (node.IsAnyKind(SyntaxKindEx.RecordDeclaration, SyntaxKindEx.RecordStructDeclaration))
{
if (visitedFirstLevel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override void Initialize(SonarAnalysisContext context)
SyntaxKind.UnsafeStatement);
context.RegisterNodeAction(
c => ReportIfUnsafe(c, ((BaseTypeDeclarationSyntax)c.Node).Modifiers),
SyntaxKind.ClassDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.StructDeclaration, SyntaxKindEx.RecordClassDeclaration, SyntaxKindEx.RecordStructDeclaration);
SyntaxKind.ClassDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.StructDeclaration, SyntaxKindEx.RecordDeclaration, SyntaxKindEx.RecordStructDeclaration);
context.RegisterNodeAction(
c => ReportIfUnsafe(c, ((BaseMethodDeclarationSyntax)c.Node).Modifiers),
SyntaxKind.MethodDeclaration, SyntaxKind.ConstructorDeclaration, SyntaxKind.DestructorDeclaration, SyntaxKind.OperatorDeclaration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed class UsingNonstandardCryptography : UsingNonstandardCryptographyB
{
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.StructDeclaration
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
}
},
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration);
SyntaxKindEx.RecordDeclaration);

private sealed class DisposableChecker
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
}
},
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.StructDeclaration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class MethodOverloadsShouldBeGrouped : MethodOverloadsShouldBeGrou
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class MethodsShouldNotHaveIdenticalImplementations : MethodsShould
protected override SyntaxKind[] SyntaxKinds => new[]
{
SyntaxKind.ClassDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.InterfaceDeclaration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) =>
}
}
},
SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKindEx.RecordClassDeclaration, SyntaxKindEx.RecordStructDeclaration);
SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKindEx.RecordDeclaration, SyntaxKindEx.RecordStructDeclaration);

private bool HasAllInvalidModifiers(FieldDeclarationSyntax fieldDeclaration) =>
fieldDeclaration.Modifiers.Count(m => InvalidModifiers.Contains(m.Kind())) == InvalidModifiers.Count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public sealed class NonDerivedPrivateClassesShouldBeSealed : SonarDiagnosticAnal
SyntaxKind.InterfaceDeclaration,
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration);

private static readonly ImmutableHashSet<SyntaxKind> PossiblyVirtualKinds = ImmutableHashSet.Create(
Expand All @@ -49,7 +49,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
context.RegisterTreeAction(c =>
{
var declarations = c.Tree.GetRoot().DescendantNodes(x => x.IsAnyKind(KindsToBeDescended))
.Where(x => x.IsAnyKind(SyntaxKind.ClassDeclaration, SyntaxKindEx.RecordClassDeclaration))
.Where(x => x.IsAnyKind(SyntaxKind.ClassDeclaration, SyntaxKindEx.RecordDeclaration))
.Select(x => (TypeDeclarationSyntax)x);

var model = new Lazy<SemanticModel>(() => c.Compilation.GetSemanticModel(c.Tree));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
},
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration);

private static IDictionary<IFieldSymbol, VariableDeclaratorSyntax> GetPrivateFields(SemanticModel model, TypeDeclarationSyntax typeDeclaration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed class PrivateStaticMethodUsedOnlyByNestedClass : SonarDiagnosticAn
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration);

private static bool HasCandidateSignature(IMethodSymbol method) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
},
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.StructDeclaration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class PublicMethodWithMultidimensionalArray : PublicMethodWithMult
SyntaxKind.ConstructorDeclaration,
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration);

protected override ILanguageFacade<SyntaxKind> Language => CSharpFacade.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class RedundancyInConstructorDestructorDeclaration : SonarDiagnost
[
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
SyntaxKind.InterfaceDeclaration,
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration);

private static void ReportRedundantBaseType(SonarSyntaxNodeReportingContext context, BaseTypeDeclarationSyntax typeDeclaration, KnownType redundantType, string message)
Expand Down
4 changes: 2 additions & 2 deletions analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ protected override void Initialize(SonarAnalysisContext context)
CheckTypeDeclarationForRedundantPartial,
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.StructDeclaration);

context.RegisterNodeAction(
CheckForUnnecessaryUnsafeBlocks,
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.StructDeclaration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override SyntaxNode GetAttributeName(AttributeSyntax attributeSyntax)
attributeSyntax.Name;

protected override bool IsClassOrRecordSyntax(SyntaxNode syntaxNode) =>
syntaxNode.IsAnyKind(SyntaxKind.ClassDeclaration, SyntaxKindEx.RecordClassDeclaration);
syntaxNode.IsAnyKind(SyntaxKind.ClassDeclaration, SyntaxKindEx.RecordDeclaration);

protected override SyntaxNode GetTypeOfOrGetTypeExpression(SyntaxNode expressionSyntax) =>
(expressionSyntax as TypeOfExpressionSyntax)?.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override void Initialize(SonarAnalysisContext context) =>
},
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
SyntaxKind.StructDeclaration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed class StaticFieldInitializerOrder : SonarDiagnosticAnalyzer
SyntaxKind.ClassDeclaration,
SyntaxKind.InterfaceDeclaration,
SyntaxKind.StructDeclaration,
SyntaxKindEx.RecordClassDeclaration,
SyntaxKindEx.RecordDeclaration,
SyntaxKindEx.RecordStructDeclaration,
};

Expand Down
Loading