Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.5" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageVersion Include="MinVer" Version="7.0.0" />
<PackageVersion Include="Verify.Xunit" Version="31.12.5" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="Verify.XunitV3" Version="31.15.0" />
<PackageVersion Include="xunit.v3" Version="1.1.0" />
<PackageVersion Include="XUnit.Hosting" Version="4.0.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions src/Injectio.Generators/AnalyzerReleases.Shipped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; Shipped analyzer releases
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
16 changes: 16 additions & 0 deletions src/Injectio.Generators/AnalyzerReleases.Unshipped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

### New Rules

Rule ID | Category | Severity | Notes
--------|----------|----------|-------
INJECT0001 | Injectio | Warning | RegisterServices method has invalid signature
INJECT0002 | Injectio | Warning | RegisterServices method has invalid second parameter
INJECT0003 | Injectio | Warning | RegisterServices method has too many parameters
INJECT0004 | Injectio | Warning | Factory method not found
INJECT0005 | Injectio | Warning | Factory method must be static
INJECT0006 | Injectio | Warning | Factory method has invalid signature
INJECT0007 | Injectio | Warning | Implementation does not implement service type
INJECT0008 | Injectio | Warning | Implementation type is abstract
INJECT0009 | Injectio | Warning | RegisterServices on non-static method in abstract class
80 changes: 80 additions & 0 deletions src/Injectio.Generators/DiagnosticDescriptors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Microsoft.CodeAnalysis;

namespace Injectio.Generators;

public static class DiagnosticDescriptors
{
private const string Category = "Injectio";

public static readonly DiagnosticDescriptor InvalidMethodSignature = new(
id: "INJECT0001",
title: "RegisterServices method has invalid signature",
messageFormat: "Method '{0}' marked with [RegisterServices] must have IServiceCollection as its first parameter",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor InvalidMethodSecondParameter = new(
id: "INJECT0002",
title: "RegisterServices method has invalid second parameter",
messageFormat: "Method '{0}' marked with [RegisterServices] has an invalid second parameter; expected a string collection (e.g., IEnumerable<string>)",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor MethodTooManyParameters = new(
id: "INJECT0003",
title: "RegisterServices method has too many parameters",
messageFormat: "Method '{0}' marked with [RegisterServices] has {1} parameters; expected 1 or 2",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor FactoryMethodNotFound = new(
id: "INJECT0004",
title: "Factory method not found",
messageFormat: "Factory method '{0}' was not found on type '{1}'",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor FactoryMethodNotStatic = new(
id: "INJECT0005",
title: "Factory method must be static",
messageFormat: "Factory method '{0}' on type '{1}' must be static",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor FactoryMethodInvalidSignature = new(
id: "INJECT0006",
title: "Factory method has invalid signature",
messageFormat: "Factory method '{0}' on type '{1}' must accept IServiceProvider as its first parameter and optionally object? as its second parameter",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor ServiceTypeMismatch = new(
id: "INJECT0007",
title: "Implementation does not implement service type",
messageFormat: "Type '{0}' does not implement or inherit from service type '{1}'",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor AbstractImplementationType = new(
id: "INJECT0008",
title: "Implementation type is abstract",
messageFormat: "Implementation type '{0}' is abstract and cannot be instantiated without a factory method",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor RegisterServicesMethodOnAbstractClass = new(
id: "INJECT0009",
title: "RegisterServices on non-static method in abstract class",
messageFormat: "Method '{0}' marked with [RegisterServices] is a non-static method on abstract class '{1}'; the class cannot be instantiated",
category: Category,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);
}
5 changes: 5 additions & 0 deletions src/Injectio.Generators/Injectio.Generators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@
</None>
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>

</Project>
Loading
Loading