Skip to content

Commit 29b102d

Browse files
committed
More code styling changes for the generated interfaces
1 parent 00949b5 commit 29b102d

File tree

53 files changed

+752
-649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+752
-649
lines changed

src/PublicInterfaceGenerator/AttributeGenerationHelper.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ public static string GenerateAttributesCode()
1212
_ = builder.AppendLine($"#nullable enable");
1313
_ = builder.AppendLine(GenerateAttributionsSuppressComments());
1414

15-
_ = builder.AppendLine(GenerateEmbeddedAttribute());
15+
//Another line to separate code from rules
1616
_ = builder.AppendLine();
17-
_ = builder.AppendLine(GenerateExcludeFromGeneratedInterfaceAttribute());
17+
18+
_ = builder.AppendLine(GenerateEmbeddedAttribute());
1819
_ = builder.AppendLine();
19-
_ = builder.AppendLine(GenerateGenerateInterfaceAttribute());
20+
_ = builder.AppendLine(GenerateInterfaceAttributes());
2021

22+
//Another line to separate code from rules
23+
_ = builder.AppendLine();
24+
2125
_ = builder.Append(GenerateAttributionsSuppressionRestoreComments());
2226

2327
return builder.ToString();
@@ -41,63 +45,57 @@ internal sealed class EmbeddedAttribute : System.Attribute {}
4145
""";
4246
}
4347

44-
public static string GenerateExcludeFromGeneratedInterfaceAttribute()
48+
public static string GenerateInterfaceAttributes()
4549
{
4650
return
4751
"""
4852
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
4953
{
5054
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
51-
[Microsoft.CodeAnalysis.EmbeddedAttribute, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
55+
[Microsoft.CodeAnalysis.EmbeddedAttribute]
56+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
5257
public sealed class ExcludeFromGeneratedInterfaceAttribute : System.Attribute
5358
{
5459
}
55-
}
56-
""";
57-
}
5860
59-
public static string GenerateGenerateInterfaceAttribute()
60-
{
61-
return """
62-
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
63-
{
6461
[System.AttributeUsage(System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
65-
[Microsoft.CodeAnalysis.EmbeddedAttribute, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
62+
[Microsoft.CodeAnalysis.EmbeddedAttribute]
63+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
6664
public sealed class GenerateInterfaceAttribute : System.Attribute
6765
{
6866
/// <summary>
6967
/// Set this to override the default interface name. Or leave it null to use the class name with an 'I' prepended to it.
7068
/// </summary>
7169
public string? InterfaceName { get; set; }
72-
70+
7371
/// <summary>
7472
/// Set this to override the namespace to generate the interface in. By default, it will be the same as the class.
7573
/// </summary>
7674
public string? Namespace { get; set; }
77-
75+
7876
/// <summary>
79-
/// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
77+
/// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
8078
/// This should be a syntax-valid list as you would type it out normally because it will be concatenated directly into the interface definition.
8179
/// For example: ""MyNamespace.MyInterface1, MyNamespace.MyInterface2""
8280
/// </summary>
8381
public string? Interfaces { get; set; }
84-
82+
8583
/// <summary>
8684
/// Set this to specify the generated interface inherits from System.IDisposable.
8785
/// This will be appended to the list of interfaces the generated interface inherits from.
8886
/// This is in addition to the <see cref="Interfaces"/> property.
89-
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
90-
/// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
87+
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
88+
/// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
9189
/// or set this to true and don't include "System.IDisposable" in the <see cref="Interfaces"/> string.
9290
/// Failure to do this will result in System.IDisposable being appended to the generated interface twice.
9391
/// </summary>
9492
public bool IsIDisposable { get; set; }
95-
93+
9694
/// <summary>
9795
/// Set this to specify the generated interface inherits from <see cref="System.IAsyncDisposable"/>.
9896
/// This is in addition to the <see cref="Interfaces"/> property.
99-
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
100-
/// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
97+
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
98+
/// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
10199
/// or set this to true and don't include "System.IAsyncDisposable" in the <see cref="Interfaces"/> string.
102100
/// Failure to do this will result in System.IAsyncDisposable being appended to the generated interface twice.
103101
/// </summary>
@@ -112,9 +110,9 @@ private static string GenerateAttributionsSuppressComments()
112110
return """
113111
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
114112
#pragma warning disable SA1402 // FileMayOnlyContainASingleType
113+
#pragma warning disable SA1403 // SA1403FileMayOnlyContainASingleNamespace
115114
#pragma warning disable SA1502 // ElementMustNotBeOnSingleLine
116-
#pragma warning disable SA1013 // ClosingBracesMustBeSpacedCorrectly
117-
115+
#pragma warning disable SA1013 // ClosingBracesMustBeSpacedCorrectly
118116
""";
119117
}
120118

@@ -123,6 +121,7 @@ private static string GenerateAttributionsSuppressionRestoreComments()
123121
return """
124122
#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName
125123
#pragma warning restore SA1402 // FileMayOnlyContainASingleType
124+
#pragma warning restore SA1403 // SA1403FileMayOnlyContainASingleNamespace
126125
#pragma warning restore SA1502 // ElementMustNotBeOnSingleLine
127126
#pragma warning restore SA1013 // ClosingBracesMustBeSpacedCorrectly
128127
""";

src/UnitTests/Snapshots/Events/EventsTests.ActionEvents_AssertResults#PublicInterfaceGeneratorAttributes.verified.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#nullable enable
33
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
44
#pragma warning disable SA1402 // FileMayOnlyContainASingleType
5+
#pragma warning disable SA1403 // SA1403FileMayOnlyContainASingleNamespace
56
#pragma warning disable SA1502 // ElementMustNotBeOnSingleLine
6-
#pragma warning disable SA1013 // ClosingBracesMustBeSpacedCorrectly
7-
7+
#pragma warning disable SA1013 // ClosingBracesMustBeSpacedCorrectly
8+
89
namespace Microsoft.CodeAnalysis
910
{
1011
[System.AttributeUsage(System.AttributeTargets.All)]
@@ -15,16 +16,15 @@ internal sealed class EmbeddedAttribute : System.Attribute {}
1516
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
1617
{
1718
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
18-
[Microsoft.CodeAnalysis.EmbeddedAttribute, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
19+
[Microsoft.CodeAnalysis.EmbeddedAttribute]
20+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
1921
public sealed class ExcludeFromGeneratedInterfaceAttribute : System.Attribute
2022
{
2123
}
22-
}
2324

24-
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
25-
{
2625
[System.AttributeUsage(System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
27-
[Microsoft.CodeAnalysis.EmbeddedAttribute, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
26+
[Microsoft.CodeAnalysis.EmbeddedAttribute]
27+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
2828
public sealed class GenerateInterfaceAttribute : System.Attribute
2929
{
3030
/// <summary>
@@ -38,7 +38,7 @@ public sealed class GenerateInterfaceAttribute : System.Attribute
3838
public string? Namespace { get; set; }
3939

4040
/// <summary>
41-
/// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
41+
/// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
4242
/// This should be a syntax-valid list as you would type it out normally because it will be concatenated directly into the interface definition.
4343
/// For example: ""MyNamespace.MyInterface1, MyNamespace.MyInterface2""
4444
/// </summary>
@@ -48,8 +48,8 @@ public sealed class GenerateInterfaceAttribute : System.Attribute
4848
/// Set this to specify the generated interface inherits from System.IDisposable.
4949
/// This will be appended to the list of interfaces the generated interface inherits from.
5050
/// This is in addition to the <see cref="Interfaces"/> property.
51-
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
52-
/// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
51+
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
52+
/// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
5353
/// or set this to true and don't include "System.IDisposable" in the <see cref="Interfaces"/> string.
5454
/// Failure to do this will result in System.IDisposable being appended to the generated interface twice.
5555
/// </summary>
@@ -58,15 +58,17 @@ public sealed class GenerateInterfaceAttribute : System.Attribute
5858
/// <summary>
5959
/// Set this to specify the generated interface inherits from <see cref="System.IAsyncDisposable"/>.
6060
/// This is in addition to the <see cref="Interfaces"/> property.
61-
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
62-
/// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
61+
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
62+
/// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
6363
/// or set this to true and don't include "System.IAsyncDisposable" in the <see cref="Interfaces"/> string.
6464
/// Failure to do this will result in System.IAsyncDisposable being appended to the generated interface twice.
6565
/// </summary>
6666
public bool IsIAsyncDisposable { get; set; }
6767
}
6868
}
69+
6970
#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName
7071
#pragma warning restore SA1402 // FileMayOnlyContainASingleType
72+
#pragma warning restore SA1403 // SA1403FileMayOnlyContainASingleNamespace
7173
#pragma warning restore SA1502 // ElementMustNotBeOnSingleLine
7274
#pragma warning restore SA1013 // ClosingBracesMustBeSpacedCorrectly

src/UnitTests/Snapshots/Events/EventsTests.CustomEvents_AssertResults#PublicInterfaceGeneratorAttributes.verified.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#nullable enable
33
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
44
#pragma warning disable SA1402 // FileMayOnlyContainASingleType
5+
#pragma warning disable SA1403 // SA1403FileMayOnlyContainASingleNamespace
56
#pragma warning disable SA1502 // ElementMustNotBeOnSingleLine
6-
#pragma warning disable SA1013 // ClosingBracesMustBeSpacedCorrectly
7-
7+
#pragma warning disable SA1013 // ClosingBracesMustBeSpacedCorrectly
8+
89
namespace Microsoft.CodeAnalysis
910
{
1011
[System.AttributeUsage(System.AttributeTargets.All)]
@@ -15,16 +16,15 @@ internal sealed class EmbeddedAttribute : System.Attribute {}
1516
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
1617
{
1718
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
18-
[Microsoft.CodeAnalysis.EmbeddedAttribute, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
19+
[Microsoft.CodeAnalysis.EmbeddedAttribute]
20+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
1921
public sealed class ExcludeFromGeneratedInterfaceAttribute : System.Attribute
2022
{
2123
}
22-
}
2324

24-
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
25-
{
2625
[System.AttributeUsage(System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
27-
[Microsoft.CodeAnalysis.EmbeddedAttribute, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
26+
[Microsoft.CodeAnalysis.EmbeddedAttribute]
27+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
2828
public sealed class GenerateInterfaceAttribute : System.Attribute
2929
{
3030
/// <summary>
@@ -38,7 +38,7 @@ public sealed class GenerateInterfaceAttribute : System.Attribute
3838
public string? Namespace { get; set; }
3939

4040
/// <summary>
41-
/// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
41+
/// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
4242
/// This should be a syntax-valid list as you would type it out normally because it will be concatenated directly into the interface definition.
4343
/// For example: ""MyNamespace.MyInterface1, MyNamespace.MyInterface2""
4444
/// </summary>
@@ -48,8 +48,8 @@ public sealed class GenerateInterfaceAttribute : System.Attribute
4848
/// Set this to specify the generated interface inherits from System.IDisposable.
4949
/// This will be appended to the list of interfaces the generated interface inherits from.
5050
/// This is in addition to the <see cref="Interfaces"/> property.
51-
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
52-
/// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
51+
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
52+
/// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
5353
/// or set this to true and don't include "System.IDisposable" in the <see cref="Interfaces"/> string.
5454
/// Failure to do this will result in System.IDisposable being appended to the generated interface twice.
5555
/// </summary>
@@ -58,15 +58,17 @@ public sealed class GenerateInterfaceAttribute : System.Attribute
5858
/// <summary>
5959
/// Set this to specify the generated interface inherits from <see cref="System.IAsyncDisposable"/>.
6060
/// This is in addition to the <see cref="Interfaces"/> property.
61-
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
62-
/// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
61+
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
62+
/// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
6363
/// or set this to true and don't include "System.IAsyncDisposable" in the <see cref="Interfaces"/> string.
6464
/// Failure to do this will result in System.IAsyncDisposable being appended to the generated interface twice.
6565
/// </summary>
6666
public bool IsIAsyncDisposable { get; set; }
6767
}
6868
}
69+
6970
#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName
7071
#pragma warning restore SA1402 // FileMayOnlyContainASingleType
72+
#pragma warning restore SA1403 // SA1403FileMayOnlyContainASingleNamespace
7173
#pragma warning restore SA1502 // ElementMustNotBeOnSingleLine
7274
#pragma warning restore SA1013 // ClosingBracesMustBeSpacedCorrectly

0 commit comments

Comments
 (0)