Skip to content

Commit 4441dd6

Browse files
committed
next level of checks
1 parent 78b26b0 commit 4441dd6

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

scss/mixins/_utilities.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,40 @@
8181
}
8282

8383
@mixin generate-utility($utility, $infix: "") {
84+
// Validate required keys
8485
@if not map.has-key($utility, property) {
8586
@error "Utility is missing required `property` key: #{$utility}";
8687
}
8788
@if not map.has-key($utility, values) {
8889
@error "Utility is missing required `values` key: #{$utility}";
8990
}
9091

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+
91100
// Determine if we're generating a class, or an attribute selector
92101
$selectorType: "class";
93102
@if map.has-key($utility, selector) {
94103
$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+
}
95109
}
96110
// Then get the class name to use in a class (e.g., .class) or in a attribute selector (e.g., [class^="class"])
97111
$selectorClass: map.get($utility, class);
98112

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+
99118
// Get the list or map of values and ensure it's a map
100119
$values: map.get($utility, values);
101120
@if meta.type-of($values) != "map" {

0 commit comments

Comments
 (0)