WPF code quality
ProprietaryCorrectness rules for WPF dependency properties, routed events, routed commands, value converters, markup extensions, template parts, styles and XML documentation, ported from the WpfAnalyzers Roslyn analyzers.
OpenRewrite. Recipes. CSharp. CodeQuality. Wpf. WpfCodeQualitymod run . --recipe= OpenRewrite. Recipes. CSharp. CodeQuality. Wpf. WpfCodeQualityInstall it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Backing member for a DependencyProperty should match registered name
- Backing member for a DependencyPropertyKey should match registered name
- CLR property for a DependencyProperty should match registered name
- CLR method for a DependencyProperty must match registered name
- Convert a trivial dependency property callback to a lambda
- Name the PropertyChangedCallback OnNameChanged
- Name the CoerceValueCallback CoerceName
- Name the ValidateValueCallback ValidateName
- Target of [DependsOn] should exist
- Default value type must match registered type
- Containing type should be used as registered owner
- CLR property type should match registered type
- CLR accessor for attached property must match registered type
- SetValue must use the registered type
- Registered owner type must inherit DependencyObject
- Default value is a shared reference type
- Metadata must be of the same type or a super type
- Use containing type
- Cast the sender of a dependency property callback to the correct type
- Cast the value of a dependency property callback to the correct type
- Cast the sender of a dependency property callback to the containing type
- Cast the value of a dependency property callback to the exact type
- Declare the coerce and validate callback value parameter nullable
- Backing member for a DependencyProperty should be static and readonly
- DependencyPropertyKey member must be declared before DependencyProperty member
- Use same dependency property in get and set
- Add [AttachedPropertyBrowsableForType]
- Use correct argument for [AttachedPropertyBrowsableForType]
- Use SetValue in setter
- Avoid side effects in CLR accessors
- Set a readonly DependencyProperty using its DependencyPropertyKey
- Set a mutable dependency property using SetCurrentValue
- Avoid side effects in attached property CLR accessors
- Do not set DataContext or Style using SetCurrentValue
- XmlnsPrefix must map to the same url as XmlnsDefinition
- XmlnsDefinition must map to an existing namespace
- XmlnsDefinitions should map all namespaces with public types
- Backing member for DependencyProperty should have standard documentation text
- Accessor method for attached property should have standard documentation text
- Property changed callback should have standard documentation text
- Add default field to converter
- Add ValueConversion attribute
- ValueConversion must use correct types
- Add ValueConversion attribute (unknown types)
- Use containing type
- Add MarkupExtensionReturnType attribute
- MarkupExtensionReturnType must use correct return type
- [ConstructorArgument] must match
- Add [ConstructorArgument]
- Target of [XamlSetMarkupExtension] should exist and have correct signature
- Target of [XamlSetTypeConverter] should exist and have correct signature
- Name the RegisterClassHandler callback OnEventName
- Name the AddHandler/RemoveHandler callback OnEventName
- Use the registered routed event handler type
- Backing member for a RoutedEvent should match registered name
- Containing type should be used as registered owner
- Name of the event should match registered name
- Use same event in add and remove
- Call AddHandler in add
- Call RemoveHandler in remove
- Use the registered handler type
- Backing member for a RoutedEvent should be static and readonly
- Backing member for RoutedEvent should have standard documentation text
- Register the containing member as the name for a RoutedCommand
- Register the containing type as the owner for a RoutedCommand
- Register a name and an owning type for a RoutedCommand
- Backing member for a RoutedCommand should be static and readonly
- Add [TemplatePart] for a looked-up template part
- Use the declared [TemplatePart] type
- Use the PART_ prefix for template part names
- ContentProperty should name an existing property
- Use the containing type when creating a ComponentResourceKey
- Use the containing member as the key when creating a ComponentResourceKey
- Use nameof() instead of a string literal
- Use nameof() instead of a constant
- StyleTypedProperty.Property must exist
- StyleTypedProperty.Property should name a Style property
- StyleTypedProperty.Property should be specified
- StyleTypedProperty.StyleTargetType should support styling
- StyleTypedProperty.StyleTargetType should be specified
- StyleTypedProperty.Property should be specified only once
- StyleTypedProperty should be specified for a Style property