Skip to content

Commit

Permalink
Update validation check
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherZane committed Dec 22, 2023
1 parent a47336a commit 91e026a
Showing 1 changed file with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,15 @@ protected override void OnValidate()
{
Guard.IsBetweenOrEqualTo(defaultValues.Length, MinValues.GetValueOrDefault(Discord.Limits.Component.Selection.MinMinimumSelectedOptions), MaxValues.GetValueOrDefault(Discord.Limits.Component.Selection.MaxMaximumSelectedOptions));
switch (Type)
Predicate<DefaultValueJsonModel> predicate = Type switch

Check warning on line 148 in src/Disqord.Core/Models/Interactions/Components/ComponentJsonModel.cs

View workflow job for this annotation

GitHub Actions / build

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern 'Disqord.ComponentType.Row' is not covered.

Check warning on line 148 in src/Disqord.Core/Models/Interactions/Components/ComponentJsonModel.cs

View workflow job for this annotation

GitHub Actions / build

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern 'Disqord.ComponentType.Row' is not covered.
{
case ComponentType.UserSelection:
Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.User));
break;
case ComponentType.RoleSelection:
Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.Role));
break;
case ComponentType.MentionableSelection:
Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.User || x.Type == DefaultSelectionValueType.Role));
break;
case ComponentType.ChannelSelection:
Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.Channel));
break;
}
ComponentType.UserSelection => value => value.Type is DefaultSelectionValueType.User,
ComponentType.RoleSelection => value => value.Type is DefaultSelectionValueType.Role,
ComponentType.MentionableSelection => value => value.Type is DefaultSelectionValueType.User or DefaultSelectionValueType.Role,
ComponentType.ChannelSelection => value => value.Type is DefaultSelectionValueType.Channel,
};
Guard.IsTrue(Array.TrueForAll(defaultValues, predicate), message: "The types of default selection values must match the type of the component.");
});

break;
Expand Down

0 comments on commit 91e026a

Please sign in to comment.