Skip to content

Commit

Permalink
Merge pull request #10 from almostchristian/develop
Browse files Browse the repository at this point in the history
Fix warnings
  • Loading branch information
almostchristian authored Sep 7, 2023
2 parents 56337a6 + e3b80cc commit d43c28d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static string ToDisplay(IParameterSymbol parameter)
if (foundServiceCollection && matchesServiceCollection)
{
keepMethod = false;
Diag(DiagnosticDescriptors.InvalidGenerateConfigurationMethodName, paramSymbol.Locations[0]);
Diag(DiagnosticDescriptors.MultipleServiceCollectionParameter, paramSymbol.Locations[0]);
break;
}
else if (matchesServiceCollection)
Expand All @@ -300,7 +300,7 @@ static string ToDisplay(IParameterSymbol parameter)
if (foundConfiguration && matchesConfiguration)
{
keepMethod = false;
Diag(DiagnosticDescriptors.InvalidGenerateConfigurationMethodName, paramSymbol.Locations[0]);
Diag(DiagnosticDescriptors.MultipleConfigurationParameter, paramSymbol.Locations[0]);
break;
}
else if (matchesConfiguration)
Expand Down Expand Up @@ -345,7 +345,7 @@ static string ToDisplay(IParameterSymbol parameter)
if (foundServiceCollection && matchesServiceCollection)
{
keepMethod = false;
Diag(DiagnosticDescriptors.InvalidGenerateConfigurationMethodName, paramSymbol.Locations[0]);
Diag(DiagnosticDescriptors.MultipleServiceCollectionParameter, paramSymbol.Locations[0]);
break;
}
else if (matchesServiceCollection)
Expand All @@ -357,7 +357,7 @@ static string ToDisplay(IParameterSymbol parameter)
if (foundConfiguration && matchesConfiguration)
{
keepMethod = false;
Diag(DiagnosticDescriptors.InvalidGenerateConfigurationMethodName, paramSymbol.Locations[0]);
Diag(DiagnosticDescriptors.MultipleConfigurationParameter, paramSymbol.Locations[0]);
break;
}
else if (matchesConfiguration)
Expand Down Expand Up @@ -390,12 +390,12 @@ static string ToDisplay(IParameterSymbol parameter)

if (multipleServiceCollectionFields)
{
Diag(DiagnosticDescriptors.MultipleServiceCollectionFields, method.GetLocation(), classDec.Identifier.Text);
Diag(DiagnosticDescriptors.MultipleServiceCollectionParameter, method.GetLocation(), classDec.Identifier.Text);
keepMethod = false;
}
else if (serviceCollectionField == null)
{
Diag(DiagnosticDescriptors.MissingServiceCollectionField, method.GetLocation(), classDec.Identifier.Text);
Diag(DiagnosticDescriptors.MissingServiceCollectionParameter, method.GetLocation(), classDec.Identifier.Text);
keepMethod = false;
}
else
Expand All @@ -405,7 +405,7 @@ static string ToDisplay(IParameterSymbol parameter)
}
else if (!foundConfiguration)
{
Diag(DiagnosticDescriptors.MissingConfigurationField, method.GetLocation(), classDec.Identifier.Text);
Diag(DiagnosticDescriptors.MissingConfigurationParameter, method.GetLocation(), classDec.Identifier.Text);
keepMethod = false;
}
}
Expand Down Expand Up @@ -444,6 +444,12 @@ potentialNamespaceParent is not NamespaceDeclarationSyntax &&
}
}

if (string.IsNullOrEmpty(nspace))
{
keepMethod = false;
Diag(DiagnosticDescriptors.TopLevelClassNotSupported, method.GetLocation());
}

if (keepMethod)
{
lc ??= new ServiceRegistrationClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static DiagnosticDescriptor Create(
string? description = null,
params string[] customTags)
{
string helpLink = $"https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/{id.ToLowerInvariant()}.md";
string helpLink = $"https://github.com/almostchristian/ConfigurationProcessor.DependencyInjection/diagnostics/{id.ToLowerInvariant()}.md";

return new DiagnosticDescriptor(id, title, messageFormat, category, defaultSeverity, isEnabledByDefault, description, helpLink, customTags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,34 @@ internal static class DiagnosticDescriptors
DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static DiagnosticDescriptor MissingConfigurationField { get; } = DiagnosticDescriptorHelper.Create(
public static DiagnosticDescriptor MissingConfigurationParameter { get; } = DiagnosticDescriptorHelper.Create(
id: "CPGEN1018",
title: "Missing IConfiguration field",
messageFormat: "Missing IConfiguration field",
title: "Missing IConfiguration parameter/field",
messageFormat: "Missing IConfiguration parameter/field",
category: Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static DiagnosticDescriptor MissingServiceCollectionField { get; } = DiagnosticDescriptorHelper.Create(
public static DiagnosticDescriptor MissingServiceCollectionParameter { get; } = DiagnosticDescriptorHelper.Create(
id: "CPGEN1019",
title: "Missing IServiceCollection field",
messageFormat: "Missing IServiceCollection field",
title: "Missing IServiceCollection parameter/field",
messageFormat: "Missing IServiceCollection paramter/field",
category: Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static DiagnosticDescriptor MultipleServiceCollectionFields { get; } = DiagnosticDescriptorHelper.Create(
public static DiagnosticDescriptor MultipleServiceCollectionParameter { get; } = DiagnosticDescriptorHelper.Create(
id: "CPGEN1020",
title: "Multiple IServiceCollection fields",
messageFormat: "Multiple IServiceCollection fields",
title: "Multiple IServiceCollection parameters/fields",
messageFormat: "Multiple IServiceCollection parameters/fields",
category: Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static DiagnosticDescriptor MultipleConfigurationParameter { get; } = DiagnosticDescriptorHelper.Create(
id: "CPGEN1021",
title: "Multiple IConfiguration parameters/fields",
messageFormat: "Multiple IConfiguration parameters/fields",
category: Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true);
Expand All @@ -117,4 +125,12 @@ internal static class DiagnosticDescriptors
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

public static DiagnosticDescriptor TopLevelClassNotSupported { get; } = DiagnosticDescriptorHelper.Create(
id: "CPGEN1028",
title: "Top level class is not supported.",
messageFormat: "Top level class is not valid.",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);
}
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.Generator')) OR $(MSBuildProjectName.EndsWith('.SourceGeneration'))">
<Version>0.2.1</Version>
<PackageVersion>$(Version)-beta.1</PackageVersion>
<PackageVersion>$(Version)-beta.2</PackageVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit d43c28d

Please sign in to comment.