CleanCodeDeveloper.Analyzers
0.1.0
See the version list below for details.
dotnet add package CleanCodeDeveloper.Analyzers --version 0.1.0
NuGet\Install-Package CleanCodeDeveloper.Analyzers -Version 0.1.0
<PackageReference Include="CleanCodeDeveloper.Analyzers" Version="0.1.0" />
paket add CleanCodeDeveloper.Analyzers --version 0.1.0
#r "nuget: CleanCodeDeveloper.Analyzers, 0.1.0"
// Install CleanCodeDeveloper.Analyzers as a Cake Addin #addin nuget:?package=CleanCodeDeveloper.Analyzers&version=0.1.0 // Install CleanCodeDeveloper.Analyzers as a Cake Tool #tool nuget:?package=CleanCodeDeveloper.Analyzers&version=0.1.0
Clean Code Developer Roslyn Analyzers
This project started as an article for the german dotnetpro[https://dotnetpro.de] magazine. It contains Roslyn Analyzers for Clean Code Developer[https://clean-code-developer.com] principles.
The current version analyzes if methods violate the IOSP: Integration Operation Segregation Principle. The principle states that a method is either an integration method or an operation. Integration methods call other methods that are defined and implemented in the solution. If one of your methods calls another of your methods its responsibility is to integrate. On the other hand an operation must not call one of your own methods. An operation calls APIs and contains expressions like "x + 2 < 42". API calls are calls to foreign methods that are not defined in your code. For example Console.WriteLine or object.ToString are API calls.
The reasoning behind the IOSP is the following: if we strictly separate integration from operation this leads to a better understanding of the code structure. This is because the abstraction level is clearly separated into high level vs. low level code. Integration methods are on a high level. They only call other methods in order to integrate them. Thus it is easy to understand such a high level integration method. On the other hand an operation is easy to read because it contains code only on a low level. Given that an operation must also conform to the SRP (Single Responsibility Principle) it is easy to read and understand an operation because it contains only low level code that solves a specific problem. In order to understand an operation it is not necessary to understand other methods from the solution. It is only necessary to understand calls to runtime or framework functionality.
The second advantage of conforming to the IOSP is testability. If we strictly separate integration from operation we can test the operations in isolation. Because operations don't call other methods from our solution every operation is a separate functional unit. Thus we don't need any mocks in order to separate an operation from its dependencies. It has no dependancies otherwise it would mix operational code with integration. The integeration methods don't contain any logic. So it is not necessary to separate the integration methods from their dependencies. The only job of the integration methods is to integrate calls to other methods. So we test the integration methods with integration tests.
Integration methods can contain control structures like foreach, for, while, if or case statements. They must not contain any expressions. It is ok to call a function that contains the expression:
if(x + 2 == 42) { ... }
vs.
if(ThisIsTheAnswer(x)) { ... }
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.4.2 | 182 | 8/15/2024 |
0.4.1 | 102 | 8/5/2024 |
0.4.0 | 74 | 8/5/2024 |
0.3.6 | 71 | 8/3/2024 |
0.3.5 | 115 | 7/30/2024 |
0.3.4 | 84 | 7/30/2024 |
0.3.3 | 85 | 7/30/2024 |
0.3.2 | 99 | 7/28/2024 |
0.3.0 | 122 | 7/8/2024 |
0.2.1 | 111 | 7/8/2024 |
0.2.0 | 146 | 4/5/2024 |
0.1.0 | 181 | 3/28/2024 |
0.0.6 | 1,896 | 10/25/2020 |
0.0.5 | 503 | 10/19/2020 |
0.0.4 | 478 | 10/3/2020 |
0.0.3 | 577 | 9/26/2020 |
0.0.2 | 588 | 9/26/2020 |
Integration Operation Segregation Principle (IOSP) is verified for methods