Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't emit SPCH1002 if property has ColumnIgnore attribute #82

Merged
merged 1 commit into from
Nov 10, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,32 @@ public partial class MyGenRowContext : WorksheetRowContext;
// Act & Assert
return context.RunAsync();
}

[Fact]
public Task ColumnIgnore_IgnorePropertyOfUnsupportedType()
{
// Arrange
var context = AnalyzerTest.CreateContext();
context.TestCode = """
using SpreadCheetah.SourceGeneration;
using System;
using System.Diagnostics;

namespace MyNamespace;

public class ClassWithUnsupportedProperty
{
[ColumnIgnore] // SPCH1002 without this attribute
public Stopwatch? Stopwatch { get; set; }

public int Value { get; set; }
}

[WorksheetRow(typeof(ClassWithUnsupportedProperty))]
public partial class MyGenRowContext : WorksheetRowContext;
""";

// Act & Assert
return context.RunAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ public Task PropertyType_ClassWithUnsupportedProperty()

namespace MyNamespace;

public record RecordWithUnsupportedProperty(Uri HomepageUri);
public class ClassWithUnsupportedProperty
{
public System.Diagnostics.Stopwatch? Stopwatch { get; set; }
}

[WorksheetRow({|SPCH1002:typeof(RecordWithUnsupportedProperty)|})]
[WorksheetRow({|SPCH1002:typeof(ClassWithUnsupportedProperty)|})]
public partial class MyGenRowContext : WorksheetRowContext;
""";

Expand All @@ -36,10 +39,13 @@ public Task PropertyType_ClassWithUnsupportedPropertyAndWarningsSuppressed()
using System;

namespace MyNamespace;

public record RecordWithUnsupportedProperty(Uri HomepageUri);

[WorksheetRow(typeof(RecordWithUnsupportedProperty))]
public class ClassWithUnsupportedProperty
{
public System.Diagnostics.Stopwatch? Stopwatch { get; set; }
}

[WorksheetRow(typeof(ClassWithUnsupportedProperty))]
[WorksheetRowGenerationOptions(SuppressWarnings = true)]
public partial class MyGenRowContext : WorksheetRowContext;
""";
Expand Down
9 changes: 7 additions & 2 deletions SpreadCheetah.SourceGenerator/Extensions/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ private static bool TryGetInheritedColumnOrderingAttribute(this AttributeData at
return true;
}

public static AttributeData? GetCellValueConverterAttribute(this IPropertySymbol property)
public static bool HasCellValueConverterAttribute(this IPropertySymbol property)
{
return property.GetAttribute(Attributes.CellValueConverter);
return property.GetAttribute(Attributes.CellValueConverter) is not null;
}

public static bool HasColumnIgnoreAttribute(this IPropertySymbol property)
{
return property.GetAttribute(Attributes.ColumnIgnore) is not null;
}

public static AttributeData? GetColumnOrderAttribute(this IPropertySymbol property)
Expand Down
5 changes: 3 additions & 2 deletions SpreadCheetah.SourceGenerator/WorksheetRowAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ private static void AnalyzeContextType(SymbolAnalysisContext context)
{
hasProperties = true;

var cellValueConverter = property.GetCellValueConverterAttribute();
if (cellValueConverter is not null)
if (property.HasColumnIgnoreAttribute())
continue;
if (property.HasCellValueConverterAttribute())
continue;
if (property.Type.IsSupportedType())
continue;
Expand Down
Loading