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

chore: update codelyzer package #762

Merged
merged 4 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/CTA.FeatureDetection.Common/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
},
"Codelyzer.Analysis": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "B3Tnur23cEulOO1N85VLHqXXjGtj5KyRzPYpDUQb11JDKK/VfldFXGpXhLqTiLIT1D9s82JpBFku6YEWnfVhcQ==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "iynKNXyC15wF0u9ZUTr4cKAmdYa1470AaGtvACuULL2BRK3VMHpzE01a/UvKbulKSXq0cZYaEMX+GrOlMVJuDQ==",
"dependencies": {
"Codelyzer.Analysis.Build": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.CSharp": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.VisualBasic": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Build": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.CSharp": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.VisualBasic": "2.4.71-alpha-g6b1f22778c",
"CommandLineParser": "2.8.0",
"Microsoft.Build.Utilities.Core": "17.1.0",
"Microsoft.Extensions.Logging.Console": "6.0.0",
Expand All @@ -69,41 +69,41 @@
},
"Codelyzer.Analysis.Build": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "fY2OFgAOuqn36mzWsVkzgdfKN2k2MP9+DFb6RRQx8VBbAuhuIr59pFbIiuVmY5hrCLMM+RkyMZcYsOZjBrn8bg==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "+senXLbp84O5oiiT1hp/B+AzCDSo7/+C+1KkDQlNrMBANBseSpcoXVacYigGTGHbSK79V16ahIlvAjpE9e9RBA==",
"dependencies": {
"Buildalyzer": "4.1.4",
"Buildalyzer.Logger": "4.1.4",
"Buildalyzer.Workspaces": "4.1.4",
"Codelyzer.Analysis.Common": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c",
"Microsoft.Extensions.Logging": "6.0.0",
"NuGet.Packaging": "6.0.0"
}
},
"Codelyzer.Analysis.Common": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "MfoRWrPY8cxrBWbS5dvlEZIcyrdmhj3zom5cW9qlUsZDEfwOgE50+ki0g9b3lUL1eu5AwN36Jeqnf38B0OKcIw==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "4nEVXfTc/FFzxkEulKOSd2s/2uh4bcTVbCncPCp4BZpf5qKLLXeLwf4VBzS/PFo6T5Y2D3A1F9kRlub74dLSXQ==",
"dependencies": {
"Codelyzer.Analysis.Model": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c",
"Microsoft.Build": "17.0.0",
"Microsoft.VisualStudio.Setup.Configuration.Interop": "3.1.2196",
"Newtonsoft.Json": "13.0.1"
}
},
"Codelyzer.Analysis.CSharp": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "aREsAiwmuWFF9lZzCwcvJlgcKwGkxSE4l9yt/RCAN/4Nairby7hF4w1XG1smWSlznPi7d8ufuylMYfB734/flQ==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "Q5Fs/FoDo6tz14aWEMCENHEjgTKJojE2/Wd1jSbFmjV8a8q27q6sk2gqMT5FcTO86THzt+GFeKq8b7FF8w2MoQ==",
"dependencies": {
"Codelyzer.Analysis.Common": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Model": "2.4.67-alpha-g1343e12a71"
"Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c"
}
},
"Codelyzer.Analysis.Model": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "ZGjzoOEUDjlnThorQ7ZxZXR2lQbKmM98qW9Hn193e5cLHmE91PXE8xNNMSEc/vTuj1+VggLKbdaeJelSZkaiqA==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "Ma1ACdIXjWStzw7ImhowEsI4E9p2fNhiANgP8FU0uegQSZOaA4x/IaUU0Aij5s5mCTbNVPX6Z5j89g2+L9YftA==",
"dependencies": {
"Microsoft.CodeAnalysis": "4.1.0",
"Microsoft.CodeAnalysis.CSharp": "4.1.0",
Expand All @@ -114,11 +114,11 @@
},
"Codelyzer.Analysis.VisualBasic": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "LJxM0bMPw/ONxC2N+v3kV4bHpTmtPt2Tr/aCP8jM2FjAXnSWNMyI+9pWuF1bKXNY9s+G7fGOjADwthX0D55Zsw==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "Hxpzw8CXD+oKN47DnYqgoajIucyAIrEW8YOdwcJgT+RGyJ9biLentcSws/9yzVgoIQWV042ppIKp7PlgwRGrJA==",
"dependencies": {
"Codelyzer.Analysis.Common": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Model": "2.4.67-alpha-g1343e12a71"
"Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c"
}
},
"CommandLineParser": {
Expand Down Expand Up @@ -1711,8 +1711,8 @@
"cta.rules.config": {
"type": "Project",
"dependencies": {
"Codelyzer.Analysis": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Model": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c",
"Microsoft.Extensions.Logging": "6.0.0",
"Microsoft.Extensions.Logging.Abstractions": "6.0.0",
"Microsoft.Extensions.Logging.Console": "6.0.0",
Expand Down
7 changes: 4 additions & 3 deletions src/CTA.Rules.Analysis/VisualBasicRulesAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,10 @@ private void AddNamedActions(FileActions fileAction, VisualBasicNodeToken token,
AccessorBlockActionFunc = c.AccessorBlockActionFunc
}));

if (fileAction.VbTypeBlockActions.Any() || fileAction.VbMethodBlockActions.Any()
|| fileAction.VbInterfaceBlockActions.Any() ||
fileAction.VbAccessorBlockActions.Any())
if (fileAction.VbTypeBlockActions.Any() ||
fileAction.VbMethodBlockActions.Any() ||
fileAction.VbInterfaceBlockActions.Any() ||
fileAction.VbAccessorBlockActions.Any())
{
var nodeToken = token.Clone();
nodeToken.TextSpan = textSpan;
Expand Down
4 changes: 2 additions & 2 deletions src/CTA.Rules.Config/CTA.Rules.Config.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Codelyzer.Analysis" Version="2.4.67-alpha-g1343e12a71" />
<PackageReference Include="Codelyzer.Analysis.Model" Version="2.4.67-alpha-g1343e12a71" />
<PackageReference Include="Codelyzer.Analysis" Version="2.4.71-alpha-g6b1f22778c" />
<PackageReference Include="Codelyzer.Analysis.Model" Version="2.4.71-alpha-g6b1f22778c" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
Expand Down
46 changes: 23 additions & 23 deletions src/CTA.Rules.Models/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
},
"Codelyzer.Analysis": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "B3Tnur23cEulOO1N85VLHqXXjGtj5KyRzPYpDUQb11JDKK/VfldFXGpXhLqTiLIT1D9s82JpBFku6YEWnfVhcQ==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "iynKNXyC15wF0u9ZUTr4cKAmdYa1470AaGtvACuULL2BRK3VMHpzE01a/UvKbulKSXq0cZYaEMX+GrOlMVJuDQ==",
"dependencies": {
"Codelyzer.Analysis.Build": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.CSharp": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.VisualBasic": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Build": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.CSharp": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.VisualBasic": "2.4.71-alpha-g6b1f22778c",
"CommandLineParser": "2.8.0",
"Microsoft.Build.Utilities.Core": "17.1.0",
"Microsoft.Extensions.Logging.Console": "6.0.0",
Expand All @@ -75,41 +75,41 @@
},
"Codelyzer.Analysis.Build": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "fY2OFgAOuqn36mzWsVkzgdfKN2k2MP9+DFb6RRQx8VBbAuhuIr59pFbIiuVmY5hrCLMM+RkyMZcYsOZjBrn8bg==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "+senXLbp84O5oiiT1hp/B+AzCDSo7/+C+1KkDQlNrMBANBseSpcoXVacYigGTGHbSK79V16ahIlvAjpE9e9RBA==",
"dependencies": {
"Buildalyzer": "4.1.4",
"Buildalyzer.Logger": "4.1.4",
"Buildalyzer.Workspaces": "4.1.4",
"Codelyzer.Analysis.Common": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c",
"Microsoft.Extensions.Logging": "6.0.0",
"NuGet.Packaging": "6.0.0"
}
},
"Codelyzer.Analysis.Common": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "MfoRWrPY8cxrBWbS5dvlEZIcyrdmhj3zom5cW9qlUsZDEfwOgE50+ki0g9b3lUL1eu5AwN36Jeqnf38B0OKcIw==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "4nEVXfTc/FFzxkEulKOSd2s/2uh4bcTVbCncPCp4BZpf5qKLLXeLwf4VBzS/PFo6T5Y2D3A1F9kRlub74dLSXQ==",
"dependencies": {
"Codelyzer.Analysis.Model": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c",
"Microsoft.Build": "17.0.0",
"Microsoft.VisualStudio.Setup.Configuration.Interop": "3.1.2196",
"Newtonsoft.Json": "13.0.1"
}
},
"Codelyzer.Analysis.CSharp": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "aREsAiwmuWFF9lZzCwcvJlgcKwGkxSE4l9yt/RCAN/4Nairby7hF4w1XG1smWSlznPi7d8ufuylMYfB734/flQ==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "Q5Fs/FoDo6tz14aWEMCENHEjgTKJojE2/Wd1jSbFmjV8a8q27q6sk2gqMT5FcTO86THzt+GFeKq8b7FF8w2MoQ==",
"dependencies": {
"Codelyzer.Analysis.Common": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Model": "2.4.67-alpha-g1343e12a71"
"Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c"
}
},
"Codelyzer.Analysis.Model": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "ZGjzoOEUDjlnThorQ7ZxZXR2lQbKmM98qW9Hn193e5cLHmE91PXE8xNNMSEc/vTuj1+VggLKbdaeJelSZkaiqA==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "Ma1ACdIXjWStzw7ImhowEsI4E9p2fNhiANgP8FU0uegQSZOaA4x/IaUU0Aij5s5mCTbNVPX6Z5j89g2+L9YftA==",
"dependencies": {
"Microsoft.CodeAnalysis": "4.1.0",
"Microsoft.CodeAnalysis.CSharp": "4.1.0",
Expand All @@ -120,11 +120,11 @@
},
"Codelyzer.Analysis.VisualBasic": {
"type": "Transitive",
"resolved": "2.4.67-alpha-g1343e12a71",
"contentHash": "LJxM0bMPw/ONxC2N+v3kV4bHpTmtPt2Tr/aCP8jM2FjAXnSWNMyI+9pWuF1bKXNY9s+G7fGOjADwthX0D55Zsw==",
"resolved": "2.4.71-alpha-g6b1f22778c",
"contentHash": "Hxpzw8CXD+oKN47DnYqgoajIucyAIrEW8YOdwcJgT+RGyJ9biLentcSws/9yzVgoIQWV042ppIKp7PlgwRGrJA==",
"dependencies": {
"Codelyzer.Analysis.Common": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Model": "2.4.67-alpha-g1343e12a71"
"Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c"
}
},
"CommandLineParser": {
Expand Down Expand Up @@ -1717,8 +1717,8 @@
"cta.rules.config": {
"type": "Project",
"dependencies": {
"Codelyzer.Analysis": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis.Model": "2.4.67-alpha-g1343e12a71",
"Codelyzer.Analysis": "2.4.71-alpha-g6b1f22778c",
"Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c",
"Microsoft.Extensions.Logging": "6.0.0",
"Microsoft.Extensions.Logging.Abstractions": "6.0.0",
"Microsoft.Extensions.Logging.Console": "6.0.0",
Expand Down
24 changes: 20 additions & 4 deletions src/CTA.Rules.Update/VisualBasicActionsRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,32 @@ public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax no

public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
{
var symbol = (IMethodSymbol)SemanticHelper.GetSemanticSymbol(node, _semanticModel, _preportSemanticModel);
var newNode = base.VisitInvocationExpression(node);
var symbol = SemanticHelper.GetSemanticSymbol(node, _semanticModel, _preportSemanticModel);

if (symbol == null)
{
return node;
}

var prefix = symbol.IsExtensionMethod ? symbol.ReceiverType?.ToString() ?? "" : symbol.ContainingType?.ToString() ?? "";
var nodeKey = $"{prefix}.{symbol.Name}({string.Join(", ", symbol.Parameters.Select(p => p.Type))})";
var nodeKey = "";
if (symbol is IMethodSymbol)
{
var methodSymbol = (IMethodSymbol)symbol;
var prefix = methodSymbol.IsExtensionMethod
? methodSymbol.ReceiverType?.ToString() ?? ""
: methodSymbol.ContainingType?.ToString() ?? "";
nodeKey =
$"{prefix}.{symbol.Name}({string.Join(", ", methodSymbol.Parameters.Select(p => p.Type))})";
}
else if (symbol is IPropertySymbol)
{
var propertySymbol = (IPropertySymbol)symbol;
var prefix = propertySymbol.ContainingType?.ToString() ?? "";
nodeKey =
$"{prefix}.{symbol.Name}({string.Join(", ", propertySymbol.Parameters.Select(p => p.Type))})";
}

var newNode = base.VisitInvocationExpression(node);

foreach (var action in _allActions.OfType<InvocationExpressionAction<InvocationExpressionSyntax>>())
{
Expand Down
85 changes: 21 additions & 64 deletions tst/CTA.Rules.Test/VisualBasicTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Codelyzer.Analysis;
using CTA.Rules.Config;
using CTA.Rules.Models;
using CTA.Rules.Update;
using NUnit.Framework;

namespace CTA.Rules.Test
Expand All @@ -31,72 +24,18 @@ public void Setup()
.ToList();
}

private TestSolutionAnalysis runCTAFile(string solutionName, string projectName = null)
{
var solutionPath = CopySolutionFolderToTemp(solutionName, _downloadLocation);
var solutionDir = Directory.GetParent(solutionPath).FullName;

FileAssert.Exists(solutionPath);

//Sample Web API has only one project:
string projectFile = (projectName == null ? Utils.GetProjectPaths(Path.Combine(solutionDir, solutionName)).FirstOrDefault() : Directory.EnumerateFiles(solutionDir, projectName, SearchOption.AllDirectories).FirstOrDefault());
FileAssert.Exists(projectFile);

ProjectConfiguration projectConfiguration = new ProjectConfiguration()
{
SolutionPath = solutionPath,
ProjectPath = projectFile,
TargetVersions = new List<string> { _version },
RulesDir = Constants.RulesDefaultPath,
AdditionalReferences = _ctaFiles
};

List<ProjectConfiguration> solutionConfiguration = new List<ProjectConfiguration>
{
projectConfiguration
};
CopyTestRules();

SolutionRewriter solutionRewriter = new SolutionRewriter(solutionPath, solutionConfiguration);
var analysisRunResult = solutionRewriter.AnalysisRun();
StringBuilder str = new StringBuilder();
foreach (var projectResult in analysisRunResult.ProjectResults)
{
str.AppendLine(projectResult.ProjectFile);
str.AppendLine(projectResult.ProjectActions.ToString());
}
var analysisResult = str.ToString();
solutionRewriter.Run(analysisRunResult.ProjectResults.ToDictionary(p => p.ProjectFile, p => p.ProjectActions));

TestSolutionAnalysis result = new TestSolutionAnalysis()
{
SolutionAnalysisResult = analysisResult,
ProjectResults = new List<ProjectResult>()
{
new ProjectResult()
{
ProjectAnalysisResult = analysisResult,
CsProjectPath = projectFile,
ProjectDirectory = Directory.GetParent(projectFile).FullName,
CsProjectContent = File.ReadAllText(projectFile)
}
}
};

return result;
}

[Test]
public void TestOwinParadiseVb()
{
var slnResults = runCTAFile("OwinParadiseVb.sln");
var slnResults = AnalyzeSolution("OwinParadiseVb.sln", _tempDir, _downloadLocation, _version);
var projresults = slnResults.ProjectResults.FirstOrDefault();
Assert.IsTrue(projresults != null);

StringAssert.Contains("Microsoft.AspNetCore.Hosting", projresults.ProjectAnalysisResult);

var signalR = File.ReadAllText(Path.Combine(projresults.ProjectDirectory, "SignalR.vb"));
var startUp = File.ReadAllText(Path.Combine(projresults.ProjectDirectory, "Startup.vb"));
var projectFile = File.ReadAllText(projresults.CsProjectPath);

//Check that namespace has been added
StringAssert.Contains(@"Microsoft.AspNetCore.Owin", startUp);
Expand All @@ -112,6 +51,10 @@ public void TestOwinParadiseVb()

//Check method actions
StringAssert.Contains("UseEndpoints", signalR);

//Check project porting
StringAssert.Contains("net5.0", projectFile);
StringAssert.Contains("Microsoft.AspNetCore.Diagnostics", projectFile);
}

[Test]
Expand All @@ -129,5 +72,19 @@ public void TestVbNetMvc()
// "<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>",
// results.CsProjectContent);
}

[Test]
public void TestMixedClassLibrary()
{
var slnResults = AnalyzeSolution("MixedClassLibrary.sln",
_tempDir,
_downloadLocation,
_version);
var projresults = slnResults.ProjectResults.Select(p => p.CsProjectContent).ToList();
Assert.IsTrue(projresults != null);
Assert.IsTrue(projresults.Count() == 2);
//check both projects ported
Assert.IsTrue(projresults.All(content => content.Contains("net5.0")));
}
}
}