@primer/stylelint-config 13.0.0-rc.99be5f2 → 13.0.0-rc.ad6cbda

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/stylelint-config",
3
- "version": "13.0.0-rc.99be5f2",
3
+ "version": "13.0.0-rc.ad6cbda",
4
4
  "description": "Sharable stylelint config used by GitHub's CSS",
5
5
  "author": "GitHub, Inc.",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "dependencies": {
46
46
  "@github/browserslist-config": "^1.0.0",
47
47
  "@primer/css": "^21.0.8",
48
- "@primer/primitives": "^7.17.1",
48
+ "@primer/primitives": "^8.2.0",
49
49
  "anymatch": "^3.1.1",
50
50
  "postcss-scss": "^4.0.2",
51
51
  "postcss-styled-syntax": "^0.6.4",
package/plugins/README.md CHANGED
@@ -13,7 +13,6 @@ This directory contains all of our custom stylelint plugins, each of which provi
13
13
  - [`primer/borders`](#primerborders)
14
14
  - [`primer/box-shadow`](#primerbox-shadow)
15
15
  - [`primer/responsive-widths`](#primerresponsive-widths)
16
- - [`primer/utilities`](#primerutilities)
17
16
  - [Variable rules](#variable-rules)
18
17
  - [Variable rule options](#variable-rule-options)
19
18
 
@@ -84,31 +83,6 @@ This [variable rule](#variable-rules) enforces the use of `$box-shadow*` variabl
84
83
 
85
84
  This plugin checks for `width` and `min-width` declarations that use a value less than the minimum browser size. `320px`
86
85
 
87
- ## `primer/utilities`
88
-
89
- Checks for selectors with single declarations that can be replaced with [primer/css utilities](https://primer.style/css/utilities/).
90
-
91
- ```scss
92
- .foo {
93
- color: var(--color-fg-default);
94
- }
95
- /** ↑
96
- * FAIL: --color-fg-default can be replaced with .color-fg-default */
97
-
98
- .foo {
99
- color: #custom;
100
- }
101
- /** ↑
102
- * OK: Color value doesn't match a utility. */
103
-
104
- .foo {
105
- color: var(--color-fg-default);
106
- padding: 0;
107
- }
108
- /** ↑
109
- * OK: Has more than one declaration, not considered */
110
- ```
111
-
112
86
  ## Variable rules
113
87
 
114
88
  Variable rules are created using a general-purpose helper that can validate constraints for matching CSS properties and values. In general, the Primer CSS variable rules enforce two basic principles for custom CSS:
@@ -19,8 +19,11 @@ export async function primitivesVariables(type) {
19
19
  for (const key of Object.keys(data)) {
20
20
  const size = data[key]
21
21
  const values = size['value']
22
- values.push(`${parseInt(size['original']['value']) + 1}px`)
23
- values.push(`${parseInt(size['original']['value']) - 1}px`)
22
+ const intValue = parseInt(size['original']['value'])
23
+ if (![2, 6].includes(intValue)) {
24
+ values.push(`${intValue + 1}px`)
25
+ values.push(`${intValue - 1}px`)
26
+ }
24
27
 
25
28
  variables.push({
26
29
  name: `--${size['name']}`,
@@ -1,526 +0,0 @@
1
- // Meant as temp until we can move to primitives or css
2
- const colorTypes = ['accent', 'success', 'attention', 'severe', 'danger', 'open', 'closed', 'done', 'sponsors']
3
-
4
- export default {
5
- color: [
6
- {
7
- value: 'var(--color-fg-default)',
8
- utilityClass: 'color-fg-default',
9
- },
10
- {
11
- value: 'var(--color-fg-muted)',
12
- utilityClass: 'color-fg-muted',
13
- },
14
- {
15
- value: 'var(--color-fg-subtle)',
16
- utilityClass: 'color-fg-subtle',
17
- },
18
- ].concat(
19
- colorTypes.map(type => {
20
- return {
21
- value: `var(--color-${type}-fg)`,
22
- utilityClass: `color-fg-${type}`,
23
- }
24
- }),
25
- ),
26
- 'background-color': [
27
- {
28
- value: 'var(--color-canvas-default)',
29
- utilityClass: 'color-bg-default',
30
- },
31
- {
32
- value: 'var(--color-canvas-overlay)',
33
- utilityClass: 'color-bg-overlay',
34
- },
35
- {
36
- value: 'var(--color-canvas-inset)',
37
- utilityClass: 'color-bg-inset',
38
- },
39
- {
40
- value: 'var(--color-canvas-subtle)',
41
- utilityClass: 'color-bg-subtle',
42
- },
43
- {
44
- value: 'transparent',
45
- utilityClass: 'color-bg-transparent',
46
- },
47
- ]
48
- .concat(
49
- colorTypes.map(type => {
50
- return {
51
- value: `var(--color-${type}-subtle)`,
52
- utilityClass: `color-bg-${type}`,
53
- }
54
- }),
55
- )
56
- .concat(
57
- colorTypes.map(type => {
58
- return {
59
- value: `var(--color-${type}-emphasis)`,
60
- utilityClass: `color-bg-${type}-emphasis`,
61
- }
62
- }),
63
- ),
64
- 'border-color': [
65
- {
66
- value: 'var(--color-border-default',
67
- utilityClass: 'color-border-default',
68
- },
69
- {
70
- value: 'var(--color-border-muted',
71
- utilityClass: 'color-border-muted',
72
- },
73
- {
74
- value: 'var(--color-border-subtle',
75
- utilityClass: 'color-border-subtle',
76
- },
77
- ]
78
- .concat(
79
- colorTypes.map(type => {
80
- return {
81
- value: `var(--color-${type}-muted)`,
82
- utilityClass: `color-border-${type}`,
83
- }
84
- }),
85
- )
86
- .concat(
87
- colorTypes.map(type => {
88
- return {
89
- value: `var(--color-${type}-emphasis)`,
90
- utilityClass: `color-border-${type}-emphasis`,
91
- }
92
- }),
93
- ),
94
- margin: Array.from(new Array(6)).map((_, i) => {
95
- return {
96
- value: `$spacer-${i + 1}`,
97
- utilityClass: `m-${i + 1}`,
98
- }
99
- }),
100
- 'margin-top': Array.from(new Array(6)).map((_, i) => {
101
- return {
102
- value: `$spacer-${i + 1}`,
103
- utilityClass: `mt-${i + 1}`,
104
- }
105
- }),
106
- 'margin-right': Array.from(new Array(6)).map((_, i) => {
107
- return {
108
- value: `$spacer-${i + 1}`,
109
- utilityClass: `mr-${i + 1}`,
110
- }
111
- }),
112
- 'margin-bottom': Array.from(new Array(6)).map((_, i) => {
113
- return {
114
- value: `$spacer-${i + 1}`,
115
- utilityClass: `mb-${i + 1}`,
116
- }
117
- }),
118
- 'margin-left': Array.from(new Array(6)).map((_, i) => {
119
- return {
120
- value: `$spacer-${i + 1}`,
121
- utilityClass: `ml-${i + 1}`,
122
- }
123
- }),
124
- padding: Array.from(new Array(6)).map((_, i) => {
125
- return {
126
- value: `$spacer-${i + 1}`,
127
- utilityClass: `p-${i + 1}`,
128
- }
129
- }),
130
- 'padding-top': Array.from(new Array(6)).map((_, i) => {
131
- return {
132
- value: `$spacer-${i + 1}`,
133
- utilityClass: `pt-${i + 1}`,
134
- }
135
- }),
136
- 'padding-right': Array.from(new Array(6)).map((_, i) => {
137
- return {
138
- value: `$spacer-${i + 1}`,
139
- utilityClass: `pr-${i + 1}`,
140
- }
141
- }),
142
- 'padding-bottom': Array.from(new Array(6)).map((_, i) => {
143
- return {
144
- value: `$spacer-${i + 1}`,
145
- utilityClass: `pb-${i + 1}`,
146
- }
147
- }),
148
- 'padding-left': Array.from(new Array(6)).map((_, i) => {
149
- return {
150
- value: `$spacer-${i + 1}`,
151
- utilityClass: `pl-${i + 1}`,
152
- }
153
- }),
154
- 'line-height': [
155
- {
156
- value: '$lh-condensed-ultra',
157
- utilityClass: 'lh-condensed-ultra',
158
- },
159
- {
160
- value: '$lh-condensed',
161
- utilityClass: 'lh-condensed',
162
- },
163
- {
164
- value: '$lh-default',
165
- utilityClass: 'lh-default',
166
- },
167
- {
168
- value: '0',
169
- utilityClass: 'lh-0',
170
- },
171
- ],
172
- 'text-align': [
173
- {
174
- value: 'left',
175
- utilityClass: 'text-left',
176
- },
177
- {
178
- value: 'right',
179
- utilityClass: 'text-right',
180
- },
181
- {
182
- value: 'center',
183
- utilityClass: 'text-center',
184
- },
185
- ],
186
- 'font-style': [
187
- {
188
- value: 'italic',
189
- utilityClass: 'text-italic',
190
- },
191
- ],
192
- 'text-transform': [
193
- {
194
- value: 'uppercase',
195
- utilityClass: 'text-uppercase',
196
- },
197
- ],
198
- 'text-decoration': [
199
- {
200
- value: 'underline',
201
- utilityClass: 'text-underline',
202
- },
203
- {
204
- value: 'none',
205
- utilityClass: 'no-underline',
206
- },
207
- ],
208
- 'white-space': [
209
- {
210
- value: 'nowrap',
211
- utilityClass: 'no-wrap',
212
- },
213
- {
214
- value: 'normal',
215
- utilityClass: 'ws-normal',
216
- },
217
- ],
218
- 'word-break': [
219
- {
220
- value: 'break-all',
221
- utilityClass: 'wb-break-all',
222
- },
223
- ],
224
- width: [
225
- {
226
- value: '100%',
227
- utilityClass: 'width-full',
228
- },
229
- {
230
- value: 'auto%',
231
- utilityClass: 'width-auto',
232
- },
233
- ],
234
- overflow: [
235
- {
236
- value: 'visible',
237
- utilityClass: 'overflow-visible',
238
- },
239
- {
240
- value: 'hidden',
241
- utilityClass: 'overflow-hidden',
242
- },
243
- {
244
- value: 'auto',
245
- utilityClass: 'overflow-auto',
246
- },
247
- {
248
- value: 'scroll',
249
- utilityClass: 'overflow-scroll',
250
- },
251
- ],
252
- 'overflow-x': [
253
- {
254
- value: 'visible',
255
- utilityClass: 'overflow-x-visible',
256
- },
257
- {
258
- value: 'hidden',
259
- utilityClass: 'overflow-x-hidden',
260
- },
261
- {
262
- value: 'auto',
263
- utilityClass: 'overflow-x-auto',
264
- },
265
- {
266
- value: 'scroll',
267
- utilityClass: 'overflow-x-scroll',
268
- },
269
- ],
270
- 'overflow-y': [
271
- {
272
- value: 'visible',
273
- utilityClass: 'overflow-y-visible',
274
- },
275
- {
276
- value: 'hidden',
277
- utilityClass: 'overflow-y-hidden',
278
- },
279
- {
280
- value: 'auto',
281
- utilityClass: 'overflow-y-auto',
282
- },
283
- {
284
- value: 'scroll',
285
- utilityClass: 'overflow-y-scroll',
286
- },
287
- ],
288
- height: [
289
- {
290
- value: '100%',
291
- utilityClass: 'height-full',
292
- },
293
- ],
294
- 'max-width': [
295
- {
296
- value: '100%',
297
- utilityClass: 'width-fit',
298
- },
299
- ],
300
- 'max-height': [
301
- {
302
- value: '100%',
303
- utilityClass: 'height-fit',
304
- },
305
- ],
306
- 'min-width': [
307
- {
308
- value: '0',
309
- utilityClass: 'min-width-0',
310
- },
311
- ],
312
- float: [
313
- {
314
- value: 'left',
315
- utilityClass: 'float-left',
316
- },
317
- {
318
- value: 'right',
319
- utilityClass: 'float-right',
320
- },
321
- {
322
- value: 'none',
323
- utilityClass: 'float-none',
324
- },
325
- ],
326
- 'list-style': [
327
- {
328
- value: 'none',
329
- utilityClass: 'list-style-none',
330
- },
331
- ],
332
- 'user-select': [
333
- {
334
- value: 'none',
335
- utilityClass: 'user-select-none',
336
- },
337
- ],
338
- visibility: [
339
- {
340
- value: 'hidden',
341
- utilityClass: 'v-hidden',
342
- },
343
- {
344
- value: 'visible',
345
- utilityClass: 'v-visible',
346
- },
347
- ],
348
- 'vertical-align': [
349
- {
350
- value: 'middle',
351
- utilityClass: 'v-align-middle',
352
- },
353
- {
354
- value: 'top',
355
- utilityClass: 'v-align-top',
356
- },
357
- {
358
- value: 'bottom',
359
- utilityClass: 'v-align-bottom',
360
- },
361
- {
362
- value: 'text-top',
363
- utilityClass: 'v-align-text-top',
364
- },
365
- {
366
- value: 'text-bottom',
367
- utilityClass: 'v-align-text-bottom',
368
- },
369
- {
370
- value: 'text-baseline',
371
- utilityClass: 'v-align-baseline',
372
- },
373
- ],
374
- 'font-weight': [
375
- {
376
- value: '$font-weight-normal',
377
- utilityClass: 'text-normal',
378
- },
379
- {
380
- value: '$font-weight-bold',
381
- utilityClass: 'text-bold',
382
- },
383
- {
384
- value: '$font-weight-semibold',
385
- utilityClass: 'text-semibold',
386
- },
387
- {
388
- value: '$font-weight-light',
389
- utilityClass: 'text-light',
390
- },
391
- ],
392
- top: [
393
- {
394
- value: '0',
395
- utilityClass: 'top-0',
396
- },
397
- {
398
- value: 'auto',
399
- utilityClass: 'top-auto',
400
- },
401
- ],
402
- right: [
403
- {
404
- value: '0',
405
- utilityClass: 'right-0',
406
- },
407
- {
408
- value: 'auto',
409
- utilityClass: 'right-auto',
410
- },
411
- ],
412
- bottom: [
413
- {
414
- value: '0',
415
- utilityClass: 'bottom-0',
416
- },
417
- {
418
- value: 'auto',
419
- utilityClass: 'bottom-auto',
420
- },
421
- ],
422
- left: [
423
- {
424
- value: '0',
425
- utilityClass: 'left-0',
426
- },
427
- {
428
- value: 'auto',
429
- utilityClass: 'left-auto',
430
- },
431
- ],
432
- position: [
433
- {
434
- value: 'static',
435
- utilityClass: 'position-static',
436
- },
437
- {
438
- value: 'relative',
439
- utilityClass: 'position-relative',
440
- },
441
- {
442
- value: 'absolute',
443
- utilityClass: 'position-absolute',
444
- },
445
- {
446
- value: 'fixed',
447
- utilityClass: 'position-fixed',
448
- },
449
- {
450
- value: 'sticky',
451
- utilityClass: 'position-sticky',
452
- },
453
- ],
454
- 'box-shadow': [
455
- {
456
- value: 'none',
457
- utilityClass: 'box-shadow-none',
458
- },
459
- {
460
- value: 'var(--color-shadow-small)',
461
- utilityClass: 'box-shadow-small',
462
- },
463
- {
464
- value: 'var(--color-shadow-medium)',
465
- utilityClass: 'box-shadow-medium',
466
- },
467
- {
468
- value: 'var(--color-shadow-large)',
469
- utilityClass: 'box-shadow-large',
470
- },
471
- {
472
- value: 'var(--color-shadow-extra-large)',
473
- utilityClass: 'box-shadow-extra-large',
474
- },
475
- ],
476
- border: [
477
- {
478
- value: '$border',
479
- utilityClass: 'border',
480
- },
481
- {
482
- value: '0',
483
- utilityClass: 'border-0',
484
- },
485
- ],
486
- 'border-top': [
487
- {
488
- value: '$border',
489
- utilityClass: 'border-top',
490
- },
491
- {
492
- value: '0',
493
- utilityClass: 'border-top-0',
494
- },
495
- ],
496
- 'border-right': [
497
- {
498
- value: '$border',
499
- utilityClass: 'border-right',
500
- },
501
- {
502
- value: '0',
503
- utilityClass: 'border-right-0',
504
- },
505
- ],
506
- 'border-bottom': [
507
- {
508
- value: '$border',
509
- utilityClass: 'border-bottom',
510
- },
511
- {
512
- value: '0',
513
- utilityClass: 'border-bottom-0',
514
- },
515
- ],
516
- 'border-left': [
517
- {
518
- value: '$border',
519
- utilityClass: 'border-left',
520
- },
521
- {
522
- value: '0',
523
- utilityClass: 'border-left-0',
524
- },
525
- ],
526
- }
@@ -1,52 +0,0 @@
1
- import stylelint from 'stylelint'
2
- import utilities from './lib/primer-utilities.js'
3
-
4
- export const ruleName = 'primer/utilities'
5
-
6
- export const messages = stylelint.utils.ruleMessages(ruleName, {
7
- rejected: (selector, utilityClass) => {
8
- return `Consider using the Primer utility '.${utilityClass}' instead of the selector '${selector}' in your html. https://primer.style/css/utilities`
9
- },
10
- })
11
-
12
- // eslint-disable-next-line no-unused-vars
13
- export default stylelint.createPlugin(ruleName, (enabled, options = {}, context) => {
14
- if (!enabled) {
15
- return noop
16
- }
17
-
18
- const utilityReplacement = (declaration, value) => {
19
- const declarationUtilities = utilities[declaration]
20
- if (declarationUtilities) {
21
- return declarationUtilities.find(utility => {
22
- return utility.value === value
23
- })
24
- }
25
- }
26
-
27
- const lintResult = (root, result) => {
28
- root.walkRules(rule => {
29
- if (!/^\.[\w\-_]+$/.exec(rule.selector)) {
30
- return
31
- }
32
- const decls = rule.nodes.filter(decl => decl.type === 'decl')
33
-
34
- if (decls.length === 1) {
35
- const replacement = utilityReplacement(decls[0].prop, decls[0].value)
36
- if (replacement) {
37
- stylelint.utils.report({
38
- index: rule.sourceIndex,
39
- message: messages.rejected(rule.selector, replacement.utilityClass),
40
- node: rule,
41
- result,
42
- ruleName,
43
- })
44
- }
45
- }
46
- })
47
- }
48
-
49
- return lintResult
50
- })
51
-
52
- function noop() {}