Skip to content

Commit

Permalink
Remove vb reference from SonarAnalyzer.CFG (#9027)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource authored Apr 10, 2024
1 parent b9e9401 commit d22fcfa
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 169 deletions.
1 change: 0 additions & 1 deletion analyzers/src/RuleDescriptorGenerator/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,6 @@
"type": "Project",
"dependencies": {
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
"Microsoft.Composition": "[1.0.27, )",
"System.Collections.Immutable": "[1.1.37, )"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,25 @@
using System.Diagnostics.CodeAnalysis;
using static System.Linq.Expressions.Expression;
using CS = Microsoft.CodeAnalysis.CSharp;
using VB = Microsoft.CodeAnalysis.VisualBasic;

namespace SonarAnalyzer.ShimLayer.AnalysisContext;

public readonly struct SymbolStartAnalysisContextWrapper
{
private const string VBSyntaxKind = "Microsoft.CodeAnalysis.VisualBasic.SyntaxKind";

private static readonly Func<object, CancellationToken> CancellationTokenAccessor;
private static readonly Func<object, Compilation> CompilationAccessor;
private static readonly Func<object, AnalyzerOptions> OptionsAccessor;
private static readonly Func<object, ISymbol> SymbolAccessor;

private static readonly Action<object, Action<CodeBlockAnalysisContext>> RegisterCodeBlockActionMethod;
private static readonly Action<object, Action<CodeBlockStartAnalysisContext<CS.SyntaxKind>>> RegisterCodeBlockStartActionCS;
private static readonly Action<object, Action<CodeBlockStartAnalysisContext<VB.SyntaxKind>>> RegisterCodeBlockStartActionVB;
private static readonly Action<object, Action<OperationAnalysisContext>, ImmutableArray<OperationKind>> RegisterOperationActionMethod;
private static readonly Action<object, Action<OperationBlockAnalysisContext>> RegisterOperationBlockActionMethod;
private static readonly Action<object, Action<OperationBlockStartAnalysisContext>> RegisterOperationBlockStartActionMethod;
private static readonly Action<object, Action<SymbolAnalysisContext>> RegisterSymbolEndActionMethod;
private static readonly Action<object, Action<SyntaxNodeAnalysisContext>, ImmutableArray<CS.SyntaxKind>> RegisterSyntaxNodeActionCS;
private static readonly Action<object, Action<SyntaxNodeAnalysisContext>, ImmutableArray<VB.SyntaxKind>> RegisterSyntaxNodeActionVB;

public CancellationToken CancellationToken => CancellationTokenAccessor(RoslynSymbolStartAnalysisContext);
public Compilation Compilation => CompilationAccessor(RoslynSymbolStartAnalysisContext);
Expand All @@ -61,17 +60,13 @@ static SymbolStartAnalysisContextWrapper()
RegisterCodeBlockActionMethod = CreateRegistrationMethod<CodeBlockAnalysisContext>(nameof(RegisterCodeBlockAction));
RegisterCodeBlockStartActionCS =
CreateRegistrationMethod<CodeBlockStartAnalysisContext<CS.SyntaxKind>>(nameof(RegisterCodeBlockStartAction), typeof(CS.SyntaxKind));
RegisterCodeBlockStartActionVB =
CreateRegistrationMethod<CodeBlockStartAnalysisContext<VB.SyntaxKind>>(nameof(RegisterCodeBlockStartAction), typeof(VB.SyntaxKind));
RegisterOperationActionMethod =
CreateRegistrationMethodWithAdditionalParameter<OperationAnalysisContext, ImmutableArray<OperationKind>>(nameof(RegisterOperationAction));
RegisterOperationBlockActionMethod = CreateRegistrationMethod<OperationBlockAnalysisContext>(nameof(RegisterOperationBlockAction));
RegisterOperationBlockStartActionMethod = CreateRegistrationMethod<OperationBlockStartAnalysisContext>(nameof(RegisterOperationBlockStartAction));
RegisterSymbolEndActionMethod = CreateRegistrationMethod<SymbolAnalysisContext>(nameof(RegisterSymbolEndAction));
RegisterSyntaxNodeActionCS = CreateRegistrationMethodWithAdditionalParameter<SyntaxNodeAnalysisContext, ImmutableArray<CS.SyntaxKind>>(
nameof(RegisterSyntaxNodeAction), typeof(CS.SyntaxKind));
RegisterSyntaxNodeActionVB = CreateRegistrationMethodWithAdditionalParameter<SyntaxNodeAnalysisContext, ImmutableArray<VB.SyntaxKind>>(
nameof(RegisterSyntaxNodeAction), typeof(VB.SyntaxKind));

// receiverParameter => ((symbolStartAnalysisContextType)receiverParameter)."propertyName"
Func<object, TProperty> CreatePropertyAccessor<TProperty>(string propertyName)
Expand Down Expand Up @@ -135,10 +130,12 @@ public void RegisterCodeBlockStartAction<TLanguageKindEnum>(Action<CodeBlockStar
var cast = (Action<CodeBlockStartAnalysisContext<CS.SyntaxKind>>)action;
RegisterCodeBlockStartActionCS(RoslynSymbolStartAnalysisContext, cast);
}
else if (languageKindType == typeof(VB.SyntaxKind))
else if (languageKindType.FullName == VBSyntaxKind)
{
var cast = (Action<CodeBlockStartAnalysisContext<VB.SyntaxKind>>)action;
RegisterCodeBlockStartActionVB(RoslynSymbolStartAnalysisContext, cast);
// See https://github.com/SonarSource/sonar-dotnet/pull/9028 for how to implement this
// Attention: Do not add a package reference to "Microsoft.CodeAnalysis.VisualBasic.Workspaces".
// It creates hard to detect file not found errors in .NET SDK 3 and .NET SDK 5 and other scenarios
// we do not fully understand.
}
else
{
Expand All @@ -165,9 +162,9 @@ public void RegisterSyntaxNodeAction<TLanguageKindEnum>(Action<SyntaxNodeAnalysi
{
RegisterSyntaxNodeActionCS(RoslynSymbolStartAnalysisContext, action, syntaxKinds.Cast<CS.SyntaxKind>().ToImmutableArray());
}
else if (languageKindType == typeof(VB.SyntaxKind))
else if (languageKindType.FullName == VBSyntaxKind)
{
RegisterSyntaxNodeActionVB(RoslynSymbolStartAnalysisContext, action, syntaxKinds.Cast<VB.SyntaxKind>().ToImmutableArray());
// See RegisterCodeBlockStartAction for how to implement this
}
else
{
Expand Down
1 change: 0 additions & 1 deletion analyzers/src/SonarAnalyzer.CFG/SonarAnalyzer.CFG.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="1.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="1.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
18 changes: 0 additions & 18 deletions analyzers/src/SonarAnalyzer.CFG/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
"resolved": "3.3.1",
"contentHash": "eT+kgNCDdTRbQ5WF6BGx1HI3D5jYfHteza/koefhWC2vNZGxObA74XxwWfg40dy3uUv7dn3OGKLK5GUPLroVog=="
},
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": {
"type": "Direct",
"requested": "[1.3.2, )",
"resolved": "1.3.2",
"contentHash": "I5Z2WBgFsx0G22Na1uVFPDkT6Ob4XI+g91GPN8JWldYUMlmIBcUDBfGmfr8oQPdUipvThpaU1x1xZrnNwRR8JA==",
"dependencies": {
"Microsoft.CodeAnalysis.VisualBasic": "[1.3.2]",
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
}
},
"Microsoft.Composition": {
"type": "Direct",
"requested": "[1.0.27, )",
Expand Down Expand Up @@ -127,14 +117,6 @@
"Microsoft.CodeAnalysis.Common": "[1.3.2]"
}
},
"Microsoft.CodeAnalysis.VisualBasic": {
"type": "Transitive",
"resolved": "1.3.2",
"contentHash": "yllH3rSYEc0bV15CJ2T9Jtx+tSXO5/OVNb+xofuWrACn65Q5VqeFBKgcbgwpyVY/98ypPcGQIWNQL2A/L1seJg==",
"dependencies": {
"Microsoft.CodeAnalysis.Common": "1.3.2"
}
},
"Microsoft.CodeAnalysis.Workspaces.Common": {
"type": "Transitive",
"resolved": "1.3.2",
Expand Down
18 changes: 0 additions & 18 deletions analyzers/src/SonarAnalyzer.CSharp.Styling/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,6 @@
"Microsoft.CodeAnalysis.Common": "[4.9.2]"
}
},
"Microsoft.CodeAnalysis.VisualBasic": {
"type": "Transitive",
"resolved": "1.3.2",
"contentHash": "yllH3rSYEc0bV15CJ2T9Jtx+tSXO5/OVNb+xofuWrACn65Q5VqeFBKgcbgwpyVY/98ypPcGQIWNQL2A/L1seJg==",
"dependencies": {
"Microsoft.CodeAnalysis.Common": "1.3.2"
}
},
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": {
"type": "Transitive",
"resolved": "1.3.2",
"contentHash": "I5Z2WBgFsx0G22Na1uVFPDkT6Ob4XI+g91GPN8JWldYUMlmIBcUDBfGmfr8oQPdUipvThpaU1x1xZrnNwRR8JA==",
"dependencies": {
"Microsoft.CodeAnalysis.VisualBasic": "[1.3.2]",
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
}
},
"Microsoft.CodeAnalysis.Workspaces.Common": {
"type": "Transitive",
"resolved": "4.9.2",
Expand Down Expand Up @@ -271,7 +254,6 @@
"type": "Project",
"dependencies": {
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
"Microsoft.Composition": "[1.0.27, )",
"System.Collections.Immutable": "[1.1.37, )"
}
Expand Down
18 changes: 0 additions & 18 deletions analyzers/src/SonarAnalyzer.CSharp/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,6 @@
"Microsoft.CodeAnalysis.Common": "[1.3.2]"
}
},
"Microsoft.CodeAnalysis.VisualBasic": {
"type": "Transitive",
"resolved": "1.3.2",
"contentHash": "yllH3rSYEc0bV15CJ2T9Jtx+tSXO5/OVNb+xofuWrACn65Q5VqeFBKgcbgwpyVY/98ypPcGQIWNQL2A/L1seJg==",
"dependencies": {
"Microsoft.CodeAnalysis.Common": "1.3.2"
}
},
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": {
"type": "Transitive",
"resolved": "1.3.2",
"contentHash": "I5Z2WBgFsx0G22Na1uVFPDkT6Ob4XI+g91GPN8JWldYUMlmIBcUDBfGmfr8oQPdUipvThpaU1x1xZrnNwRR8JA==",
"dependencies": {
"Microsoft.CodeAnalysis.VisualBasic": "[1.3.2]",
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
}
},
"Microsoft.CodeAnalysis.Workspaces.Common": {
"type": "Transitive",
"resolved": "1.3.2",
Expand Down Expand Up @@ -944,7 +927,6 @@
"type": "Project",
"dependencies": {
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
"Microsoft.Composition": "[1.0.27, )",
"System.Collections.Immutable": "[1.1.37, )"
}
Expand Down
18 changes: 0 additions & 18 deletions analyzers/src/SonarAnalyzer.Common/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,6 @@
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
}
},
"Microsoft.CodeAnalysis.VisualBasic": {
"type": "Transitive",
"resolved": "1.3.2",
"contentHash": "yllH3rSYEc0bV15CJ2T9Jtx+tSXO5/OVNb+xofuWrACn65Q5VqeFBKgcbgwpyVY/98ypPcGQIWNQL2A/L1seJg==",
"dependencies": {
"Microsoft.CodeAnalysis.Common": "1.3.2"
}
},
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": {
"type": "Transitive",
"resolved": "1.3.2",
"contentHash": "I5Z2WBgFsx0G22Na1uVFPDkT6Ob4XI+g91GPN8JWldYUMlmIBcUDBfGmfr8oQPdUipvThpaU1x1xZrnNwRR8JA==",
"dependencies": {
"Microsoft.CodeAnalysis.VisualBasic": "[1.3.2]",
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
}
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
"resolved": "1.1.0",
Expand Down Expand Up @@ -942,7 +925,6 @@
"type": "Project",
"dependencies": {
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
"Microsoft.Composition": "[1.0.27, )",
"System.Collections.Immutable": "[1.1.37, )"
}
Expand Down
1 change: 0 additions & 1 deletion analyzers/src/SonarAnalyzer.VisualBasic/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,6 @@
"type": "Project",
"dependencies": {
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
"Microsoft.Composition": "[1.0.27, )",
"System.Collections.Immutable": "[1.1.37, )"
}
Expand Down
1 change: 0 additions & 1 deletion analyzers/tests/ITs.JsonParser.Test/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@
"type": "Project",
"dependencies": {
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
"Microsoft.Composition": "[1.0.27, )",
"System.Collections.Immutable": "[1.1.37, )"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@
"type": "Project",
"dependencies": {
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
"Microsoft.Composition": "[1.0.27, )",
"System.Collections.Immutable": "[1.1.37, )"
}
Expand Down
1 change: 0 additions & 1 deletion analyzers/tests/SonarAnalyzer.Net8.Test/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@
"type": "Project",
"dependencies": {
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
"Microsoft.Composition": "[1.0.27, )",
"System.Collections.Immutable": "[1.1.37, )"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
Imports System.Web.Mvc

<Route("[controller]")>
Public Class NoncompliantController ' Noncompliant {{Change the paths of the actions of this controller to be relative and adapt the controller route accordingly.}}
Public Class NoncompliantController ' FN Non-compliant {{Change the paths of the actions of this controller to be relative and adapt the controller route accordingly.}}
Inherits Controller
<Route("/Index1")> ' Secondary
<Route("/Index1")> ' FN Second-ary
Public Function Index1() As ActionResult
Return View()
End Function

<Route("/SubPath/Index2_1")> ' Secondary
<Route("/[controller]/Index2_2")> ' Secondary
<Route("/SubPath/Index2_1")> ' FN Second-ary
<Route("/[controller]/Index2_2")> ' FN Second-ary
Public Function Index2() As ActionResult
Return View()
End Function

<Route("/[action]")> ' Secondary
<Route("/[action]")> ' FN Second-ary
Public Function Index3() As ActionResult
Return View()
End Function

<Route("/SubPath/Index4_1")> ' Secondary
<Route("/[controller]/Index4_2")> ' Secondary
<Route("/SubPath/Index4_1")> ' FN Second-ary
<Route("/[controller]/Index4_2")> ' FN Second-ary
Public Function Index4() As ActionResult
Return View()
End Function
End Class

<RoutePrefix("[controller]")>
Public Class NoncompliantWithRoutePrefixController ' Noncompliant {{Change the paths of the actions of this controller to be relative and adapt the controller route accordingly.}}
Public Class NoncompliantWithRoutePrefixController ' FN Non-compliant {{Change the paths of the actions of this controller to be relative and adapt the controller route accordingly.}}
Inherits Controller
<Route("/Index1")> ' Secondary
<Route("/Index1")> ' FN Second-ary
Public Function Index1() As ActionResult
Return View()
End Function
End Class

<Route("[controller]")>
<Route("[controller]/[action]")>
Public Class NoncompliantMultiRouteController ' Noncompliant {{Change the paths of the actions of this controller to be relative and adapt the controller route accordingly.}}
Public Class NoncompliantMultiRouteController ' FN Non-compliant {{Change the paths of the actions of this controller to be relative and adapt the controller route accordingly.}}
Inherits Controller
<Route("/Index1")> ' Secondary
<Route("/Index1")> ' FN Second-ary
Public Function Index1() As ActionResult
Return View()
End Function

<Route("/SubPath/Index2_1")> ' Secondary
<Route("/[controller]/Index2_2")> ' Secondary
<Route("/SubPath/Index2_1")> ' FN Second-ary
<Route("/[controller]/Index2_2")> ' FN Second-ary
Public Function Index2() As ActionResult
Return View()
End Function

<Route("/[action]")> ' Secondary
<Route("/[action]")> ' FN Second-ary
Public Function Index3() As ActionResult
Return View()
End Function
Expand Down Expand Up @@ -81,20 +81,20 @@ Public Class CompliantController ' Compliant: at least one action has at least a
End Function
End Class

Public Class NoncompliantNoControllerRouteController ' Noncompliant {{Change the paths of the actions of this controller to be relative and add a controller route with the common prefix.}}
Public Class NoncompliantNoControllerRouteController ' FN Non-compliant {{Change the paths of the actions of this controller to be relative and add a controller route with the common prefix.}}
Inherits Controller
<Route("/Index1")> ' Secondary
<Route("/Index1")> ' FN Second-ary
Public Function Index1() As ActionResult
Return View()
End Function

<Route("/SubPath/Index2_1")> ' Secondary
<Route("/[controller]/Index2_2")> ' Secondary
<Route("/SubPath/Index2_1")> ' FN Second-ary
<Route("/[controller]/Index2_2")> ' FN Second-ary
Public Function Index2() As ActionResult
Return View()
End Function

<Route("/[action]")> ' Secondary
<Route("/[action]")> ' FN Second-ary
Public Function Index3() As ActionResult
Return View()
End Function
Expand Down
Loading

0 comments on commit d22fcfa

Please sign in to comment.