Skip to content

Commit

Permalink
Introduce AnalyzerStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Nov 25, 2021
1 parent 25aa05e commit c5f0ae7
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 21 deletions.
13 changes: 13 additions & 0 deletions src/EFCore.Analyzers/EFCore.Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

<ItemGroup>
<Compile Include="..\Shared\CodeAnnotations.cs" />
<Compile Update="Properties\AnalyzerStrings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AnalyzerStrings.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand All @@ -45,4 +50,12 @@
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\AnalyzerStrings.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>AnalyzerStrings.Designer.cs</LastGenOutput>
<CustomToolNamespace>Microsoft.EntityFrameworkCore</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>

</Project>
15 changes: 3 additions & 12 deletions src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,14 @@ namespace Microsoft.EntityFrameworkCore;
public sealed class InternalUsageDiagnosticAnalyzer : DiagnosticAnalyzer
{
public const string Id = "EF1001";

public const string MessageFormat
= "{0} is an internal API that supports the Entity Framework Core infrastructure and "
+ "not subject to the same compatibility standards as public APIs. "
+ "It may be changed or removed without notice in any release.";

private const string DefaultTitle = "Internal EF Core API usage.";
private const string Category = "Usage";

private static readonly int EFLen = "EntityFrameworkCore".Length;

private static readonly DiagnosticDescriptor _descriptor
= new(
Id,
title: DefaultTitle,
messageFormat: MessageFormat,
category: Category,
title: AnalyzerStrings.InternalUsageTitle,
messageFormat: AnalyzerStrings.InternalUsageMessageFormat,
category: "Usage",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

Expand Down
66 changes: 66 additions & 0 deletions src/EFCore.Analyzers/Properties/AnalyzerStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/EFCore.Analyzers/Properties/AnalyzerStrings.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="UninitializedDbSetWarningSuppressionJustification" xml:space="preserve">
<value>DbSet properties on DbContext subclasses are automatically populated by the DbContext constructor.</value>
</data>
<data name="InternalUsageMessageFormat" xml:space="preserve">
<value>{0} is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.</value>
</data>
<data name="InternalUsageTitle" xml:space="preserve">
<value>Internal EF Core API usage.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class UninitializedDbSetDiagnosticSuppressor : DiagnosticSuppresso
private static readonly SuppressionDescriptor _suppressUninitializedDbSetRule = new(
id: "SPR1001",
suppressedDiagnosticId: "CS8618",
justification: "DbSet properties on DbContext subclasses are automatically populated by the DbContext constructor");
justification: AnalyzerStrings.UninitializedDbSetWarningSuppressionJustification);

/// <inheritdoc />
public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MyClass : Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalPara
Assert.Equal(DiagnosticSeverity.Warning, diagnostic.Severity);
Assert.Equal(
string.Format(
InternalUsageDiagnosticAnalyzer.MessageFormat,
AnalyzerStrings.InternalUsageMessageFormat,
"Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalParameter"),
diagnostic.GetMessage());

Expand All @@ -55,7 +55,7 @@ class MyClass : Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalPara
Assert.Equal(DiagnosticSeverity.Warning, diagnostic.Severity);
Assert.Equal(
string.Format(
InternalUsageDiagnosticAnalyzer.MessageFormat,
AnalyzerStrings.InternalUsageMessageFormat,
"Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalParameter"),
diagnostic.GetMessage());

Expand Down Expand Up @@ -201,9 +201,7 @@ private async Task Test(

Assert.Equal(InternalUsageDiagnosticAnalyzer.Id, diagnostic.Id);
Assert.Equal(DiagnosticSeverity.Warning, diagnostic.Severity);
Assert.Equal(
string.Format(InternalUsageDiagnosticAnalyzer.MessageFormat, expectedInternalApi),
diagnostic.GetMessage());
Assert.Equal(string.Format(AnalyzerStrings.InternalUsageMessageFormat, expectedInternalApi), diagnostic.GetMessage());

var span = diagnostic.Location.SourceSpan;
Assert.Equal(expectedDiagnosticSpan, fullSource[span.Start..span.End]);
Expand All @@ -219,9 +217,7 @@ private async Task TestFullSource(

Assert.Equal(InternalUsageDiagnosticAnalyzer.Id, diagnostic.Id);
Assert.Equal(DiagnosticSeverity.Warning, diagnostic.Severity);
Assert.Equal(
string.Format(InternalUsageDiagnosticAnalyzer.MessageFormat, expectedInternalApi),
diagnostic.GetMessage());
Assert.Equal(string.Format(AnalyzerStrings.InternalUsageMessageFormat, expectedInternalApi), diagnostic.GetMessage());

var span = diagnostic.Location.SourceSpan;
Assert.Equal(expectedDiagnosticSpan, fullSource[span.Start..span.End]);
Expand Down

0 comments on commit c5f0ae7

Please sign in to comment.