You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BREAKING CHANGE: this was prevent legit use of custom properties to
override children:
```css
.root {
position: relative;
--SomeChild-width: 960px;
}
```
Instead we now just care about "API declarations"
@@ -32,32 +32,26 @@ Stylelint plugin that validates CSS custom properties in CSS modules to ensure t
32
32
33
33
## Why?
34
34
35
-
When working with CSS modules, it's common to use custom properties that are scoped to a specific component. This plugin enforces a naming convention where custom properties must be prefixed with the component name derived from the CSS module filename.
35
+
When working with CSS modules, components often expose custom properties as a public API that can be overridden by parent components. This plugin validates that these **public**custom properties follow a consistent naming convention based on the component name.
36
36
37
-
For example, if your CSS module is named `Button.module.css`, all custom properties should be prefixed with `--Button-`:
38
-
39
-
```css
40
-
.button {
41
-
--Button-primary-color: #007bff;
42
-
--Button-padding: 0.5rem1rem;
43
-
}
44
-
```
45
-
46
-
The validation is also applied to declaring custom properties with a fallback as this is seen as providing an API that is designed to be overridden:
37
+
For example, if your CSS module is named `Button.module.css`:
-**Consistency**: All custom properties follow the same naming pattern
59
-
-**Clarity**: It's immediately clear which component a custom property belongs to
60
-
-**Avoiding conflicts**: Prevents naming collisions when components are nested or used together, since CSS custom properties inherit through the DOM tree
51
+
-**Consistency**: All public custom properties follow the same naming pattern
52
+
-**Clarity**: It's immediately clear which properties are part of the component's public API
53
+
-**Avoiding conflicts**: Prevents naming collisions when components are nested
54
+
-**API documentation**: Fallback values serve as default values and documentation
61
55
62
56
## Installation
63
57
@@ -151,25 +145,15 @@ Use your own regular expression for suffix validation:
151
145
The plugin:
152
146
153
147
-**Only applies to CSS modules** - files ending with `.module.css`
154
-
-**Validates custom properties** - ensures they start with `--ComponentName-`
155
-
-**Autofix** - can automatically correct invalid prefixes
148
+
-**Validates public API custom properties** - ensures they start with `--ComponentName-`
149
+
-**Ignores private custom properties** - allows any naming for internal use
150
+
-**Autofix** - can automatically correct invalid prefixes in API declarations
156
151
157
152
### What gets validated
158
153
159
-
The plugin validates custom properties in two specific scenarios:
160
-
161
-
#### Direct assignments
162
-
163
-
Direct custom property usage is always validated:
154
+
The plugin validates custom properties only when they're used as **public API declarations**.
164
155
165
-
```css
166
-
:root {
167
-
--Button-color: red;
168
-
--Button-padding: 1rem;
169
-
}
170
-
```
171
-
172
-
#### Fallback declarations
156
+
#### API declarations (validated)
173
157
174
158
Custom properties used in `var()` functions **with fallback values** are treated as component API declarations:
175
159
@@ -180,22 +164,20 @@ Custom properties used in `var()` functions **with fallback values** are treated
180
164
}
181
165
```
182
166
183
-
This usage allows a user to override the custom properties from a parent
184
-
component
167
+
#### Private properties (ignored)
168
+
169
+
Direct custom property assignments are considered private implementation details:
185
170
186
171
```css
187
-
/* parent component can override `Button` spacing */
188
-
.parent {
189
-
--Button-spacing: 2rem;
190
-
--Button-max-width: 400px;
172
+
.button {
173
+
--internal-state: hover;
174
+
--computed-size: calc(100%-2rem);
191
175
}
192
176
```
193
177
194
-
This distinction ensures the plugin only validates properties that are being "declared" as part of the component's API, rather than properties being consumed from elsewhere.
178
+
#### Property consumption (ignored)
195
179
196
-
#### What's ignored
197
-
198
-
Custom properties used without fallbacks are considered consumption of existing properties and are ignored:
180
+
Custom properties used without fallbacks are considered consumption of existing properties:
199
181
200
182
```css
201
183
.button {
@@ -212,20 +194,23 @@ Custom properties used without fallbacks are considered consumption of existing
0 commit comments