Port code fixer for new analyzer
このコミットが含まれているのは:
1 親
a45a43d4e2
コミット
fa88d6aaf2
11ファイル変更
+335
-19
検索条件に一致するファイルはありません
+1
-1
@@ -16,7 +16,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\InvalidGeneratedCanvasEffectPropertyContainingTypeAnalyzer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\InvalidGeneratedCanvasEffectPropertyDeclarationAnalyzer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\RequireCSharpLanguageVersionPreviewAnalyzer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\UseCanvasEffectPropertyOnSemiAutoPropertyAnalyzer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\UseGeneratedCanvasEffectPropertyOnSemiAutoPropertyAnalyzer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\DiagnosticDescriptors.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Models\CanvasEffectPropertyInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)..\ComputeSharp.D2D1.UI\CanvasEffectInvalidationType.cs" Link="ComputeSharp.D2D1.UI\CanvasEffectInvalidationType.cs" />
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ComputeSharp.D2D1.WinUI.SourceGenerators.Constants;
|
||||
internal static class WellKnownTypeNames
|
||||
{
|
||||
/// <summary>
|
||||
/// The fully qualified type name for the <c>[GeneratedCanvasEffectPropertyAttribute]</c> type.
|
||||
/// The fully qualified type name for the <c>[GeneratedCanvasEffectProperty]</c> type.
|
||||
/// </summary>
|
||||
public const string GeneratedCanvasEffectPropertyAttribute =
|
||||
#if WINDOWS_UWP
|
||||
|
||||
+9
-5
@@ -28,10 +28,10 @@ namespace ComputeSharp.D2D1.WinUI.SourceGenerators;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// A diagnostic analyzer that generates a suggestion whenever <c>[CanvasEffectProperty]</c> is used on a semi-auto property when a partial property could be used instead.
|
||||
/// A diagnostic analyzer that generates a suggestion whenever <c>[GeneratedCanvasEffectProperty]</c> is used on a semi-auto property when a partial property could be used instead.
|
||||
/// </summary>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class UseCanvasEffectPropertyOnSemiAutoPropertyAnalyzer : DiagnosticAnalyzer
|
||||
public sealed class UseGeneratedCanvasEffectPropertyOnSemiAutoPropertyAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
/// <summary>
|
||||
/// The number of pooled flags per stack (ie. how many properties we expect on average per type).
|
||||
@@ -55,7 +55,7 @@ public sealed class UseCanvasEffectPropertyOnSemiAutoPropertyAnalyzer : Diagnost
|
||||
public const string InvalidationModePropertyName = "InvalidationMode";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = [UseCanvasEffectPropertyOnSemiAutoProperty];
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = [UseGeneratedCanvasEffectPropertyOnSemiAutoProperty];
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize(AnalysisContext context)
|
||||
@@ -282,10 +282,14 @@ public sealed class UseCanvasEffectPropertyOnSemiAutoPropertyAnalyzer : Diagnost
|
||||
{
|
||||
if (pair.Value is [1, 1 or 2])
|
||||
{
|
||||
// Shift back the index to match the actual enum values, to simplify the code fixer. Here we're adding 1 to
|
||||
// signal "the setter is valid", but we want to hide this implementation detail to downstream consumers.
|
||||
int invalidationType = pair.Value[1] - 1;
|
||||
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
UseCanvasEffectPropertyOnSemiAutoProperty,
|
||||
UseGeneratedCanvasEffectPropertyOnSemiAutoProperty,
|
||||
pair.Key.Locations.FirstOrDefault(),
|
||||
ImmutableDictionary.Create<string, string?>().Add(InvalidationModePropertyName, pair.Value[1].ToString()),
|
||||
ImmutableDictionary.Create<string, string?>().Add(InvalidationModePropertyName, invalidationType.ToString()),
|
||||
pair.Key));
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,9 @@ internal static class DiagnosticDescriptors
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The diagnostic id for <see cref="UseCanvasEffectPropertyOnSemiAutoProperty"/>.
|
||||
/// The diagnostic id for <see cref="UseGeneratedCanvasEffectPropertyOnSemiAutoProperty"/>.
|
||||
/// </summary>
|
||||
public const string UseCanvasEffectPropertyOnSemiAutoPropertyId = $"{DiagnosticIdPrefix}0008";
|
||||
public const string UseGeneratedCanvasEffectPropertyOnSemiAutoPropertyId = $"{DiagnosticIdPrefix}0008";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid CanvasEffect property.
|
||||
@@ -149,18 +149,18 @@ internal static class DiagnosticDescriptors
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when a semi-auto property can be converted to use <c>[CanvasEffectProperty]</c> instead.
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when a semi-auto property can be converted to use <c>[GeneratedCanvasEffectProperty]</c> instead.
|
||||
/// <para>
|
||||
/// Format: <c>"The semi-auto property "{0}" can be converted to a partial property using [CanvasEffectProperty], which is recommended (doing so makes the code less verbose and results in more optimized code)"</c>.
|
||||
/// Format: <c>"The semi-auto property "{0}" can be converted to a partial property using [GeneratedCanvasEffectProperty], which is recommended (doing so makes the code less verbose and results in more optimized code)"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor UseCanvasEffectPropertyOnSemiAutoProperty = new(
|
||||
id: UseCanvasEffectPropertyOnSemiAutoPropertyId,
|
||||
title: "Prefer using [CanvasEffectProperty] over semi-auto properties",
|
||||
messageFormat: """The semi-auto property "{0}" can be converted to a partial property using [CanvasEffectProperty], which is recommended (doing so makes the code less verbose and results in more optimized code)""",
|
||||
public static readonly DiagnosticDescriptor UseGeneratedCanvasEffectPropertyOnSemiAutoProperty = new(
|
||||
id: UseGeneratedCanvasEffectPropertyOnSemiAutoPropertyId,
|
||||
title: "Prefer using [GeneratedCanvasEffectProperty] over semi-auto properties",
|
||||
messageFormat: """The semi-auto property "{0}" can be converted to a partial property using [GeneratedCanvasEffectProperty], which is recommended (doing so makes the code less verbose and results in more optimized code)""",
|
||||
category: DiagnosticCategory,
|
||||
defaultSeverity: DiagnosticSeverity.Info,
|
||||
isEnabledByDefault: true,
|
||||
description: "Semi-auto properties should be converted to partial properties using [CanvasEffectProperty] when possible, which is recommended (doing so makes the code less verbose and results in more optimized code).",
|
||||
description: "Semi-auto properties should be converted to partial properties using [GeneratedCanvasEffectProperty] when possible, which is recommended (doing so makes the code less verbose and results in more optimized code).",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする