RSCG – rscg_demeter
| name | rscg_demeter | 
| nuget | https://www.nuget.org/packages/rscg_demeter/ | 
| link | https://github.com/ignatandrei/rscg_demeter/ | 
| author | Andrei Ignat | 
Generating diagnostics about Law of Demeter violations
This is how you can use rscg_demeter .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net9.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <IsPackable>false</IsPackable> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <WarningsNotAsErrors>CS0436,NU1903</WarningsNotAsErrors> </PropertyGroup> <ItemGroup> <CompilerVisibleProperty Include="RSCG_Demeter_GenerateFile" /> </ItemGroup> <PropertyGroup> <RSCG_Demeter_GenerateFile>obj/gx/RSCG_Console.csproj.txt</RSCG_Demeter_GenerateFile> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.3" /> <PackageReference Include="RSCG_Demeter" Version="2026.328.706" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> </ItemGroup> <PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> </PropertyGroup> </Project>
The code that you will use is
  // See https://aka.ms/new-console-template for more information using RSCG_Console;  Console.WriteLine("Hello,World!"); var dep = new Department(); dep.Employees.Add(new Employee());  foreach (var emp in dep.Employees) {     dep.EmployeeNames.Add(emp.Name); } var empAll = dep.Employees; var empWithA = empAll.Where(it => it.Name.StartsWith("a")); await Task.Run(dep.GetEmployees); var asda = new List<int>(empAll.Select(it => it.ID).Distinct().OrderBy(it => it)); Console.WriteLine(asda.Count); List<string> data = []; var d = AppDomain.CurrentDomain.GetAssemblies()     .Where(it => data.Any(a => !(it.FullName?.StartsWith(a) ?? false)))     .Distinct()     .ToArray();  var builder = new EmpBuilder().SetName("Ignat").SetId(1).SetName("Andrei"); var emp1 =builder.BuildEmployee();  
The code that is generated is
 {   "dateGenerator": "20250329050839","nameGenerator": "Gerhart Hauptmann is feeling agreeable in Porto-Novo","maxDemeterDots": 3,"locationsFound": 5,"DemeterLocations": [     {       "id": 1,"startLine": 5,"nrDots": 2,"endLine": 5,"filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs","text": "dep.Employees.Add(new Employee())"     },{       "id": 2,"startLine": 9,"nrDots": 2,"endLine": 9,"filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs","text": "    dep.EmployeeNames.Add(emp.Name)"     },{       "id": 3,"startLine": 12,"nrDots": 2,"endLine": 12,"filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs","text": "it.Name.StartsWith(\u0022a\u0022)"     },{       "id": 4,"startLine": 14,"nrDots": 2,"endLine": 14,"filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs","text": "empAll.Select(it =\u003E it.ID).Distinct().OrderBy(it =\u003E it)"     },{       "id": 5,"startLine": 17,"nrDots": 3,"endLine": 20,"filePath": "D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\rscg_demeter\\src\\RSCG_Console\\Program.cs","text": "AppDomain.CurrentDomain.GetAssemblies()\r\n    .Where(it =\u003E data.Any(a =\u003E !(it.FullName?.StartsWith(a) ?? false)))\r\n    .Distinct()\r\n    .ToArray()"     }   ] } 
Code and pdf at https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg_demeter
Leave a Reply