Browse Source

Cleanup attributes

Enable rules CA1018: Mark attributes with AttributeUsageAttribute; CA1813: Avoid unsealed attributes
pull/10169/head
Dmitry Zhelnin 3 years ago
committed by DmitryZhelnin
parent
commit
69b3db42a2
  1. 4
      .editorconfig
  2. 4
      src/Avalonia.Base/Metadata/AmbientAttribute.cs
  3. 2
      src/Avalonia.Base/Metadata/ContentAttribute.cs
  4. 4
      src/Avalonia.Base/Metadata/DataTypeAttribute.cs
  5. 2
      src/Avalonia.Base/Metadata/DependsOnAttribute.cs
  6. 2
      src/Avalonia.Base/Metadata/NotClientImplementableAttribute.cs
  7. 2
      src/Avalonia.Base/Metadata/TemplateContent.cs
  8. 2
      src/Avalonia.Base/Metadata/TrimSurroundingWhitespaceAttribute.cs
  9. 3
      src/Avalonia.Base/Metadata/UnstableAttribute.cs
  10. 4
      src/Avalonia.Base/Metadata/UsableDuringInitializationAttribute.cs
  11. 2
      src/Avalonia.Base/Metadata/WhitespaceSignificantCollectionAttribute.cs
  12. 2
      src/Avalonia.Base/Metadata/XmlnsDefinitionAttribute.cs
  13. 3
      src/Avalonia.Base/Rendering/Composition/Expressions/Expression.cs
  14. 2
      src/Avalonia.Controls/Platform/ExportAvaloniaModuleAttribute.cs
  15. 3
      src/Avalonia.Controls/ResolveByNameAttribute.cs
  16. 4
      src/Avalonia.OpenGL/GlEntryPointAttribute.cs
  17. 2
      src/Avalonia.Remote.Protocol/AvaloniaRemoteMessageGuidAttribute.cs
  18. 3
      src/Markup/Avalonia.Markup.Xaml/XamlTypes.cs
  19. 3
      src/Shared/ModuleInitializer.cs
  20. 11
      src/Shared/SourceGeneratorAttributes.cs

4
.editorconfig

@ -145,10 +145,14 @@ dotnet_diagnostic.CS1591.severity = suggestion
# CS0162: Remove unreachable code # CS0162: Remove unreachable code
dotnet_diagnostic.CS0162.severity = error dotnet_diagnostic.CS0162.severity = error
# CA1018: Mark attributes with AttributeUsageAttribute
dotnet_diagnostic.CA1018.severity = error
# CA1304: Specify CultureInfo # CA1304: Specify CultureInfo
dotnet_diagnostic.CA1304.severity = warning dotnet_diagnostic.CA1304.severity = warning
# CA1802: Use literals where appropriate # CA1802: Use literals where appropriate
dotnet_diagnostic.CA1802.severity = warning dotnet_diagnostic.CA1802.severity = warning
# CA1813: Avoid unsealed attributes
dotnet_diagnostic.CA1813.severity = error
# CA1815: Override equals and operator equals on value types # CA1815: Override equals and operator equals on value types
dotnet_diagnostic.CA1815.severity = warning dotnet_diagnostic.CA1815.severity = warning
# CA1820: Test for empty strings using string length # CA1820: Test for empty strings using string length

4
src/Avalonia.Base/Metadata/AmbientAttribute.cs

@ -3,10 +3,10 @@ using System;
namespace Avalonia.Metadata namespace Avalonia.Metadata
{ {
/// <summary> /// <summary>
/// Defines the ambient class/property /// Defines the ambient class/property
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, Inherited = true)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, Inherited = true)]
public class AmbientAttribute : Attribute public sealed class AmbientAttribute : Attribute
{ {
} }
} }

2
src/Avalonia.Base/Metadata/ContentAttribute.cs

@ -6,7 +6,7 @@ namespace Avalonia.Metadata
/// Defines the property that contains the object's content in markup. /// Defines the property that contains the object's content in markup.
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class ContentAttribute : Attribute public sealed class ContentAttribute : Attribute
{ {
} }
} }

4
src/Avalonia.Base/Metadata/DataTypeAttribute.cs

@ -9,7 +9,7 @@ namespace Avalonia.Metadata;
/// Used on DataTemplate.DataType property so it can be inherited in compiled bindings inside of the template. /// Used on DataTemplate.DataType property so it can be inherited in compiled bindings inside of the template.
/// </remarks> /// </remarks>
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class DataTypeAttribute : Attribute public sealed class DataTypeAttribute : Attribute
{ {
} }

2
src/Avalonia.Base/Metadata/DependsOnAttribute.cs

@ -6,7 +6,7 @@ namespace Avalonia.Metadata
/// Indicates that the property depends on the value of another property in markup. /// Indicates that the property depends on the value of another property in markup.
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class DependsOnAttribute : Attribute public sealed class DependsOnAttribute : Attribute
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DependsOnAttribute"/> class. /// Initializes a new instance of the <see cref="DependsOnAttribute"/> class.

2
src/Avalonia.Base/Metadata/NotClientImplementableAttribute.cs

@ -11,7 +11,7 @@ namespace Avalonia.Metadata
/// may be added to its API. /// may be added to its API.
/// </remarks> /// </remarks>
[AttributeUsage(AttributeTargets.Interface)] [AttributeUsage(AttributeTargets.Interface)]
public class NotClientImplementableAttribute : Attribute public sealed class NotClientImplementableAttribute : Attribute
{ {
} }
} }

2
src/Avalonia.Base/Metadata/TemplateContent.cs

@ -6,7 +6,7 @@ namespace Avalonia.Metadata
/// Defines the property that contains the object's content in markup. /// Defines the property that contains the object's content in markup.
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class TemplateContentAttribute : Attribute public sealed class TemplateContentAttribute : Attribute
{ {
public Type? TemplateResultType { get; set; } public Type? TemplateResultType { get; set; }
} }

2
src/Avalonia.Base/Metadata/TrimSurroundingWhitespaceAttribute.cs

@ -3,7 +3,7 @@
namespace Avalonia.Metadata namespace Avalonia.Metadata
{ {
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class TrimSurroundingWhitespaceAttribute : Attribute public sealed class TrimSurroundingWhitespaceAttribute : Attribute
{ {
} }

3
src/Avalonia.Base/Metadata/UnstableAttribute.cs

@ -6,7 +6,8 @@ namespace Avalonia.Metadata
/// This API is unstable and is not covered by API compatibility guarantees between minor and /// This API is unstable and is not covered by API compatibility guarantees between minor and
/// patch releases. /// patch releases.
/// </summary> /// </summary>
public class UnstableAttribute : Attribute [AttributeUsage(AttributeTargets.All)]
public sealed class UnstableAttribute : Attribute
{ {
} }
} }

4
src/Avalonia.Base/Metadata/UsableDuringInitializationAttribute.cs

@ -3,8 +3,8 @@ using System;
namespace Avalonia.Metadata namespace Avalonia.Metadata
{ {
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class)]
public class UsableDuringInitializationAttribute : Attribute public sealed class UsableDuringInitializationAttribute : Attribute
{ {
} }
} }

2
src/Avalonia.Base/Metadata/WhitespaceSignificantCollectionAttribute.cs

@ -6,7 +6,7 @@ namespace Avalonia.Metadata
/// Indicates that a collection type should be processed as being whitespace significant by a XAML processor. /// Indicates that a collection type should be processed as being whitespace significant by a XAML processor.
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class WhitespaceSignificantCollectionAttribute : Attribute public sealed class WhitespaceSignificantCollectionAttribute : Attribute
{ {
} }
} }

2
src/Avalonia.Base/Metadata/XmlnsDefinitionAttribute.cs

@ -6,7 +6,7 @@ namespace Avalonia.Metadata
/// Maps an XML namespace to a CLR namespace for use in XAML. /// Maps an XML namespace to a CLR namespace for use in XAML.
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class XmlnsDefinitionAttribute : Attribute public sealed class XmlnsDefinitionAttribute : Attribute
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="XmlnsDefinitionAttribute"/> class. /// Initializes a new instance of the <see cref="XmlnsDefinitionAttribute"/> class.

3
src/Avalonia.Base/Rendering/Composition/Expressions/Expression.cs

@ -39,7 +39,8 @@ namespace Avalonia.Rendering.Composition.Expressions
} }
} }
internal class PrettyPrintStringAttribute : Attribute [AttributeUsage(AttributeTargets.Field)]
internal sealed class PrettyPrintStringAttribute : Attribute
{ {
public string Name { get; } public string Name { get; }

2
src/Avalonia.Controls/Platform/ExportAvaloniaModuleAttribute.cs

@ -41,7 +41,7 @@ namespace Avalonia.Platform
/// The fallback module will only be initialized if the Skia-specific module is not applicable. /// The fallback module will only be initialized if the Skia-specific module is not applicable.
/// </remarks> /// </remarks>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class ExportAvaloniaModuleAttribute : Attribute public sealed class ExportAvaloniaModuleAttribute : Attribute
{ {
public ExportAvaloniaModuleAttribute(string name, Type moduleType) public ExportAvaloniaModuleAttribute(string name, Type moduleType)
{ {

3
src/Avalonia.Controls/ResolveByNameAttribute.cs

@ -7,7 +7,8 @@ namespace Avalonia.Controls
/// When applying this to attached properties, ensure to put on both /// When applying this to attached properties, ensure to put on both
/// the Getter and Setter methods. /// the Getter and Setter methods.
/// </summary> /// </summary>
public class ResolveByNameAttribute : Attribute [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
public sealed class ResolveByNameAttribute : Attribute
{ {
} }
} }

4
src/Avalonia.OpenGL/GlEntryPointAttribute.cs

@ -3,7 +3,7 @@ using System;
namespace Avalonia.OpenGL namespace Avalonia.OpenGL
{ {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
class GlMinVersionEntryPoint : Attribute sealed class GlMinVersionEntryPoint : Attribute
{ {
public GlMinVersionEntryPoint(string entry, int minVersionMajor, int minVersionMinor) public GlMinVersionEntryPoint(string entry, int minVersionMajor, int minVersionMinor)
{ {
@ -28,7 +28,7 @@ namespace Avalonia.OpenGL
} }
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
class GlExtensionEntryPoint : Attribute sealed class GlExtensionEntryPoint : Attribute
{ {
public GlExtensionEntryPoint(string entry, string extension) public GlExtensionEntryPoint(string entry, string extension)
{ {

2
src/Avalonia.Remote.Protocol/AvaloniaRemoteMessageGuidAttribute.cs

@ -3,7 +3,7 @@
namespace Avalonia.Remote.Protocol namespace Avalonia.Remote.Protocol
{ {
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class)]
public class AvaloniaRemoteMessageGuidAttribute : Attribute public sealed class AvaloniaRemoteMessageGuidAttribute : Attribute
{ {
public Guid Guid { get; } public Guid Guid { get; }

3
src/Markup/Avalonia.Markup.Xaml/XamlTypes.cs

@ -34,7 +34,8 @@ namespace Avalonia.Markup.Xaml
} }
public class ConstructorArgumentAttribute : Attribute [AttributeUsage(AttributeTargets.Property)]
public sealed class ConstructorArgumentAttribute : Attribute
{ {
public ConstructorArgumentAttribute(string name) public ConstructorArgumentAttribute(string name)
{ {

3
src/Shared/ModuleInitializer.cs

@ -1,7 +1,8 @@
namespace System.Runtime.CompilerServices namespace System.Runtime.CompilerServices
{ {
#if NETSTANDARD2_0 #if NETSTANDARD2_0
internal class ModuleInitializerAttribute : Attribute [AttributeUsage(AttributeTargets.Method)]
internal sealed class ModuleInitializerAttribute : Attribute
{ {
} }

11
src/Shared/SourceGeneratorAttributes.cs

@ -16,7 +16,9 @@ namespace Avalonia.SourceGenerator
} }
internal class GetProcAddressAttribute : Attribute
[AttributeUsage(AttributeTargets.Method)]
internal sealed class GetProcAddressAttribute : Attribute
{ {
public GetProcAddressAttribute(string proc) public GetProcAddressAttribute(string proc)
{ {
@ -39,11 +41,14 @@ namespace Avalonia.SourceGenerator
} }
} }
internal class GenerateEnumValueDictionaryAttribute : Attribute [AttributeUsage(AttributeTargets.Method)]
internal sealed class GenerateEnumValueDictionaryAttribute : Attribute
{ {
} }
internal class GenerateEnumValueListAttribute : Attribute
[AttributeUsage(AttributeTargets.Method)]
internal sealed class GenerateEnumValueListAttribute : Attribute
{ {
} }
} }

Loading…
Cancel
Save