|
81 | 81 | } |
82 | 82 |
|
83 | 83 | @mixin generate-utility($utility, $infix: "") { |
| 84 | + // Validate required keys |
| 85 | + @if not map.has-key($utility, property) { |
| 86 | + @error "Utility is missing required `property` key: #{$utility}"; |
| 87 | + } |
| 88 | + @if not map.has-key($utility, values) { |
| 89 | + @error "Utility is missing required `values` key: #{$utility}"; |
| 90 | + } |
| 91 | + |
| 92 | + // Warn on unknown keys (likely typos) |
| 93 | + $valid-keys: property, values, class, selector, responsive, print, important, state, variables; |
| 94 | + @each $key in map.keys($utility) { |
| 95 | + @if not list.index($valid-keys, $key) { |
| 96 | + @warn "Unknown utility key `#{$key}` found. Valid keys are: #{$valid-keys}"; |
| 97 | + } |
| 98 | + } |
| 99 | + |
84 | 100 | // Determine if we're generating a class, or an attribute selector |
85 | 101 | $selectorType: "class"; |
86 | 102 | @if map.has-key($utility, selector) { |
87 | 103 | $selectorType: map.get($utility, selector); |
| 104 | + // Validate selector type |
| 105 | + $valid-selectors: "class", "attr-starts", "attr-includes"; |
| 106 | + @if not list.index($valid-selectors, $selectorType) { |
| 107 | + @error "Invalid `selector` value `#{$selectorType}`. Must be one of: #{$valid-selectors}"; |
| 108 | + } |
88 | 109 | } |
89 | 110 | // Then get the class name to use in a class (e.g., .class) or in a attribute selector (e.g., [class^="class"]) |
90 | 111 | $selectorClass: map.get($utility, class); |
91 | 112 |
|
| 113 | + // Attribute selectors require a `class` key |
| 114 | + @if $selectorType != "class" and not map.has-key($utility, class) { |
| 115 | + @error "Utility with `selector: #{$selectorType}` requires a `class` key."; |
| 116 | + } |
| 117 | + |
92 | 118 | // Get the list or map of values and ensure it's a map |
93 | 119 | $values: map.get($utility, values); |
94 | 120 | @if meta.type-of($values) != "map" { |
|
0 commit comments