cybermaxs/awesome-analyzers
GitHub: cybermaxs/awesome-analyzers
一个精选的 .NET Roslyn 诊断分析器和代码修复资源列表,旨在提升代码质量、安全性和可维护性。
Stars: 629 | Forks: 35
# 精彩分析器
一份精选的 .NET Compiler Platform ("Roslyn") 诊断分析器、代码修复及相关资源列表。
欢迎所有人在此贡献!
## 入门指南
用于创建您的第一个分析器的资源:
* [使用 Roslyn 为您的 API 编写实时代码分析器](https://msdn.microsoft.com/en-us/magazine/dn879356.aspx) - Alex Turner 撰写的 MSDN 杂志文章
* [为您的 Roslyn 分析器添加代码修复](https://msdn.microsoft.com/en-us/magazine/dn904670.aspx) - Alex Turner 撰写的 MSDN 杂志文章
* [如何编写 C# 分析器和代码修复](https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix) - Microsoft Learn 教程
* [使用 Roslyn 分析器的 ASP.NET Core 中间件](https://blog.elmah.io/asp-net-core-middleware-with-roslyn-analyzers-part-1/) - Thomas Ardal 撰写的 elmah.io 博客文章
* [.NET Analyzers GitHub 组织](https://github.com/DotNetAnalyzers) - 一个使用 .NET Compiler Platform 开发分析器(诊断、代码修复和重构)的组织。
## 流行的分析器
### 分析器集合
* [.NET 源代码分析](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview) - 由 Roslyn 团队开发和维护的官方 Roslyn 诊断分析器。内置分析器包含在 .NET SDK 中,可通过在您的项目文件中添加 `EnableNETAnalyzers` 属性来启用。其他分析器可作为单独的 NuGet 包获取,例如:
* [Microsoft.CodeAnalysis.PublicApiAnalyzers](https://www.nuget.org/packages/Microsoft.CodeAnalysis.PublicApiAnalyzers/) - 一组 Roslyn 诊断分析器,用于跟踪可复用代码的公共 API 暴露情况,有助于正确的封装。
* [Microsoft.CodeAnalysis.BannedApiAnalyzers](https://www.nuget.org/packages/Microsoft.CodeAnalysis.BannedApiAnalyzers/) - 一组 Roslyn 诊断分析器,用于帮助强制执行禁止使用的 API。
* [StyleCopAnalyzers](https://github.com/DotNetAnalyzers/StyleCopAnalyzers) - 使用 .NET Compiler Platform 实现的 StyleCop 规则。
* [Wintellect.Analyzers](https://github.com/Wintellect/Wintellect.Analyzers) - 由 Wintellect 编写的 .NET Compiler Platform ("Roslyn") 诊断分析器和代码修复。
* [sonarlint-vs](https://github.com/SonarSource/sonarlint-visualstudio) - SonarLint 是一个 Visual Studio 2015 扩展,可即时向开发者反馈新引入的缺陷和代码质量问题。
* [sonar-dotnet](https://github.com/SonarSource/sonar-dotnet) - Sonar Roslyn 分析器,为 SonarLint 提供支持。它们也作为 [SonarAnalyzer.CSharp](https://www.nuget.org/packages/SonarAnalyzer.CSharp/) NuGet 包发布。
* [Roslynator](https://github.com/JosefPihrt/Roslynator) - 一个包含 500 多个 C# 分析器、重构和修复的集合,由 Roslyn 提供支持。
* [ErrorProne.NET](https://github.com/SergeyTeplyakov/ErrorProne.NET) - ErrorProne.NET 是一组基于 Roslyn 的分析器,可帮助您编写正确的代码。其理念类似于 Google 的 error-prone,但专注于 C# 程序的正确性(可能还包括性能)。
* [Gu.Analyzers](https://github.com/GuOrg/Gu.Analyzers) - Roslyn 分析器和修复。
* [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) - 一个用于在 C# 中强制执行一些良好实践的 Roslyn 分析器。
* [SharpSource](https://github.com/Vannevelj/SharpSource) - 一组分析器,旨在在编译时发现那些否则可能直到为时已晚都未被察觉的缺陷。
* [BlowinCleanCode](https://github.com/blowin/BlowinCleanCode/) - BlowinCleanCode 是一个基于 Roslyn 的 C# 代码分析器,旨在提供一套规则来帮助简化代码并使其更清晰。
* [Selectorlyzer.Analyzers](https://github.com/rlgnak/Selectorlyzer.Analyzers) - Selectorlyzer.Analyzers 是一个高度可定制的 Roslyn 分析器,旨在赋予开发者使用类似 CSS 选择器语法创建项目特定分析器的能力。
* [Menees.Analyzers](https://github.com/menees/Analyzers) - 基于 Roslyn 的 C# 代码分析器。各种从 StyleCop+ 移植而来的分析器。
* [Exceptionator](https://github.com/elmahio/Exceptionator) - 用于改进 C# 代码中异常处理的 Roslyn 分析器。
* [Philips.CodeAnalysis](https://github.com/philips-software/roslyn-analyzers) - Philips 软件 Roslyn 诊断分析器。包含:
* `Philips.CodeAnalysis.DuplicateCodeAnalyzer`
* `Philips.CodeAnalysis.MaintainabilityAnalyzers`
* `Philips.CodeAnalysis.MoqAnalyzers`
* `Philips.CodeAnalysis.SecurityAnalyzers`
* [AgodaAnalyzers](https://github.com/agoda-com/AgodaAnalyzers) - 一组用于 C# 的固执己见的 Roslyn 分析器。
### 安全
* [SecurityCodeScan](https://github.com/security-code-scan/security-code-scan) - C# 和 VB.NET 的漏洞模式检测器。
* [Puma Scan](https://www.pumascan.com) - 为 C# 应用程序提供实时、持续的源代码分析的安全分析器。
### ASP.NET Core 和 Web
* [AspNetCoreAnalyzers](https://www.nuget.org/packages/AspNetCoreAnalyzers) - 用于 Microsoft.AspNetCore 的分析器。
### 异步/多线程
* [AsyncFixer](https://github.com/semihokur/AsyncFixer) - 针对 C# 的高级 Async/Await 诊断和代码修复。
* [SmartAnalyzers.MultithreadingAnalyzer](https://github.com/cezarypiatek/MultithreadingAnalyzer) - 一组与多线程相关的 Roslyn 分析器。
* [Asyncify](https://www.nuget.org/packages/Asyncify/) - Asyncify-CSharp 是一个分析器和代码修复工具,可让您快速更新代码以使用任务异步编程模型。此模型在 C# 5 中引入,为 C# 中的异步调用提供了一种直观的处理方式。该分析器允许通过查找违规并沿调用树应用修复,轻松地修改大型代码库以使用 TAP 模型。
* [Microsoft.VisualStudio.Threading.Analyzers / vs-threading](https://www.nuget.org/packages/Microsoft.VisualStudio.Threading.Analyzers) - 静态代码分析器,用于检测有关线程和异步编码的常见错误或潜在问题。
* [DbContextThreadSafety.Analyzer](https://github.com/Maxofpower/DbContextThreadSafetyAnalyzer) - 当在多线程或并行场景中使用 DbContext 时,此分析器尤其有用,会对误用 DbContext 发出警告。
### 项目文件
* [.NET 项目文件分析器](https://github.com/dotnet-project-file-analyzers/dotnet-project-file-analyzers) - 报告 .NET 项目文件中的问题。
### 第三方库
* [Moq.Analyzers](https://github.com/rjmurillo/moq.analyzers) - Roslyn 分析器,通过高亮显示典型错误并建议快速修复,帮助使用 Moq 模拟库编写单元测试。它是 Resharper 扩展到 Roslyn 的移植。检测到的问题的完整列表可在项目 GitHub 页面找到。
* [Roslynator.Testing.CSharp.Xunit](https://www.nuget.org/packages/Roslynator.Testing.CSharp.Xunit/) - 用于 Roslyn 分析器、重构和代码修复的测试框架。
* [xunit.analyzers](https://github.com/xunit/xunit.analyzers) - 用于使用 xUnit.net 项目的代码分析器,帮助发现和修复编写测试时的常见问题。
* [ClosedTypeHierarchyDiagnosticSuppressor](https://github.com/shuebner/ClosedTypeHierarchyDiagnosticSuppressor) - 基于 Roslyn 的 C# 诊断抑制器,增强了 `switch` 对闭合类型层次结构模式(即鉴别联合)的穷尽性检查。
* [OneOfDiagnosticSuppressor](https://github.com/shuebner/OneOfDiagnosticSuppressor) - 基于 Roslyn 的 C# 诊断抑制器,增强了 [OneOf 库](https://github.com/mcintyre321/OneOf) 中 `OneOf<...>.Value` 的 `switch` 穷尽性检查,从而能够有效使用原生 `switch` 作为该库自带 `Switch` 和 `Match` 方法的替代方案。
* [NSubstitute.Analyzers](https://github.com/nsubstitute/NSubstitute.Analyzers) - 提供诊断分析器,用于警告在 C# 或 VB 中对 [NSubstitute](https://github.com/nsubstitute/NSubstitute) 的不正确使用。
* [System.IO.Abstractions.Analyzers](https://github.com/TestableIO/System.IO.Abstractions.Analyzers) - 用于帮助使用 [System.IO.Abstractions](https://github.com/Testably/Testably.Abstractions) 包的分析器。
* [FluentAssertions.Analyzers](https://github.com/fluentassertions/fluentassertions.analyzers) - 基于 [FluentAssertions](https://github.com/fluentassertions/fluentassertions) 最佳实践文档的分析器。
* [SerilogAnalyzer](https://github.com/Suchiman/SerilogAnalyzer) - 基于 Roslyn 的分析器,用于使用 [Serilog 日志库](https://github.com/serilog/serilog) 的代码。检查常见错误和使用问题。
### 其他
* [NetFabric.Hyperlinq.Analyzer](https://github.com/NetFabric/NetFabric.Hyperlinq.Analyzer) - C# 中集合枚举的最佳实践。
* [SmartAnalyzers.ExceptionAnalyzer](https://github.com/smartanalyzers/ExceptionAnalyzer) - 一组与异常使用相关的 Roslyn 分析器。
* [DotNetAnalyzers.DocumentationAnalyzers](https://github.com/DotNetAnalyzers/DocumentationAnalyzers) - 使用 Roslyn 分析器和代码修复实现的 .NET 文档规则。
* [IDisposableAnalyzers](https://github.com/DotNetAnalyzers/IDisposableAnalyzers) - 用于 IDisposable 的分析器和修复。
## 已弃用的分析器
* [Code Cracker](https://github.com/code-cracker/code-cracker) - 一个用于 C# 和 VB 的分析器库,使用 Roslyn 生成重构、代码分析和其他特性。
* [CSharpEssentials](https://github.com/DustinCampbell/CSharpEssentials) - C# Essentials 是一个 Roslyn 诊断分析器、代码修复和重构的集合,使处理 C# 6 语言特性变得容易。
* [RefactoringEssentials](https://github.com/icsharpcode/RefactoringEssentials/) - 免费的 Visual Studio 2015 扩展,用于 C# 和 VB.NET 重构,包括代码最佳实践分析器,以改进您的项目。
* [公共 API 分析器](https://github.com/DotNetAnalyzers/PublicApiAnalyzer) (已被 [Microsoft.CodeAnalysis.PublicApiAnalyzers](https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md) 取代) - 帮助跟踪可复用代码的公共 API 暴露情况,有助于正确的封装。
* [VSDiagnostics](https://www.nuget.org/packages/VSDiagnostics/) - 基于新 Roslyn 平台的代码质量分析器集合。此项目旨在确保在您于编辑器中键入代码时即保证代码质量,而不是将其作为单独的构建步骤。
* [RoslynClrHeapAllocationAnalyzer](https://github.com/mjsabby/RoslynClrHeapAllocationAnalyzer) - 基于 Roslyn 的 C# 堆分配诊断分析器,可检测显式和许多隐式分配,如装箱、显示类(即闭包)、隐式委托创建等。
* [Mews.Analyzers](https://www.nuget.org/packages/Mews.Analyzers/) - Mews 使用的基于 Roslyn 的代码分析器。
* [Blowin.Required](https://github.com/blowin/Blowin.Required/) - 实现提案 'Required Properties' [https://github.com/dotnet/csharplang/issues/3630](https://github.com/dotnet/csharplang/issues/3630)。
* [ZeroFormatter.Analyzer](https://www.nuget.org/packages/ZeroFormatter.Analyzer/) - ZeroFormatter 的分析器,验证 [ZeroFormattable] 类的规则。
* [MappingGenerator](https://github.com/cezarypiatek/MappingGenerator) - 🔄 类似 "AutoMapper" 的、基于 Roslyn 的代码修复提供程序,允许在设计时生成映射代码。
## 免费在线工具
* [Roslyn Quoter](https://github.com/KirillOsenkov/RoslynQuoter) - Roslyn 工具,对于给定的 C# 程序,显示用于构造其语法树的语法树 API 调用。
## 博客
* [与 Roslyn 同乐](https://johnkoerner.com/)
* [立即学习 Roslyn](https://joshvarty.com/learn-roslyn-now/)
标签:API 分析, ASP.NET Core, awesome list, NuGet, Roslyn, 代码修复, 代码规范, 代码重构, 多人体追踪, 开源, 教程, 编译器技术, 诊断分析器, 错误基检测, 静态代码分析, 风格检查