π¨βπ³ kuker is a C# analyzer that helps you βπ³ "kuk" βπ tasty and clean code πΈ
This analyzer based on Roslyn API | Tutorial
1οΈβ£ Install kuker via NuGet:
dotnet add package kurnakovv.kuker
This command adds the following reference to your project:
<!-- Use the latest available version -->
<PackageReference Include="kurnakovv.kuker" Version="0.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>Note
It is recommended to define this dependency in Directory.Build.props (what is it?)
2οΈβ£ Build the project:
dotnet build
You may see output similar to the following:
PS D:\C#\JustApplication> dotnet build
Restore complete (0.7s)
JustApplication net8 succeeded with 7 warning(s) (3.5s) β JustApplication\bin\Debug\net8\JustApplication.dll
D:\C#\JustApplication\JustApplication\Program.cs(2414,21): warning CS0219: The variable 'afdf' is assigned but its value is never used
D:\C#\JustApplication\JustApplication\MyTest\MyTest.cs(1,1): warning KUK0002: The file name should match the name of one of the public or internal types: 'UserDto, TestClass, Point' (https://github.com/kurnakovv/kuker/wiki/KUK0002)
D:\C#\JustApplication\JustApplication\Program.cs(2388,44): warning KUK0001: Argument 'a.MyTest.Ids' is passed multiple times to the same method call (https://github.com/kurnakovv/kuker/wiki/KUK0001)
D:\C#\JustApplication\JustApplication\Program.cs(2390,48): warning KUK0001: Argument 'a.MyTest?.Ids' is passed multiple times to the same method call (https://github.com/kurnakovv/kuker/wiki/KUK0001)
D:\C#\JustApplication\JustApplication\MyTest\MyTest.cs(20,41): warning KUK0003: 'Max' on a sequence of non-nullable value types may throw InvalidOperationException if the sequence is empty. Use a nullable selector or DefaultIfEmpty(). (https://github.com/kurnakovv/kuker/wiki/KUK0003)
D:\C#\JustApplication\JustApplication\MyTest\MyTest.cs(23,38): warning KUK0003: 'MaxAsync' on a sequence of non-nullable value types may throw InvalidOperationException if the sequence is empty. Use a nullable selector or DefaultIfEmpty(). (https://github.com/kurnakovv/kuker/wiki/KUK0003)
D:\C#\JustApplication\JustApplication\Program.cs(2393,34): warning KUK0001: Argument '(Test)a' is passed multiple times to the same method call (https://github.com/kurnakovv/kuker/wiki/KUK0001)
Build succeeded with 7 warning(s) in 4.6sThat's it - kuker is now up and running. Happy coding! π
You can configure all rules via .editorconfig file
[*.cs]
##
## kuker
##
# Docs here https://github.com/kurnakovv/kuker
# Setup all rules with global category
dotnet_analyzer_diagnostic.category-KukerAllRules.severity = warning
dotnet_diagnostic.KUK0001.severity = warning # Duplicate arguments passed to method | https://github.com/kurnakovv/kuker/wiki/KUK0001
dotnet_diagnostic.KUK0002.severity = warning # File name mismatch | https://github.com/kurnakovv/kuker/wiki/KUK0002
dotnet_diagnostic.KUK0003.severity = warning # Min/Max (Async) and MinBy/MaxBy may throw InvalidOperationException on empty sequences | https://github.com/kurnakovv/kuker/wiki/KUK0003
dotnet_diagnostic.KUK0004.severity = warning # Avoid primary constructor | https://github.com/kurnakovv/kuker/wiki/KUK0004
dotnet_diagnostic.KUK0005.severity = warning # .TagWithCallSite() on EF Core query execution | https://github.com/kurnakovv/kuker/wiki/KUK0005
dotnet_diagnostic.KUK0001.excluded_methods = Foo,Bar # Optional | Ignore selected methods
# ...For more information about the configuration, please visit our wiki
The .NET ecosystem offers many powerful analyzers, including built-in ones like CAxxxx and IDExxxx, as well as well-known third-party analyzers based on the Roslyn API, such as Roslynator and StyleCop.
Despite their wide coverage, certain rules remain uncovered. π¨βπ³ kuker analyzer is designed to address these gaps by providing additional, highly focused analysis rules.
I hope this analyzer is useful for you, if so, please give this repository a star, thank you :)
PVS-Studio - static analyzer for C, C++, C#, and Java code.
