Skip to content

Commit d22fcfa

Browse files
Remove vb reference from SonarAnalyzer.CFG (#9027)
1 parent b9e9401 commit d22fcfa

File tree

17 files changed

+77
-169
lines changed

17 files changed

+77
-169
lines changed

analyzers/src/RuleDescriptorGenerator/packages.lock.json

-1
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,6 @@
929929
"type": "Project",
930930
"dependencies": {
931931
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
932-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
933932
"Microsoft.Composition": "[1.0.27, )",
934933
"System.Collections.Immutable": "[1.1.37, )"
935934
}

analyzers/src/SonarAnalyzer.CFG/ShimLayer/AnalysisContext/SymbolStartAnalysisContextWrapper.cs

+9-12
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,25 @@
2121
using System.Diagnostics.CodeAnalysis;
2222
using static System.Linq.Expressions.Expression;
2323
using CS = Microsoft.CodeAnalysis.CSharp;
24-
using VB = Microsoft.CodeAnalysis.VisualBasic;
2524

2625
namespace SonarAnalyzer.ShimLayer.AnalysisContext;
2726

2827
public readonly struct SymbolStartAnalysisContextWrapper
2928
{
29+
private const string VBSyntaxKind = "Microsoft.CodeAnalysis.VisualBasic.SyntaxKind";
30+
3031
private static readonly Func<object, CancellationToken> CancellationTokenAccessor;
3132
private static readonly Func<object, Compilation> CompilationAccessor;
3233
private static readonly Func<object, AnalyzerOptions> OptionsAccessor;
3334
private static readonly Func<object, ISymbol> SymbolAccessor;
3435

3536
private static readonly Action<object, Action<CodeBlockAnalysisContext>> RegisterCodeBlockActionMethod;
3637
private static readonly Action<object, Action<CodeBlockStartAnalysisContext<CS.SyntaxKind>>> RegisterCodeBlockStartActionCS;
37-
private static readonly Action<object, Action<CodeBlockStartAnalysisContext<VB.SyntaxKind>>> RegisterCodeBlockStartActionVB;
3838
private static readonly Action<object, Action<OperationAnalysisContext>, ImmutableArray<OperationKind>> RegisterOperationActionMethod;
3939
private static readonly Action<object, Action<OperationBlockAnalysisContext>> RegisterOperationBlockActionMethod;
4040
private static readonly Action<object, Action<OperationBlockStartAnalysisContext>> RegisterOperationBlockStartActionMethod;
4141
private static readonly Action<object, Action<SymbolAnalysisContext>> RegisterSymbolEndActionMethod;
4242
private static readonly Action<object, Action<SyntaxNodeAnalysisContext>, ImmutableArray<CS.SyntaxKind>> RegisterSyntaxNodeActionCS;
43-
private static readonly Action<object, Action<SyntaxNodeAnalysisContext>, ImmutableArray<VB.SyntaxKind>> RegisterSyntaxNodeActionVB;
4443

4544
public CancellationToken CancellationToken => CancellationTokenAccessor(RoslynSymbolStartAnalysisContext);
4645
public Compilation Compilation => CompilationAccessor(RoslynSymbolStartAnalysisContext);
@@ -61,17 +60,13 @@ static SymbolStartAnalysisContextWrapper()
6160
RegisterCodeBlockActionMethod = CreateRegistrationMethod<CodeBlockAnalysisContext>(nameof(RegisterCodeBlockAction));
6261
RegisterCodeBlockStartActionCS =
6362
CreateRegistrationMethod<CodeBlockStartAnalysisContext<CS.SyntaxKind>>(nameof(RegisterCodeBlockStartAction), typeof(CS.SyntaxKind));
64-
RegisterCodeBlockStartActionVB =
65-
CreateRegistrationMethod<CodeBlockStartAnalysisContext<VB.SyntaxKind>>(nameof(RegisterCodeBlockStartAction), typeof(VB.SyntaxKind));
6663
RegisterOperationActionMethod =
6764
CreateRegistrationMethodWithAdditionalParameter<OperationAnalysisContext, ImmutableArray<OperationKind>>(nameof(RegisterOperationAction));
6865
RegisterOperationBlockActionMethod = CreateRegistrationMethod<OperationBlockAnalysisContext>(nameof(RegisterOperationBlockAction));
6966
RegisterOperationBlockStartActionMethod = CreateRegistrationMethod<OperationBlockStartAnalysisContext>(nameof(RegisterOperationBlockStartAction));
7067
RegisterSymbolEndActionMethod = CreateRegistrationMethod<SymbolAnalysisContext>(nameof(RegisterSymbolEndAction));
7168
RegisterSyntaxNodeActionCS = CreateRegistrationMethodWithAdditionalParameter<SyntaxNodeAnalysisContext, ImmutableArray<CS.SyntaxKind>>(
7269
nameof(RegisterSyntaxNodeAction), typeof(CS.SyntaxKind));
73-
RegisterSyntaxNodeActionVB = CreateRegistrationMethodWithAdditionalParameter<SyntaxNodeAnalysisContext, ImmutableArray<VB.SyntaxKind>>(
74-
nameof(RegisterSyntaxNodeAction), typeof(VB.SyntaxKind));
7570

7671
// receiverParameter => ((symbolStartAnalysisContextType)receiverParameter)."propertyName"
7772
Func<object, TProperty> CreatePropertyAccessor<TProperty>(string propertyName)
@@ -135,10 +130,12 @@ public void RegisterCodeBlockStartAction<TLanguageKindEnum>(Action<CodeBlockStar
135130
var cast = (Action<CodeBlockStartAnalysisContext<CS.SyntaxKind>>)action;
136131
RegisterCodeBlockStartActionCS(RoslynSymbolStartAnalysisContext, cast);
137132
}
138-
else if (languageKindType == typeof(VB.SyntaxKind))
133+
else if (languageKindType.FullName == VBSyntaxKind)
139134
{
140-
var cast = (Action<CodeBlockStartAnalysisContext<VB.SyntaxKind>>)action;
141-
RegisterCodeBlockStartActionVB(RoslynSymbolStartAnalysisContext, cast);
135+
// See https://github.com/SonarSource/sonar-dotnet/pull/9028 for how to implement this
136+
// Attention: Do not add a package reference to "Microsoft.CodeAnalysis.VisualBasic.Workspaces".
137+
// It creates hard to detect file not found errors in .NET SDK 3 and .NET SDK 5 and other scenarios
138+
// we do not fully understand.
142139
}
143140
else
144141
{
@@ -165,9 +162,9 @@ public void RegisterSyntaxNodeAction<TLanguageKindEnum>(Action<SyntaxNodeAnalysi
165162
{
166163
RegisterSyntaxNodeActionCS(RoslynSymbolStartAnalysisContext, action, syntaxKinds.Cast<CS.SyntaxKind>().ToImmutableArray());
167164
}
168-
else if (languageKindType == typeof(VB.SyntaxKind))
165+
else if (languageKindType.FullName == VBSyntaxKind)
169166
{
170-
RegisterSyntaxNodeActionVB(RoslynSymbolStartAnalysisContext, action, syntaxKinds.Cast<VB.SyntaxKind>().ToImmutableArray());
167+
// See RegisterCodeBlockStartAction for how to implement this
171168
}
172169
else
173170
{

analyzers/src/SonarAnalyzer.CFG/SonarAnalyzer.CFG.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
</PropertyGroup>
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="1.3.2" />
12-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="1.3.2" />
1312
<PackageReference Include="Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers" Version="3.3.1">
1413
<PrivateAssets>all</PrivateAssets>
1514
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

analyzers/src/SonarAnalyzer.CFG/packages.lock.json

-18
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@
1818
"resolved": "3.3.1",
1919
"contentHash": "eT+kgNCDdTRbQ5WF6BGx1HI3D5jYfHteza/koefhWC2vNZGxObA74XxwWfg40dy3uUv7dn3OGKLK5GUPLroVog=="
2020
},
21-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": {
22-
"type": "Direct",
23-
"requested": "[1.3.2, )",
24-
"resolved": "1.3.2",
25-
"contentHash": "I5Z2WBgFsx0G22Na1uVFPDkT6Ob4XI+g91GPN8JWldYUMlmIBcUDBfGmfr8oQPdUipvThpaU1x1xZrnNwRR8JA==",
26-
"dependencies": {
27-
"Microsoft.CodeAnalysis.VisualBasic": "[1.3.2]",
28-
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
29-
}
30-
},
3121
"Microsoft.Composition": {
3222
"type": "Direct",
3323
"requested": "[1.0.27, )",
@@ -127,14 +117,6 @@
127117
"Microsoft.CodeAnalysis.Common": "[1.3.2]"
128118
}
129119
},
130-
"Microsoft.CodeAnalysis.VisualBasic": {
131-
"type": "Transitive",
132-
"resolved": "1.3.2",
133-
"contentHash": "yllH3rSYEc0bV15CJ2T9Jtx+tSXO5/OVNb+xofuWrACn65Q5VqeFBKgcbgwpyVY/98ypPcGQIWNQL2A/L1seJg==",
134-
"dependencies": {
135-
"Microsoft.CodeAnalysis.Common": "1.3.2"
136-
}
137-
},
138120
"Microsoft.CodeAnalysis.Workspaces.Common": {
139121
"type": "Transitive",
140122
"resolved": "1.3.2",

analyzers/src/SonarAnalyzer.CSharp.Styling/packages.lock.json

-18
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,6 @@
8585
"Microsoft.CodeAnalysis.Common": "[4.9.2]"
8686
}
8787
},
88-
"Microsoft.CodeAnalysis.VisualBasic": {
89-
"type": "Transitive",
90-
"resolved": "1.3.2",
91-
"contentHash": "yllH3rSYEc0bV15CJ2T9Jtx+tSXO5/OVNb+xofuWrACn65Q5VqeFBKgcbgwpyVY/98ypPcGQIWNQL2A/L1seJg==",
92-
"dependencies": {
93-
"Microsoft.CodeAnalysis.Common": "1.3.2"
94-
}
95-
},
96-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": {
97-
"type": "Transitive",
98-
"resolved": "1.3.2",
99-
"contentHash": "I5Z2WBgFsx0G22Na1uVFPDkT6Ob4XI+g91GPN8JWldYUMlmIBcUDBfGmfr8oQPdUipvThpaU1x1xZrnNwRR8JA==",
100-
"dependencies": {
101-
"Microsoft.CodeAnalysis.VisualBasic": "[1.3.2]",
102-
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
103-
}
104-
},
10588
"Microsoft.CodeAnalysis.Workspaces.Common": {
10689
"type": "Transitive",
10790
"resolved": "4.9.2",
@@ -271,7 +254,6 @@
271254
"type": "Project",
272255
"dependencies": {
273256
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
274-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
275257
"Microsoft.Composition": "[1.0.27, )",
276258
"System.Collections.Immutable": "[1.1.37, )"
277259
}

analyzers/src/SonarAnalyzer.CSharp/packages.lock.json

-18
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,6 @@
124124
"Microsoft.CodeAnalysis.Common": "[1.3.2]"
125125
}
126126
},
127-
"Microsoft.CodeAnalysis.VisualBasic": {
128-
"type": "Transitive",
129-
"resolved": "1.3.2",
130-
"contentHash": "yllH3rSYEc0bV15CJ2T9Jtx+tSXO5/OVNb+xofuWrACn65Q5VqeFBKgcbgwpyVY/98ypPcGQIWNQL2A/L1seJg==",
131-
"dependencies": {
132-
"Microsoft.CodeAnalysis.Common": "1.3.2"
133-
}
134-
},
135-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": {
136-
"type": "Transitive",
137-
"resolved": "1.3.2",
138-
"contentHash": "I5Z2WBgFsx0G22Na1uVFPDkT6Ob4XI+g91GPN8JWldYUMlmIBcUDBfGmfr8oQPdUipvThpaU1x1xZrnNwRR8JA==",
139-
"dependencies": {
140-
"Microsoft.CodeAnalysis.VisualBasic": "[1.3.2]",
141-
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
142-
}
143-
},
144127
"Microsoft.CodeAnalysis.Workspaces.Common": {
145128
"type": "Transitive",
146129
"resolved": "1.3.2",
@@ -944,7 +927,6 @@
944927
"type": "Project",
945928
"dependencies": {
946929
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
947-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
948930
"Microsoft.Composition": "[1.0.27, )",
949931
"System.Collections.Immutable": "[1.1.37, )"
950932
}

analyzers/src/SonarAnalyzer.Common/packages.lock.json

-18
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,6 @@
147147
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
148148
}
149149
},
150-
"Microsoft.CodeAnalysis.VisualBasic": {
151-
"type": "Transitive",
152-
"resolved": "1.3.2",
153-
"contentHash": "yllH3rSYEc0bV15CJ2T9Jtx+tSXO5/OVNb+xofuWrACn65Q5VqeFBKgcbgwpyVY/98ypPcGQIWNQL2A/L1seJg==",
154-
"dependencies": {
155-
"Microsoft.CodeAnalysis.Common": "1.3.2"
156-
}
157-
},
158-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": {
159-
"type": "Transitive",
160-
"resolved": "1.3.2",
161-
"contentHash": "I5Z2WBgFsx0G22Na1uVFPDkT6Ob4XI+g91GPN8JWldYUMlmIBcUDBfGmfr8oQPdUipvThpaU1x1xZrnNwRR8JA==",
162-
"dependencies": {
163-
"Microsoft.CodeAnalysis.VisualBasic": "[1.3.2]",
164-
"Microsoft.CodeAnalysis.Workspaces.Common": "[1.3.2]"
165-
}
166-
},
167150
"Microsoft.NETCore.Platforms": {
168151
"type": "Transitive",
169152
"resolved": "1.1.0",
@@ -942,7 +925,6 @@
942925
"type": "Project",
943926
"dependencies": {
944927
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
945-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
946928
"Microsoft.Composition": "[1.0.27, )",
947929
"System.Collections.Immutable": "[1.1.37, )"
948930
}

analyzers/src/SonarAnalyzer.VisualBasic/packages.lock.json

-1
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,6 @@
944944
"type": "Project",
945945
"dependencies": {
946946
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
947-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
948947
"Microsoft.Composition": "[1.0.27, )",
949948
"System.Collections.Immutable": "[1.1.37, )"
950949
}

analyzers/tests/ITs.JsonParser.Test/packages.lock.json

-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@
565565
"type": "Project",
566566
"dependencies": {
567567
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
568-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
569568
"Microsoft.Composition": "[1.0.27, )",
570569
"System.Collections.Immutable": "[1.1.37, )"
571570
}

analyzers/tests/SonarAnalyzer.CSharp.Styling.Test/packages.lock.json

-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@
547547
"type": "Project",
548548
"dependencies": {
549549
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
550-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
551550
"Microsoft.Composition": "[1.0.27, )",
552551
"System.Collections.Immutable": "[1.1.37, )"
553552
}

analyzers/tests/SonarAnalyzer.Net8.Test/packages.lock.json

-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@
547547
"type": "Project",
548548
"dependencies": {
549549
"Microsoft.CodeAnalysis.CSharp.Workspaces": "[1.3.2, )",
550-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces": "[1.3.2, )",
551550
"Microsoft.Composition": "[1.0.27, )",
552551
"System.Collections.Immutable": "[1.1.37, )"
553552
}

analyzers/tests/SonarAnalyzer.Test/TestCases/RouteTemplateShouldNotStartWithSlash.AspNet4x.vb

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
Imports System.Web.Mvc
22

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

11-
<Route("/SubPath/Index2_1")> ' Secondary
12-
<Route("/[controller]/Index2_2")> ' Secondary
11+
<Route("/SubPath/Index2_1")> ' FN Second-ary
12+
<Route("/[controller]/Index2_2")> ' FN Second-ary
1313
Public Function Index2() As ActionResult
1414
Return View()
1515
End Function
1616

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

22-
<Route("/SubPath/Index4_1")> ' Secondary
23-
<Route("/[controller]/Index4_2")> ' Secondary
22+
<Route("/SubPath/Index4_1")> ' FN Second-ary
23+
<Route("/[controller]/Index4_2")> ' FN Second-ary
2424
Public Function Index4() As ActionResult
2525
Return View()
2626
End Function
2727
End Class
2828

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

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

47-
<Route("/SubPath/Index2_1")> ' Secondary
48-
<Route("/[controller]/Index2_2")> ' Secondary
47+
<Route("/SubPath/Index2_1")> ' FN Second-ary
48+
<Route("/[controller]/Index2_2")> ' FN Second-ary
4949
Public Function Index2() As ActionResult
5050
Return View()
5151
End Function
5252

53-
<Route("/[action]")> ' Secondary
53+
<Route("/[action]")> ' FN Second-ary
5454
Public Function Index3() As ActionResult
5555
Return View()
5656
End Function
@@ -81,20 +81,20 @@ Public Class CompliantController ' Compliant: at least one action has at least a
8181
End Function
8282
End Class
8383

84-
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.}}
84+
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.}}
8585
Inherits Controller
86-
<Route("/Index1")> ' Secondary
86+
<Route("/Index1")> ' FN Second-ary
8787
Public Function Index1() As ActionResult
8888
Return View()
8989
End Function
9090

91-
<Route("/SubPath/Index2_1")> ' Secondary
92-
<Route("/[controller]/Index2_2")> ' Secondary
91+
<Route("/SubPath/Index2_1")> ' FN Second-ary
92+
<Route("/[controller]/Index2_2")> ' FN Second-ary
9393
Public Function Index2() As ActionResult
9494
Return View()
9595
End Function
9696

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

0 commit comments

Comments
 (0)