@canonical/code-standards 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/data/css.ttl CHANGED
@@ -15,33 +15,36 @@ cs:CSSSelectorNamespace a cs:CodeStandard ;
15
15
  cs:name "css/selectors/namespace" ;
16
16
  cs:hasCategory cs:CSSCategory ;
17
17
  cs:description "All component selectors must be prefixed with the `.ds` namespace (e.g., `.ds.button`)." ;
18
- cs:dos """
19
- (Do) Prefix all component selectors with `.ds`.
20
- ```css
18
+ cs:do [
19
+ cs:description "Prefix all component selectors with `.ds`." ;
20
+ cs:language "css" ;
21
+ cs:code """
21
22
  /* Component root with namespace */
22
23
  .ds.button {
23
24
  /* Base styles */
24
25
  }
25
- ```
26
- """ ;
27
- cs:donts """
28
- (Don't) Omit the `.ds` namespace from component selectors.
29
- ```css
26
+ """
27
+ ] ;
28
+ cs:dont [
29
+ cs:description "Omit the `.ds` namespace from component selectors." ;
30
+ cs:language "css" ;
31
+ cs:code """
30
32
  /* Bad: Missing .ds namespace */
31
33
  .button {
32
34
  /* styles */
33
35
  }
34
- ```
35
- """ .
36
+ """
37
+ ] .
36
38
 
37
39
  # CSS Component Encapsulation Standard
38
40
  cs:CSSComponentEncapsulation a cs:CodeStandard ;
39
41
  cs:name "css/component/encapsulation" ;
40
42
  cs:hasCategory cs:CSSCategory ;
41
43
  cs:description "Component styles must be encapsulated using the component's root class as a boundary. All internal element styles must be scoped to the component's namespace." ;
42
- cs:dos """
43
- (Do) Scope internal element styles using the component's namespace.
44
- ```css
44
+ cs:do [
45
+ cs:description "Scope internal element styles using the component's namespace." ;
46
+ cs:language "css" ;
47
+ cs:code """
45
48
  .ds.button {
46
49
  /* Component root styles */
47
50
 
@@ -50,42 +53,45 @@ cs:CSSComponentEncapsulation a cs:CodeStandard ;
50
53
  margin-right: var(--button-icon-spacing);
51
54
  }
52
55
  }
53
- ```
54
- """ ;
55
- cs:donts """
56
- (Don't) Don't style internal elements without the component namespace.
57
- ```css
56
+ """
57
+ ] ;
58
+ cs:dont [
59
+ cs:description "Don't style internal elements without the component namespace." ;
60
+ cs:language "css" ;
61
+ cs:code """
58
62
  /* Bad: Internal element not scoped to component */
59
63
  .icon {
60
64
  margin-right: var(--button-icon-spacing);
61
65
  }
62
- ```
63
- """ .
66
+ """
67
+ ] .
64
68
 
65
69
  # CSS State Handling Standard
66
70
  cs:CSSStateHandling a cs:CodeStandard ;
67
71
  cs:name "css/component/states" ;
68
72
  cs:hasCategory cs:CSSCategory ;
69
73
  cs:description "Component states must be handled using attribute selectors for native states and class modifiers for custom states." ;
70
- cs:dos """
71
- (Do) Use attribute selectors for native element states.
72
- ```css
74
+ cs:do [
75
+ cs:description "Use attribute selectors for native element states." ;
76
+ cs:language "css" ;
77
+ cs:code """
73
78
  .ds.button {
74
79
  &[disabled] {
75
80
  opacity: var(--button-disabled-opacity);
76
81
  }
77
82
  }
78
- ```
79
- """ ;
80
- cs:donts """
81
- (Don't) Use class modifiers for native states.
82
- ```css
83
+ """
84
+ ] ;
85
+ cs:dont [
86
+ cs:description "Use class modifiers for native states." ;
87
+ cs:language "css" ;
88
+ cs:code """
83
89
  /* Bad: Using class for native state */
84
90
  .ds.button.disabled {
85
91
  opacity: var(--button-disabled-opacity);
86
92
  }
87
- ```
88
- """ .
93
+ """
94
+ ] .
89
95
 
90
96
  # CSS Specificity Management Standard
91
97
  cs:CSSSpecificityManagement a cs:CodeStandard ;
@@ -95,111 +101,123 @@ cs:CSSSpecificityManagement a cs:CodeStandard ;
95
101
  - Component root must use namespace + component name (.ds.button)
96
102
  - Single modifier class for variants (.ds.button.primary)
97
103
  - Single attribute for states (.ds.button[disabled])""" ;
98
- cs:dos """
99
- (Do) Use a single modifier class for component variants.
100
- ```css
104
+ cs:do [
105
+ cs:description "Use a single modifier class for component variants." ;
106
+ cs:language "css" ;
107
+ cs:code """
101
108
  .ds.button.primary {
102
109
  /* Variant: root + modifier (3 classes) */
103
110
  background: var(--button-primary-background);
104
111
  }
105
- ```
106
- """ ;
107
- cs:donts """
108
- (Don't) Combine multiple modifiers or mix states with variants.
109
- ```css
112
+ """
113
+ ] ;
114
+ cs:dont [
115
+ cs:description "Combine multiple modifiers or mix states with variants." ;
116
+ cs:language "css" ;
117
+ cs:code """
110
118
  /* Bad: Mixing variant with state */
111
119
  .ds.button.primary[disabled].large {
112
120
  /* Too specific: root + 2 modifiers + state */
113
121
  }
114
- ```
115
- """ .
122
+ """
123
+ ] .
116
124
 
117
125
  # CSS Selector Semantics Standard
118
126
  cs:CSSSelectorSemantics a cs:CodeStandard ;
119
127
  cs:name "css/selectors/semantics" ;
120
128
  cs:hasCategory cs:CSSCategory ;
121
129
  cs:description "CSS class names must describe the purpose or state of an element, not its appearance." ;
122
- cs:dos """
123
- (Do) Use semantic modifier classes to represent component variations.
124
- ```css
130
+ cs:do [
131
+ cs:description "Use semantic modifier classes to represent component variations." ;
132
+ cs:language "css" ;
133
+ cs:code """
125
134
  /* Semantic modifier for a primary button */
126
135
  .ds.button.primary {
127
136
  --modifier-color: var(--color-primary);
128
137
  }
129
- ```
130
- """ ;
131
- cs:donts """
132
- (Don't) Use non-semantic or presentational class names.
133
- ```css
138
+ """
139
+ ] ;
140
+ cs:dont [
141
+ cs:description "Use non-semantic or presentational class names." ;
142
+ cs:language "css" ;
143
+ cs:code """
134
144
  /* Bad: 'big' describes appearance, not purpose */
135
145
  .ds.button.big {
136
146
  padding: 1rem;
137
147
  }
138
- ```
139
- """ .
148
+ """
149
+ ] .
140
150
 
141
151
  # Theme Activation Standard
142
152
  cs:ThemeActivation a cs:CodeStandard ;
143
153
  cs:name "css/themes/activation" ;
144
154
  cs:hasCategory cs:CSSCategory ;
145
155
  cs:description """Theme tokens must be activated through CSS classes on container elements. See styling/themes/definition for theme token structure.""" ;
146
- cs:dos """
147
- (Do) Define semantic tokens within theme classes.
148
- ```css
156
+ cs:do [
157
+ cs:description "Define semantic tokens within theme classes." ;
158
+ cs:language "css" ;
159
+ cs:code """
149
160
  .canonical {
150
161
  --spacing-vertical-medium: var(--spacing-unit-2x);
151
162
  --color-background: var(--color-neutral-100);
152
163
  }
153
- ```
154
- """ ;
155
- cs:donts """
156
- (Don't) Hardcode theme names in component styles.
157
- ```css
164
+ """
165
+ ] ;
166
+ cs:dont [
167
+ cs:description "Hardcode theme names in component styles." ;
168
+ cs:language "css" ;
169
+ cs:code """
158
170
  /* Bad: Component locked to specific theme */
159
171
  .ds.button {
160
172
  padding: var(--canonical-spacing-vertical-medium);
161
173
  }
162
- ```
163
- """ .
174
+ """
175
+ ] .
164
176
 
165
177
  # CSS Property Values Standard
166
178
  cs:CSSPropertyValues a cs:CodeStandard ;
167
179
  cs:name "css/properties/values" ;
168
180
  cs:hasCategory cs:CSSCategory ;
169
181
  cs:description """CSS properties must use design tokens for design decisions (see styling/tokens/creation) and raw values for properties that are independent from design decisions, or "unthemable".""" ;
170
- cs:dos """
171
- (Do) Use design tokens for design decisions.
172
- ```css
182
+ cs:do [
183
+ cs:description "Use design tokens for design decisions." ;
184
+ cs:language "css" ;
185
+ cs:code """
173
186
  .ds.button {
174
187
  /* Design decision uses token */
175
188
  background: var(--button-background);
176
189
  }
177
- ```
178
- (Do) Use raw values for unthemable properties (independent of design decisions).
179
- ```css
190
+ """
191
+ ] ;
192
+ cs:do [
193
+ cs:description "Use raw values for unthemable properties (independent of design decisions)." ;
194
+ cs:language "css" ;
195
+ cs:code """
180
196
  .ds.skip-link {
181
197
  visibility: hidden;
182
198
  }
183
- ```
184
- """ ;
185
- cs:donts """
186
- (Don't) Use raw values for design decisions.
187
- ```css
199
+ """
200
+ ] ;
201
+ cs:dont [
202
+ cs:description "Use raw values for design decisions." ;
203
+ cs:language "css" ;
204
+ cs:code """
188
205
  .ds.button {
189
206
  /* Bad: Design decision using raw value */
190
207
  background: #0066CC;
191
208
  }
192
- ```
193
- """ .
209
+ """
210
+ ] .
194
211
 
195
212
  # Child Element Naming Standard
196
213
  cs:CSSChildElementNaming a cs:CodeStandard ;
197
214
  cs:name "css/selectors/child-elements" ;
198
215
  cs:hasCategory cs:CSSCategory ;
199
216
  cs:description """Child elements within components must use simple, role-based class names (e.g., `.header`, `.content`, `.icon`) scoped by the parent selector, NOT verbose prefixed names that repeat the component name.""" ;
200
- cs:dos """
201
- (Do) Use simple role-based class names scoped by the parent.
202
- ```css
217
+ cs:do [
218
+ cs:description "Use simple role-based class names scoped by the parent." ;
219
+ cs:language "css" ;
220
+ cs:code """
203
221
  .ds.accordion-item {
204
222
  & > .header {
205
223
  /* Header styles */
@@ -227,11 +245,12 @@ cs:CSSChildElementNaming a cs:CodeStandard ;
227
245
  /* Separator styles */
228
246
  }
229
247
  }
230
- ```
231
- """ ;
232
- cs:donts """
233
- (Don't) Use verbose prefixed class names that repeat the component name.
234
- ```css
248
+ """
249
+ ] ;
250
+ cs:dont [
251
+ cs:description "Use verbose prefixed class names that repeat the component name." ;
252
+ cs:language "css" ;
253
+ cs:code """
235
254
  /* Bad: Redundant component prefix in child class names */
236
255
  .ds.accordion-item .accordion-item-header {
237
256
  /* 'accordion-item-' prefix is redundant */
@@ -244,22 +263,22 @@ cs:CSSChildElementNaming a cs:CodeStandard ;
244
263
  .ds.timeline-event .timeline-event-marker {
245
264
  /* Verbose and BEM-like */
246
265
  }
247
- ```
248
- """ .
266
+ """
267
+ ] .
249
268
 
250
269
  # Component Naming Convention for CSS
251
270
  cs:CSSComponentNamingConvention a cs:CodeStandard ;
252
271
  cs:name "css/selectors/naming-convention" ;
253
272
  cs:hasCategory cs:CSSCategory ;
254
273
  cs:description "Component CSS class names must be the kebab-case version of the component's PascalCase name." ;
255
- cs:dos """
256
- (Do) Convert PascalCase component names to kebab-case for CSS classes:
274
+ cs:do [
275
+ cs:description "Convert PascalCase component names to kebab-case for CSS classes:
257
276
  - `MyComponent` -> `.ds.my-component`
258
277
  - `UserProfile` -> `.ds.user-profile`
259
- - `Button` -> `.ds.button`
260
- """ ;
261
- cs:donts """
262
- (Don't) Use PascalCase or other formats in CSS class names:
278
+ - `Button` -> `.ds.button`"
279
+ ] ;
280
+ cs:dont [
281
+ cs:description "Use PascalCase or other formats in CSS class names:
263
282
  - `.ds.MyComponent` (Bad: Not kebab-case)
264
- - `.ds.user_profile` (Bad: Not kebab-case)
265
- """ .
283
+ - `.ds.user_profile` (Bad: Not kebab-case)"
284
+ ] .