@@ -9,6 +9,7 @@ pub fn validate_node_fn(parsed: &ParsedNodeFn) -> syn::Result<()> {
9
9
// Add more validators here as needed
10
10
validate_implementations_for_generics,
11
11
validate_primary_input_expose,
12
+ validate_min_max,
12
13
] ;
13
14
14
15
for validator in validators {
@@ -18,6 +19,73 @@ pub fn validate_node_fn(parsed: &ParsedNodeFn) -> syn::Result<()> {
18
19
Ok ( ( ) )
19
20
}
20
21
22
+ fn validate_min_max ( parsed : & ParsedNodeFn ) {
23
+ for field in & parsed. fields {
24
+ match field {
25
+ ParsedField :: Regular {
26
+ number_hard_max,
27
+ number_hard_min,
28
+ number_soft_max,
29
+ number_soft_min,
30
+ pat_ident,
31
+ ..
32
+ } => {
33
+ match ( number_soft_min, number_hard_min) {
34
+ ( Some ( soft_min) , Some ( hard_min) ) => {
35
+ let soft_min_value: f64 = soft_min. base10_parse ( ) . unwrap_or_default ( ) ;
36
+ let hard_min_value: f64 = hard_min. base10_parse ( ) . unwrap_or_default ( ) ;
37
+ if soft_min_value == hard_min_value {
38
+ emit_error ! (
39
+ pat_ident. span( ) ,
40
+ "Unnecessary #[soft_min] attribute on `{}` as #[hard_min] equals to it." ,
41
+ pat_ident. ident;
42
+ help = "You can safely remove the #[soft_min] attribute from this field." ;
43
+ note = "The #[hard_min] also limits the range to same without #[soft_min]" ,
44
+ ) ;
45
+ } else if soft_min_value < hard_min_value {
46
+ emit_error ! (
47
+ pat_ident. span( ) ,
48
+ "The #[soft_min] attribute exists on `{}` and is lower than #[hard_min]." ,
49
+ pat_ident. ident;
50
+ help = "You probably meant to reverse the two macros" ;
51
+ note = "Allowing the possible range in slider to be more than #[hard_min] doesn't make sense" ,
52
+ ) ;
53
+ }
54
+ }
55
+ _ => ( ) ,
56
+ }
57
+
58
+ match ( number_soft_max, number_hard_max) {
59
+ ( Some ( soft_max) , Some ( hard_max) ) => {
60
+ let soft_max_value: f64 = soft_max. base10_parse ( ) . unwrap_or_default ( ) ;
61
+ let hard_max_value: f64 = hard_max. base10_parse ( ) . unwrap_or_default ( ) ;
62
+ if soft_max_value == hard_max_value {
63
+ emit_error ! (
64
+ pat_ident. span( ) ,
65
+ "Unnecessary #[soft_max] attribute on `{}` as #[hard_max] equals to it." ,
66
+ pat_ident. ident;
67
+ help = "You can safely remove the #[soft_max] attribute from this field." ;
68
+ note = "The #[hard_max] also limits the range to same without #[soft_max]" ,
69
+ ) ;
70
+ } else if soft_max_value < hard_max_value {
71
+ emit_error ! (
72
+ pat_ident. span( ) ,
73
+ "The #[soft_max] attribute exists on `{}` and is greater than #[hard_max]." ,
74
+ pat_ident. ident;
75
+ help = "You probably meant to reverse the two macros" ;
76
+ note = "Allowing the possible range in slider to be more than #[hard_max] doesn't make sense" ,
77
+ ) ;
78
+ }
79
+ }
80
+ _ => ( ) ,
81
+ }
82
+ }
83
+
84
+ _ => ( ) ,
85
+ }
86
+ }
87
+ }
88
+
21
89
fn validate_primary_input_expose ( parsed : & ParsedNodeFn ) {
22
90
if let Some ( ParsedField :: Regular { exposed : true , pat_ident, .. } ) = parsed. fields . first ( ) {
23
91
emit_error ! (
0 commit comments