Skip to content
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
4 changes: 0 additions & 4 deletions CodeLineCounter.Tests/CyclomaticComplexityCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public void TestCalculateComplexity()
{
// Arrange
var code = @"
using System;
namespace TestNamespace
{
public class TestClass
{
public void TestMethod()
Expand All @@ -22,7 +19,6 @@ public void TestMethod()
for (int i = 0; i < 10; i++) {}
}
}
}
";
var tree = CSharpSyntaxTree.ParseText(code);
var compilation = CSharpCompilation.Create("Test", new[] { tree });
Expand Down
10 changes: 9 additions & 1 deletion CodeLineCounter/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CodeLineCounter.Services;
using CodeLineCounter.Utils;
using System.Diagnostics;
using System;
using System.IO;

Expand Down Expand Up @@ -49,12 +50,18 @@ static void Main(string[] args)
Console.Write("Choose a solution to analyze (enter the number): ");
if (int.TryParse(Console.ReadLine(), out int choice) && choice > 0 && choice <= solutionFiles.Count)
{
// Add watch
var timer = new Stopwatch();
timer.Start();
string solutionPath = solutionFiles[choice - 1];
string solutionFilename = Path.GetFileName(solutionPath);
string csvFilePath = solutionFilename + "-" + "CodeMetrics.csv"; // You can modify this path according to your needs

var analyzer = new CodeAnalyzer();
var (metrics, projectTotals, totalLines, totalFiles) = analyzer.AnalyzeSolution(solutionPath);
timer.Stop();
TimeSpan timeTaken = timer.Elapsed;
string processingTime = "Time taken: " + timeTaken.ToString(@"m\:ss\.fff");

if (verbose)
{
Expand All @@ -72,8 +79,9 @@ static void Main(string[] args)
Console.WriteLine($"Total lines of code: {totalLines}");

// Export the data to CSV format
CsvExporter.ExportToCsv(csvFilePath, metrics, projectTotals, totalLines);
CsvExporter.ExportToCsv(csvFilePath, metrics.ToList(), projectTotals, totalLines);
Console.WriteLine($"The data has been exported to {csvFilePath}");
Console.WriteLine(processingTime);
}
else
{
Expand Down
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,24 @@ The program generates a CSV file named `CodeMetrics.csv` containing the followin
## Example Output

```csv
Project,ProjectPath,Namespace,FileName,FilePath,LineCount,CyclomaticComplexity
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter,Program.cs,CodeLineCounter\Program.cs,56,7
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Models,NamespaceMetrics.cs,CodeLineCounter\Models\NamespaceMetrics.cs,13,1
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,NamespaceMetrics,CodeAnalyzer.cs,CodeLineCounter\Services\CodeAnalyzer.cs,101,10
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Services,CyclomaticComplexityCalculator.cs,CodeLineCounter\Services\CyclomaticComplexityCalculator.cs,65,12
Project,ProjectPath,Namespace,FileName,FilePath,LineCount,CyclomaticComplexity,
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Utils,CsvExporter.cs,CodeLineCounter\Utils\CsvExporter.cs,32,5
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter,Program.cs,CodeLineCounter\Program.cs,71,11
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Services,CyclomaticComplexityCalculator.cs,CodeLineCounter\Services\CyclomaticComplexityCalculator.cs,65,12
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Models,NamespaceMetrics.cs,CodeLineCounter\Models\NamespaceMetrics.cs,13,1
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,NamespaceMetrics,CodeAnalyzer.cs,CodeLineCounter\Services\CodeAnalyzer.cs,142,8
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Utils,FileUtils.cs,CodeLineCounter\Utils\FileUtils.cs,33,3
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter,Total,.\CodeLineCounter,54,0
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Models,Total,.\CodeLineCounter,13,0
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Services,Total,.\CodeLineCounter,114,0
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,NamespaceMetrics,Total,.\CodeLineCounter,46,0
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Utils,Total,.\CodeLineCounter,62,0
CodeLineCounter,Total,,,,300,
CodeLineCounter.Tests,CodeLineCounter.Tests\CodeLineCounter.Tests.csproj,CodeLineCounter.Tests,CodeAnalyzerTests.cs,CodeLineCounter.Tests\CodeAnalyzerTests.cs,19,1
CodeLineCounter.Tests,CodeLineCounter.Tests\CodeLineCounter.Tests.csproj,TestNamespace,CyclomaticComplexityCalculatorTests.cs,CodeLineCounter.Tests\CyclomaticComplexityCalculatorTests.cs,32,1
CodeLineCounter.Tests,CodeLineCounter.Tests\CodeLineCounter.Tests.csproj,CodeLineCounter.Tests,Total,.\CodeLineCounter.Tests,27,0
CodeLineCounter.Tests,CodeLineCounter.Tests\CodeLineCounter.Tests.csproj,TestNamespace,Total,.\CodeLineCounter.Tests,21,0
CodeLineCounter.Tests,Total,,,,51,
Total,,,,,351,
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter,Total,.\CodeLineCounter,67,0
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Models,Total,.\CodeLineCounter,13,0
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,NamespaceMetrics,Total,.\CodeLineCounter,101,0
CodeLineCounter,CodeLineCounter\CodeLineCounter.csproj,CodeLineCounter.Services,Total,.\CodeLineCounter,100,0
CodeLineCounter,Total,,,,356,
CodeLineCounter.Tests,CodeLineCounter.Tests\CodeLineCounter.Tests.csproj,CodeLineCounter.Tests,CodeAnalyzerTests.cs,CodeLineCounter.Tests\CodeAnalyzerTests.cs,68,1
CodeLineCounter.Tests,CodeLineCounter.Tests\CodeLineCounter.Tests.csproj,CodeLineCounter.Tests,CyclomaticComplexityCalculatorTests.cs,CodeLineCounter.Tests\CyclomaticComplexityCalculatorTests.cs,54,1
CodeLineCounter.Tests,CodeLineCounter.Tests\CodeLineCounter.Tests.csproj,CodeLineCounter.Tests,Total,.\CodeLineCounter.Tests,118,0
CodeLineCounter.Tests,Total,,,,122,
Total,,,,,478,
```

## Project Structure
Expand Down