@primer/stylelint-config 13.0.1-rc.bbe2b12 → 13.1.0-rc.437e7b4
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/dist/index.cjs +181 -356
- package/dist/index.mjs +179 -354
- package/package.json +2 -5
- package/plugins/colors.js +166 -41
- package/plugins/lib/utils.js +16 -0
- package/plugins/lib/decl-validator.js +0 -238
- package/plugins/lib/new-color-css-vars-map.json +0 -279
- package/plugins/lib/primitives-v8.json +0 -1482
- package/plugins/lib/variable-rules.js +0 -83
package/dist/index.mjs
CHANGED
|
@@ -3,9 +3,6 @@ import stylelint from 'stylelint';
|
|
|
3
3
|
import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.cjs';
|
|
4
4
|
import valueParser from 'postcss-value-parser';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
|
-
import anymatch from 'anymatch';
|
|
7
|
-
import TapMap from 'tap-map';
|
|
8
|
-
import variables$3 from '@primer/css/dist/variables.json' with { type: 'json' };
|
|
9
6
|
import matchAll from 'string.prototype.matchall';
|
|
10
7
|
|
|
11
8
|
var propertyOrder = [
|
|
@@ -202,6 +199,9 @@ function primitivesVariables(type) {
|
|
|
202
199
|
files.push('functional/themes/light.json');
|
|
203
200
|
files.push('functional/size/border.json');
|
|
204
201
|
break
|
|
202
|
+
case 'colors':
|
|
203
|
+
files.push('functional/themes/light.json');
|
|
204
|
+
break
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
for (const file of files) {
|
|
@@ -222,6 +222,19 @@ function primitivesVariables(type) {
|
|
|
222
222
|
return variables
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
const HAS_VALID_HEX = /#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})(?:$|[^\da-f])/i;
|
|
226
|
+
const COLOR_FUNCTION_NAMES = ['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'lab', 'lch', 'oklab', 'oklch'];
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Check if a value contains a valid 3, 4, 6 or 8 digit hex
|
|
230
|
+
*
|
|
231
|
+
* @param {string} value
|
|
232
|
+
* @returns {boolean}
|
|
233
|
+
*/
|
|
234
|
+
function hasValidColor(value) {
|
|
235
|
+
return HAS_VALID_HEX.test(value) || COLOR_FUNCTION_NAMES.includes(value)
|
|
236
|
+
}
|
|
237
|
+
|
|
225
238
|
function walkGroups$1(root, validate) {
|
|
226
239
|
for (const node of root.nodes) {
|
|
227
240
|
if (node.type === 'function') {
|
|
@@ -234,12 +247,12 @@ function walkGroups$1(root, validate) {
|
|
|
234
247
|
}
|
|
235
248
|
|
|
236
249
|
const {
|
|
237
|
-
createPlugin: createPlugin$
|
|
238
|
-
utils: {report: report$
|
|
250
|
+
createPlugin: createPlugin$4,
|
|
251
|
+
utils: {report: report$4, ruleMessages: ruleMessages$4, validateOptions: validateOptions$4},
|
|
239
252
|
} = stylelint;
|
|
240
253
|
|
|
241
|
-
const ruleName$
|
|
242
|
-
const messages$
|
|
254
|
+
const ruleName$6 = 'primer/borders';
|
|
255
|
+
const messages$6 = ruleMessages$4(ruleName$6, {
|
|
243
256
|
rejected: (value, replacement, propName) => {
|
|
244
257
|
if (propName && propName.includes('radius') && value.includes('borderWidth')) {
|
|
245
258
|
return `Border radius variables can not be used for border widths`
|
|
@@ -257,7 +270,7 @@ const messages$5 = ruleMessages$3(ruleName$5, {
|
|
|
257
270
|
},
|
|
258
271
|
});
|
|
259
272
|
|
|
260
|
-
const variables$
|
|
273
|
+
const variables$3 = primitivesVariables('border');
|
|
261
274
|
const sizes$1 = [];
|
|
262
275
|
const radii = [];
|
|
263
276
|
|
|
@@ -269,7 +282,7 @@ const valueList$1 = ['${'];
|
|
|
269
282
|
const borderShorthand = prop =>
|
|
270
283
|
/^border(-(top|right|bottom|left|block-start|block-end|inline-start|inline-end))?$/.test(prop);
|
|
271
284
|
|
|
272
|
-
for (const variable of variables$
|
|
285
|
+
for (const variable of variables$3) {
|
|
273
286
|
const name = variable['name'];
|
|
274
287
|
|
|
275
288
|
if (name.includes('borderWidth')) {
|
|
@@ -289,9 +302,9 @@ for (const variable of variables$2) {
|
|
|
289
302
|
}
|
|
290
303
|
|
|
291
304
|
/** @type {import('stylelint').Rule} */
|
|
292
|
-
const ruleFunction$
|
|
305
|
+
const ruleFunction$4 = primary => {
|
|
293
306
|
return (root, result) => {
|
|
294
|
-
const validOptions = validateOptions$
|
|
307
|
+
const validOptions = validateOptions$4(result, ruleName$6, {
|
|
295
308
|
actual: primary,
|
|
296
309
|
possible: [true],
|
|
297
310
|
});
|
|
@@ -388,13 +401,13 @@ const ruleFunction$3 = primary => {
|
|
|
388
401
|
node.value = node.value.replace(node.value, `var(${replacement['name']})`);
|
|
389
402
|
};
|
|
390
403
|
}
|
|
391
|
-
report$
|
|
404
|
+
report$4({
|
|
392
405
|
index: declarationValueIndex(declNode) + node.sourceIndex,
|
|
393
406
|
endIndex: declarationValueIndex(declNode) + node.sourceIndex + node.value.length,
|
|
394
|
-
message: messages$
|
|
407
|
+
message: messages$6.rejected(node.value, replacement, prop),
|
|
395
408
|
node: declNode,
|
|
396
409
|
result,
|
|
397
|
-
ruleName: ruleName$
|
|
410
|
+
ruleName: ruleName$6,
|
|
398
411
|
fix,
|
|
399
412
|
});
|
|
400
413
|
|
|
@@ -406,21 +419,21 @@ const ruleFunction$3 = primary => {
|
|
|
406
419
|
}
|
|
407
420
|
};
|
|
408
421
|
|
|
409
|
-
ruleFunction$
|
|
410
|
-
ruleFunction$
|
|
411
|
-
ruleFunction$
|
|
422
|
+
ruleFunction$4.ruleName = ruleName$6;
|
|
423
|
+
ruleFunction$4.messages = messages$6;
|
|
424
|
+
ruleFunction$4.meta = {
|
|
412
425
|
fixable: true,
|
|
413
426
|
};
|
|
414
427
|
|
|
415
|
-
var borders = createPlugin$
|
|
428
|
+
var borders = createPlugin$4(ruleName$6, ruleFunction$4);
|
|
416
429
|
|
|
417
430
|
const {
|
|
418
|
-
createPlugin: createPlugin$
|
|
419
|
-
utils: {report: report$
|
|
431
|
+
createPlugin: createPlugin$3,
|
|
432
|
+
utils: {report: report$3, ruleMessages: ruleMessages$3, validateOptions: validateOptions$3},
|
|
420
433
|
} = stylelint;
|
|
421
434
|
|
|
422
|
-
const ruleName$
|
|
423
|
-
const messages$
|
|
435
|
+
const ruleName$5 = 'primer/box-shadow';
|
|
436
|
+
const messages$5 = ruleMessages$3(ruleName$5, {
|
|
424
437
|
rejected: (value, replacement) => {
|
|
425
438
|
if (!replacement) {
|
|
426
439
|
return `Please use a Primer box-shadow variable instead of '${value}'. Consult the primer docs for a suitable replacement. https://primer.style/foundations/primitives/color#shadow or https://primer.style/foundations/primitives/size#border-size`
|
|
@@ -430,10 +443,10 @@ const messages$4 = ruleMessages$2(ruleName$4, {
|
|
|
430
443
|
},
|
|
431
444
|
});
|
|
432
445
|
|
|
433
|
-
const variables$
|
|
446
|
+
const variables$2 = primitivesVariables('box-shadow');
|
|
434
447
|
const shadows = [];
|
|
435
448
|
|
|
436
|
-
for (const variable of variables$
|
|
449
|
+
for (const variable of variables$2) {
|
|
437
450
|
const name = variable['name'];
|
|
438
451
|
|
|
439
452
|
// TODO: Decide if this is safe. Someday we might have variables that
|
|
@@ -444,9 +457,9 @@ for (const variable of variables$1) {
|
|
|
444
457
|
}
|
|
445
458
|
|
|
446
459
|
/** @type {import('stylelint').Rule} */
|
|
447
|
-
const ruleFunction$
|
|
460
|
+
const ruleFunction$3 = primary => {
|
|
448
461
|
return (root, result) => {
|
|
449
|
-
const validOptions = validateOptions$
|
|
462
|
+
const validOptions = validateOptions$3(result, ruleName$5, {
|
|
450
463
|
actual: primary,
|
|
451
464
|
possible: [true],
|
|
452
465
|
});
|
|
@@ -479,378 +492,190 @@ const ruleFunction$2 = primary => {
|
|
|
479
492
|
};
|
|
480
493
|
}
|
|
481
494
|
|
|
482
|
-
report$
|
|
495
|
+
report$3({
|
|
483
496
|
index: declarationValueIndex(declNode),
|
|
484
497
|
endIndex: declarationValueIndex(declNode) + value.length,
|
|
485
|
-
message: messages$
|
|
498
|
+
message: messages$5.rejected(value, replacement),
|
|
486
499
|
node: declNode,
|
|
487
500
|
result,
|
|
488
|
-
ruleName: ruleName$
|
|
501
|
+
ruleName: ruleName$5,
|
|
489
502
|
fix,
|
|
490
503
|
});
|
|
491
504
|
});
|
|
492
505
|
}
|
|
493
506
|
};
|
|
494
507
|
|
|
495
|
-
ruleFunction$
|
|
496
|
-
ruleFunction$
|
|
497
|
-
ruleFunction$
|
|
508
|
+
ruleFunction$3.ruleName = ruleName$5;
|
|
509
|
+
ruleFunction$3.messages = messages$5;
|
|
510
|
+
ruleFunction$3.meta = {
|
|
498
511
|
fixable: true,
|
|
499
512
|
};
|
|
500
513
|
|
|
501
|
-
var boxShadow = createPlugin$
|
|
502
|
-
|
|
503
|
-
const SKIP_VALUE_NODE_TYPES = new Set(['space', 'div']);
|
|
504
|
-
const SKIP_AT_RULE_NAMES = new Set(['each', 'for', 'function', 'mixin']);
|
|
514
|
+
var boxShadow = createPlugin$3(ruleName$5, ruleFunction$3);
|
|
505
515
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
for (const [name, {values}] of Object.entries(variables)) {
|
|
511
|
-
for (const value of values) {
|
|
512
|
-
variableReplacements.tap(value, () => []).push(name);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
+
const {
|
|
517
|
+
createPlugin: createPlugin$2,
|
|
518
|
+
utils: {report: report$2, ruleMessages: ruleMessages$2, validateOptions: validateOptions$2},
|
|
519
|
+
} = stylelint;
|
|
516
520
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
return {
|
|
527
|
-
rule,
|
|
528
|
-
matchesProp: anymatch(props),
|
|
529
|
-
validate: Array.isArray(rule.components) ? componentValidator(rule) : valueValidator(rule),
|
|
530
|
-
}
|
|
531
|
-
})
|
|
532
|
-
.filter(Boolean);
|
|
533
|
-
|
|
534
|
-
const validatorsByProp = new TapMap();
|
|
535
|
-
const validatorsByReplacementValue = new Map();
|
|
536
|
-
for (const validator of validators) {
|
|
537
|
-
for (const value of Object.keys(validator.rule.replacements)) {
|
|
538
|
-
validatorsByReplacementValue.set(value, validator);
|
|
521
|
+
const ruleName$4 = 'primer/colors';
|
|
522
|
+
const messages$4 = ruleMessages$2(ruleName$4, {
|
|
523
|
+
rejected: (value, type) => {
|
|
524
|
+
if (type === 'fg') {
|
|
525
|
+
return `Please use a Primer foreground color variable instead of '${value}'. https://primer.style/foundations/primitives/color#foreground`
|
|
526
|
+
} else if (type === 'bg') {
|
|
527
|
+
return `Please use a Primer background color variable instead of '${value}'. https://primer.style/foundations/primitives/color#background`
|
|
528
|
+
} else if (type === 'border') {
|
|
529
|
+
return `Please use a Primer border color variable instead of '${value}'. https://primer.style/foundations/primitives/color#border`
|
|
539
530
|
}
|
|
540
|
-
|
|
531
|
+
return `Please use with a Primer color variable instead of '${value}'. https://primer.style/foundations/primitives/color`
|
|
532
|
+
},
|
|
533
|
+
});
|
|
541
534
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
// they want
|
|
551
|
-
return {valid: true}
|
|
552
|
-
}
|
|
553
|
-
const validator = getPropValidator(decl.prop);
|
|
554
|
-
if (validator) {
|
|
555
|
-
const result = validator.validate(decl);
|
|
556
|
-
result.errors = result.errors.map(formatMessage);
|
|
557
|
-
return result
|
|
558
|
-
} else {
|
|
559
|
-
return {valid: true}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
535
|
+
let variables$1 = primitivesVariables('colors');
|
|
536
|
+
const validProps = {
|
|
537
|
+
'^color$': ['fgColor', 'iconColor'],
|
|
538
|
+
'^background(-color)?$': ['bgColor'],
|
|
539
|
+
'^border(-top|-right|-bottom|-left|-inline|-block)*(-color)?$': ['borderColor'],
|
|
540
|
+
'^fill$': ['fgColor', 'iconColor', 'bgColor'],
|
|
541
|
+
'^stroke$': ['fgColor', 'iconColor', 'bgColor', 'borderColor'],
|
|
542
|
+
};
|
|
562
543
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
return replacements
|
|
575
|
-
}
|
|
544
|
+
const validValues = [
|
|
545
|
+
'none',
|
|
546
|
+
'currentcolor',
|
|
547
|
+
'inherit',
|
|
548
|
+
'initial',
|
|
549
|
+
'unset',
|
|
550
|
+
'revert',
|
|
551
|
+
'revert-layer',
|
|
552
|
+
'transparent',
|
|
553
|
+
'0',
|
|
554
|
+
];
|
|
576
555
|
|
|
577
|
-
|
|
578
|
-
|
|
556
|
+
const propType = prop => {
|
|
557
|
+
if (/^color/.test(prop)) {
|
|
558
|
+
return 'fg'
|
|
559
|
+
} else if (/^background(-color)?$/.test(prop)) {
|
|
560
|
+
return 'bg'
|
|
561
|
+
} else if (/^border(-top|-right|-bottom|-left|-inline|-block)*(-color)?$/.test(prop)) {
|
|
562
|
+
return 'border'
|
|
563
|
+
} else if (/^fill$/.test(prop)) {
|
|
564
|
+
return 'fg'
|
|
565
|
+
} else if (/^stroke$/.test(prop)) {
|
|
566
|
+
return 'fg'
|
|
579
567
|
}
|
|
568
|
+
return undefined
|
|
569
|
+
};
|
|
580
570
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
valid: true,
|
|
587
|
-
errors: [],
|
|
588
|
-
fixable: false,
|
|
589
|
-
replacement: undefined,
|
|
590
|
-
}
|
|
591
|
-
} else if (replacements[value]) {
|
|
592
|
-
let replacement = value;
|
|
593
|
-
do {
|
|
594
|
-
replacement = replacements[replacement];
|
|
595
|
-
} while (replacements[replacement])
|
|
596
|
-
return {
|
|
597
|
-
valid: false,
|
|
598
|
-
errors: [{expects, prop, value, replacement}],
|
|
599
|
-
fixable: true,
|
|
600
|
-
replacement,
|
|
601
|
-
}
|
|
602
|
-
} else {
|
|
603
|
-
if (nested || singular) {
|
|
604
|
-
return {
|
|
605
|
-
valid: false,
|
|
606
|
-
errors: [{expects, prop, value}],
|
|
607
|
-
fixable: false,
|
|
608
|
-
replacement: undefined,
|
|
609
|
-
}
|
|
610
|
-
}
|
|
571
|
+
variables$1 = variables$1.filter(variable => {
|
|
572
|
+
const name = variable['name'];
|
|
573
|
+
// remove shadow and boxShadow variables
|
|
574
|
+
return !(name.includes('shadow') || name.includes('boxShadow'))
|
|
575
|
+
});
|
|
611
576
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
});
|
|
577
|
+
/** @type {import('stylelint').Rule} */
|
|
578
|
+
const ruleFunction$2 = primary => {
|
|
579
|
+
return (root, result) => {
|
|
580
|
+
const validOptions = validateOptions$2(result, ruleName$4, {
|
|
581
|
+
actual: primary,
|
|
582
|
+
possible: [true],
|
|
583
|
+
});
|
|
584
|
+
if (!validOptions) return
|
|
621
585
|
|
|
622
|
-
|
|
623
|
-
if (valid) {
|
|
624
|
-
return {valid, errors: [], fixable: false, replacement: undefined}
|
|
625
|
-
}
|
|
586
|
+
const valueIsCorrectType = (value, types) => types.some(type => value.includes(type));
|
|
626
587
|
|
|
627
|
-
|
|
628
|
-
|
|
588
|
+
root.walkDecls(declNode => {
|
|
589
|
+
const {prop, value} = declNode;
|
|
629
590
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
if (fixable && validation.replacement) {
|
|
633
|
-
parsed.nodes[validation.index] = {type: 'word', value: validation.replacement};
|
|
634
|
-
}
|
|
635
|
-
}
|
|
591
|
+
// Skip if prop is not a valid color prop
|
|
592
|
+
if (!Object.keys(validProps).some(validProp => new RegExp(validProp).test(prop))) return
|
|
636
593
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
594
|
+
// Get the valid types for the prop
|
|
595
|
+
const types = validProps[Object.keys(validProps).find(re => new RegExp(re).test(prop))];
|
|
640
596
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
replacement,
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
597
|
+
// Walk the value split
|
|
598
|
+
valueParser(value).walk(valueNode => {
|
|
599
|
+
// Skip if value is not a word or function
|
|
600
|
+
if (valueNode.type !== 'word' && valueNode.type !== 'function') return
|
|
650
601
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
return decl => {
|
|
654
|
-
const {prop, value: compoundValue} = decl;
|
|
655
|
-
const parsed = valueParser(compoundValue);
|
|
656
|
-
if (parsed.nodes.length === 1 && matchesCompoundValue(compoundValue)) {
|
|
657
|
-
return {valid: true, errors: []}
|
|
658
|
-
}
|
|
602
|
+
// Skip if value is a valid value
|
|
603
|
+
if (validValues.includes(valueNode.value)) return
|
|
659
604
|
|
|
660
|
-
|
|
605
|
+
if (hasValidColor(valueNode.value) || /^\$/.test(valueNode.value)) {
|
|
606
|
+
const rejectedValue =
|
|
607
|
+
valueNode.type === 'function'
|
|
608
|
+
? `${valueNode.value}(${valueParser.stringify(valueNode.nodes)})`
|
|
609
|
+
: valueNode.value;
|
|
661
610
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
611
|
+
report$2({
|
|
612
|
+
index: declarationValueIndex(declNode) + valueNode.sourceIndex,
|
|
613
|
+
endIndex: declarationValueIndex(declNode) + valueNode.sourceEndIndex,
|
|
614
|
+
message: messages$4.rejected(rejectedValue, propType(prop)),
|
|
615
|
+
node: declNode,
|
|
616
|
+
result,
|
|
617
|
+
ruleName: ruleName$4,
|
|
618
|
+
});
|
|
619
|
+
return
|
|
667
620
|
}
|
|
668
621
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
let validator = getPropValidator(componentProp);
|
|
673
|
-
if (validatorsByReplacementValue.has(value)) {
|
|
674
|
-
validator = validatorsByReplacementValue.get(value);
|
|
675
|
-
componentProp = validator.rule.name;
|
|
622
|
+
// Skip functions
|
|
623
|
+
if (valueNode.type === 'function') {
|
|
624
|
+
return
|
|
676
625
|
}
|
|
677
626
|
|
|
678
|
-
|
|
679
|
-
if (
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
value: result.replacement,
|
|
685
|
-
};
|
|
686
|
-
fixable = true;
|
|
687
|
-
}
|
|
688
|
-
for (const error of result.errors) {
|
|
689
|
-
errors.push(error);
|
|
690
|
-
}
|
|
691
|
-
} else {
|
|
692
|
-
errors.push({expects, prop: nestedProp, value});
|
|
627
|
+
// Variable exists and is the correct type (fg, bg, border)
|
|
628
|
+
if (
|
|
629
|
+
variables$1.some(variable => new RegExp(variable['name']).test(valueNode.value)) &&
|
|
630
|
+
valueIsCorrectType(valueNode.value, types)
|
|
631
|
+
) {
|
|
632
|
+
return
|
|
693
633
|
}
|
|
694
|
-
}
|
|
695
634
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (replacement && replacements[replacement]) {
|
|
700
|
-
do {
|
|
701
|
-
replacement = replacements[replacement];
|
|
702
|
-
} while (replacements[replacement])
|
|
703
|
-
return {
|
|
704
|
-
valid: false,
|
|
705
|
-
errors: [{expects, prop, value: compoundValue, replacement}],
|
|
706
|
-
fixable: true,
|
|
707
|
-
replacement,
|
|
635
|
+
// Value doesn't start with variable --
|
|
636
|
+
if (!valueNode.value.startsWith('--')) {
|
|
637
|
+
return
|
|
708
638
|
}
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
return {
|
|
712
|
-
valid: errors.length === 0,
|
|
713
|
-
errors,
|
|
714
|
-
fixable,
|
|
715
|
-
replacement,
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
639
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
function closest(node, test) {
|
|
732
|
-
let ancestor = node;
|
|
733
|
-
do {
|
|
734
|
-
if (test(ancestor)) return ancestor
|
|
735
|
-
} while ((ancestor = ancestor.parent))
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
function createVariableRule(ruleName, rules, url) {
|
|
739
|
-
const plugin = stylelint.createPlugin(ruleName, (enabled, options = {}, context) => {
|
|
740
|
-
if (enabled === false) {
|
|
741
|
-
return noop$2
|
|
742
|
-
}
|
|
640
|
+
// Ignore old system colors --color-*
|
|
641
|
+
if (
|
|
642
|
+
[
|
|
643
|
+
/^--color-(?:[a-zA-Z0-9-]+-)*text(?:-[a-zA-Z0-9-]+)*$/,
|
|
644
|
+
/^--color-(?:[a-zA-Z0-9-](?!-))*-fg(?:-[a-zA-Z0-9-]+)*$/,
|
|
645
|
+
/^--color-[^)]+$/,
|
|
646
|
+
].some(oldSysRe => oldSysRe.test(valueNode.value))
|
|
647
|
+
) {
|
|
648
|
+
return
|
|
649
|
+
}
|
|
743
650
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
if (typeof overrides === 'function') {
|
|
752
|
-
delete options.rules;
|
|
753
|
-
overrides = overrides({rules: actualRules, options, ruleName, variables: variables$3});
|
|
754
|
-
}
|
|
755
|
-
if (overrides) {
|
|
756
|
-
Object.assign(actualRules, overrides);
|
|
757
|
-
}
|
|
758
|
-
const validate = declarationValidator(actualRules, {variables: variables$3});
|
|
759
|
-
|
|
760
|
-
// The stylelint docs suggest respecting a "disableFix" rule option that
|
|
761
|
-
// overrides the "global" context.fix (--fix) linting option.
|
|
762
|
-
const {verbose = false, disableFix} = options;
|
|
763
|
-
const fixEnabled = context && context.fix && !disableFix;
|
|
764
|
-
const seen = new WeakMap();
|
|
765
|
-
|
|
766
|
-
return (root, result) => {
|
|
767
|
-
root.walkRules(rule => {
|
|
768
|
-
rule.walkDecls(decl => {
|
|
769
|
-
if (seen.has(decl)) {
|
|
770
|
-
return
|
|
771
|
-
} else {
|
|
772
|
-
seen.set(decl, true);
|
|
773
|
-
}
|
|
651
|
+
// Property is shortand and value doesn't include color
|
|
652
|
+
if (
|
|
653
|
+
(/^border(-top|-right|-bottom|-left|-inline|-block)*$/.test(prop) || /^background$/.test(prop)) &&
|
|
654
|
+
!valueNode.value.toLowerCase().includes('color')
|
|
655
|
+
) {
|
|
656
|
+
return
|
|
657
|
+
}
|
|
774
658
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
for (const error of errors) {
|
|
783
|
-
const message = stylelint.utils
|
|
784
|
-
.ruleMessages(ruleName, {
|
|
785
|
-
rejected: m => {
|
|
786
|
-
{
|
|
787
|
-
return `${m}. See ${url}.`
|
|
788
|
-
}
|
|
789
|
-
},
|
|
790
|
-
})
|
|
791
|
-
.rejected(error);
|
|
792
|
-
|
|
793
|
-
stylelint.utils.report({
|
|
794
|
-
message,
|
|
795
|
-
node: decl,
|
|
796
|
-
result,
|
|
797
|
-
ruleName,
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
}
|
|
659
|
+
report$2({
|
|
660
|
+
index: declarationValueIndex(declNode) + valueNode.sourceIndex,
|
|
661
|
+
endIndex: declarationValueIndex(declNode) + valueNode.sourceEndIndex,
|
|
662
|
+
message: messages$4.rejected(`var(${valueNode.value})`, propType(prop)),
|
|
663
|
+
node: declNode,
|
|
664
|
+
result,
|
|
665
|
+
ruleName: ruleName$4,
|
|
801
666
|
});
|
|
802
667
|
});
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
Object.assign(plugin, {rules});
|
|
807
|
-
|
|
808
|
-
return plugin
|
|
809
|
-
}
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
};
|
|
810
671
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
// Match variables in any of the following formats: --color-bg-*, --color-*-bg-*, --color-*-bg, *bgColor*, *fgColor*, *borderColor*, *iconColor*
|
|
817
|
-
/var\(--color-(.+-)*bg(-.+)*\)/,
|
|
818
|
-
/var\(--color-[^)]+\)/,
|
|
819
|
-
/var\((.+-)*bgColor(-.+)*\)/,
|
|
820
|
-
/var\((.+-)*fgColor(-.+)*\)/,
|
|
821
|
-
/var\((.+-)*borderColor(-.+)*\)/,
|
|
822
|
-
/var\((.+-)*iconColor(-.+)*\)/,
|
|
823
|
-
];
|
|
672
|
+
ruleFunction$2.ruleName = ruleName$4;
|
|
673
|
+
ruleFunction$2.messages = messages$4;
|
|
674
|
+
ruleFunction$2.meta = {
|
|
675
|
+
fixable: false,
|
|
676
|
+
};
|
|
824
677
|
|
|
825
|
-
var colors =
|
|
826
|
-
'primer/colors',
|
|
827
|
-
{
|
|
828
|
-
'background-color': {
|
|
829
|
-
expects: 'a background color variable',
|
|
830
|
-
values: bgVars.concat('none', 'transparent'),
|
|
831
|
-
},
|
|
832
|
-
background: {
|
|
833
|
-
expects: 'a background color variable',
|
|
834
|
-
values: bgVars.concat('none', 'transparent', 'top', 'right', 'bottom', 'left', 'center', '*px', 'url(*)'),
|
|
835
|
-
},
|
|
836
|
-
'text color': {
|
|
837
|
-
expects: 'a text color variable',
|
|
838
|
-
props: 'color',
|
|
839
|
-
values: [
|
|
840
|
-
'$text-*',
|
|
841
|
-
'$tooltip-text-color',
|
|
842
|
-
'inherit',
|
|
843
|
-
// Match variables in any of the following formats: --color-text-*, --color-*-text-*, --color-*-text, *fgColor*, *iconColor*
|
|
844
|
-
/var\(--color-(.+-)*text(-.+)*\)/,
|
|
845
|
-
/var\(--color-(.+-)*fg(-.+)*\)/,
|
|
846
|
-
/var\(--color-[^)]+\)/,
|
|
847
|
-
/var\((.+-)*fgColor(-.+)*\)/,
|
|
848
|
-
/var\((.+-)*iconColor(-.+)*\)/,
|
|
849
|
-
],
|
|
850
|
-
},
|
|
851
|
-
},
|
|
852
|
-
'https://primer.style/primitives/colors',
|
|
853
|
-
);
|
|
678
|
+
var colors = createPlugin$2(ruleName$4, ruleFunction$2);
|
|
854
679
|
|
|
855
680
|
const ruleName$3 = 'primer/responsive-widths';
|
|
856
681
|
|