WPF code quality
Recipe ID
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.WpfCodeQualityArtifactOpenRewrite.Recipes.CSharp.CodeQualityCorrectness 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.
Composite recipecsharpcode-qualityProprietary
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.WpfCodeQualityIf the recipe isn’t available locally, install it with:
mod config recipes nuget install OpenRewrite.Recipes.CSharp.CodeQualityDefinition
This recipe runs the following recipes in order.
- Backing member for a DependencyProperty should match registered name
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameDependencyPropertyBackingMember - Backing member for a DependencyPropertyKey should match registered name
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameDependencyPropertyKeyBackingMember - CLR property for a DependencyProperty should match registered name
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameClrPropertyToMatchRegisteredName - CLR method for a DependencyProperty must match registered name
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameClrAccessorMethodToMatchRegisteredName - Convert a trivial dependency property callback to a lambda
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.ConvertTrivialCallbackToLambda - Name the PropertyChangedCallback OnNameChanged
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenamePropertyChangedCallbackToMatchRegisteredName - Name the CoerceValueCallback CoerceName
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameCoerceValueCallbackToMatchRegisteredName - Name the ValidateValueCallback ValidateName
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameValidateValueCallbackToMatchRegisteredName - Target of [DependsOn] should exist
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindDependsOnTargetMissing - Default value type must match registered type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindDefaultValueTypeMismatch - Containing type should be used as registered owner
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseContainingTypeAsRegisteredOwner - CLR property type should match registered type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseRegisteredTypeForClrProperty - CLR accessor for attached property must match registered type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseRegisteredTypeForClrAccessorMethod - SetValue must use the registered type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindSetValueTypeMismatch - Registered owner type must inherit DependencyObject
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindRegisteredOwnerNotDependencyObject - Default value is a shared reference type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindSharedReferenceTypeDefaultValue - Metadata must be of the same type or a super type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindOverrideMetadataTypeMismatch - Use containing type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindDefaultStyleKeyOverrideMetadataArgument - Cast the sender of a dependency property callback to the correct type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.CastSenderToCorrectType - Cast the value of a dependency property callback to the correct type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.CastValueToCorrectType - Cast the sender of a dependency property callback to the containing type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.CastSenderToContainingType - Cast the value of a dependency property callback to the exact type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.CastValueToExactType - Declare the coerce and validate callback value parameter nullable
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.MakeCallbackParameterNullable - Backing member for a DependencyProperty should be static and readonly
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.MakeDependencyPropertyBackingMemberStaticReadonly - DependencyPropertyKey member must be declared before DependencyProperty member
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.DeclareDependencyPropertyKeyBeforeProperty - Use same dependency property in get and set
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequireSameDependencyPropertyInGetAndSet - Add [AttachedPropertyBrowsableForType]
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.AddAttachedPropertyBrowsableForTypeAttribute - Use correct argument for [AttachedPropertyBrowsableForType]
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseCorrectAttachedPropertyBrowsableForType - Use SetValue in setter
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseSetValueInClrPropertySetter - Avoid side effects in CLR accessors
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindSideEffectsInClrAccessors - Set a readonly DependencyProperty using its DependencyPropertyKey
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseDependencyPropertyKeyToSetValue - Set a mutable dependency property using SetCurrentValue
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseSetCurrentValueForMutableProperty - Avoid side effects in attached property CLR accessors
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindSideEffectsInAttachedPropertyAccessor - Do not set DataContext or Style using SetCurrentValue
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseSetValueForDataContextAndStyle - XmlnsPrefix must map to the same url as XmlnsDefinition
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindXmlnsPrefixDefinitionMismatch - XmlnsDefinition must map to an existing namespace
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindXmlnsDefinitionForMissingNamespace - XmlnsDefinitions should map all namespaces with public types
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.AddXmlnsDefinitionForUnmappedNamespaces - Backing member for DependencyProperty should have standard documentation text
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.DocumentDependencyPropertyBackingMember - Accessor method for attached property should have standard documentation text
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.DocumentAttachedPropertyAccessor - Property changed callback should have standard documentation text
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.DocumentPropertyChangedCallback - Add default field to converter
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.AddDefaultFieldToValueConverter - Add ValueConversion attribute
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.AddValueConversionAttribute - ValueConversion must use correct types
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseCorrectValueConversionTypes - Add ValueConversion attribute (unknown types)
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindValueConverterWithUnknownConversionTypes - Use containing type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseContainingTypeForConverterDefault - Add MarkupExtensionReturnType attribute
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.AddMarkupExtensionReturnTypeAttribute - MarkupExtensionReturnType must use correct return type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseCorrectMarkupExtensionReturnType - [ConstructorArgument] must match
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseCorrectConstructorArgumentName - Add [ConstructorArgument]
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.AddConstructorArgumentAttribute - Target of [XamlSetMarkupExtension] should exist and have correct signature
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.XamlSetMarkupExtensionTargetShouldExist - Target of [XamlSetTypeConverter] should exist and have correct signature
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.XamlSetTypeConverterTargetShouldExist - Name the RegisterClassHandler callback OnEventName
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameRegisterClassHandlerCallbackToMatchEvent - Name the AddHandler/RemoveHandler callback OnEventName
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameAddRemoveHandlerCallbackToMatchEvent - Use the registered routed event handler type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseRegisteredRoutedEventHandlerType - Backing member for a RoutedEvent should match registered name
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameRoutedEventBackingMember - Containing type should be used as registered owner
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RegisterContainingTypeAsRoutedEventOwner - Name of the event should match registered name
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RenameEventDeclarationToMatchRegisteredName - Use same event in add and remove
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindEventDeclarationAddRemoveMismatch - Call AddHandler in add
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindEventAddAccessorNotCallingAddHandler - Call RemoveHandler in remove
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindEventRemoveAccessorNotCallingRemoveHandler - Use the registered handler type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindEventDeclarationHandlerTypeMismatch - Backing member for a RoutedEvent should be static and readonly
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.MakeRoutedEventBackingMemberStaticReadonly - Backing member for RoutedEvent should have standard documentation text
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.DocumentRoutedEventBackingMember - Register the containing member as the name for a RoutedCommand
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseContainingMemberAsRoutedCommandName - Register the containing type as the owner for a RoutedCommand
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseContainingTypeAsRoutedCommandOwner - Register a name and an owning type for a RoutedCommand
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RegisterRoutedCommandNameAndOwner - Backing member for a RoutedCommand should be static and readonly
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.MakeRoutedCommandBackingMemberStaticReadonly - Add [TemplatePart] for a looked-up template part
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.AddTemplatePartAttribute - Use the declared [TemplatePart] type
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequireCorrectTemplatePartType - Use the PART_ prefix for template part names
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequirePartPrefixInTemplatePartName - ContentProperty should name an existing property
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindMissingContentPropertyTarget - Use the containing type when creating a ComponentResourceKey
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseContainingTypeForComponentResourceKey - Use the containing member as the key when creating a ComponentResourceKey
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseContainingMemberForComponentResourceKey - Use nameof() instead of a string literal
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseNameofInsteadOfLiteral - Use nameof() instead of a constant
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.UseNameofInsteadOfConstant - StyleTypedProperty.Property must exist
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequireExistingStyleTypedProperty - StyleTypedProperty.Property should name a Style property
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequireStyleTypedPropertyOfStyleType - StyleTypedProperty.Property should be specified
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequireStyleTypedPropertyProperty - StyleTypedProperty.StyleTargetType should support styling
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequireStyleTypedPropertyStyleTargetTypeToSupportStyle - StyleTypedProperty.StyleTargetType should be specified
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequireStyleTypedPropertyStyleTargetType - StyleTypedProperty.Property should be specified only once
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.RequireUniqueStyleTypedProperty - StyleTypedProperty should be specified for a Style property
OpenRewrite.Recipes.CSharp.CodeQuality.Wpf.FindMissingStyleTypedProperty