kuker

[](https://www.nuget.org/packages/kurnakovv.kuker)
[](https://www.nuget.org/packages/kurnakovv.kuker)
[](https://www.nuget.org/packages/kurnakovv.kuker-preview)
[](https://www.nuget.org/packages/kurnakovv.kuker-preview)
[](https://github.com/kurnakovv/kuker/actions/workflows/build-and-tests.yml)
[](https://github.com/kurnakovv/kuker/actions/workflows/dotnet-format.yml)
[](https://github.com/kurnakovv/kuker/actions/workflows/inspect-code.yml)
[](https://pvs-studio.com/en/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source)
[](https://github.com/kurnakovv/kuker/actions/workflows/codeql.yml)
[](https://app.codecov.io/gh/kurnakovv/kuker)
[](https://github.com/kurnakovv/kuker/blob/dev/LICENSE)

## 📙 描述
👨🍳
kuker 是一款 C# 分析器,帮助你 🍳 “kuk” 🔍 出美味且整洁的代码 😸
此分析器基于 [Roslyn API](https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/) | [教程](https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix)
## 🚀 快速开始
1️⃣ 通过 NuGet 安装 kuker:
```
dotnet add package kurnakovv.kuker
```
此命令会将以下引用添加到你的项目中:
```
all
runtime; build; native; contentfiles; analyzers; buildtransitive
```
2️⃣ 构建项目:
```
dotnet build
```
你可能会看到类似以下的输出:
```
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.6s
```
就是这样——kuker 现已启动并运行。祝你编码愉快!🚀
## ⚙️ 配置
你可以通过 `.editorconfig` 文件配置所有规则
```
[*.cs]
## ## kuker
## # 文档请见 https://github.com/kurnakovv/kuker
# 设置所有具有 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
# ...
```
有关配置的更多信息,请访问我们的 [wiki](https://github.com/kurnakovv/kuker/wiki)
## ❔ 原因
.NET 生态系统提供了许多强大的分析器,包括诸如 [CAxxxx](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/categories?view=visualstudio) 和 [IDExxxx](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/?view=visualstudio) 等内置分析器,以及基于 [Roslyn API](https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/) 的知名第三方分析器,例如 [Roslynator](https://josefpihrt.github.io/docs/roslynator/) 和 [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers)。
尽管它们覆盖面很广,但某些规则仍未被覆盖。👨🍳
kuker 分析器旨在通过提供额外的、高度专注的分析规则来填补这些空白。
## ⭐ 点个 Star
我希望这个分析器对你有用,如果是的话,请给这个仓库点个 star,谢谢 :)
## SAST 工具
[PVS-Studio](https://pvs-studio.com/en/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source) - 用于 C、C++、C# 和 Java 代码的静态分析器。