@primer/stylelint-config 13.0.0-rc.f33e046 → 13.0.0-rc.f7b4bdd

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.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import browsers from '@github/browserslist-config';
2
2
  import stylelint from 'stylelint';
3
- import anymatch from 'anymatch';
3
+ import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.cjs';
4
4
  import valueParser from 'postcss-value-parser';
5
+ import { createRequire } from 'node:module';
6
+ import anymatch from 'anymatch';
5
7
  import TapMap from 'tap-map';
6
- import variables from '@primer/css/dist/variables.json' assert { type: 'json' };
7
- import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.cjs';
8
+ import variables$1 from '@primer/css/dist/variables.json' assert { type: 'json' };
8
9
  import matchAll from 'string.prototype.matchall';
9
- import { createRequire } from 'node:module';
10
10
 
11
11
  var propertyOrder = [
12
12
  'all',
@@ -181,6 +181,243 @@ var propertyOrder = [
181
181
  'animation-direction',
182
182
  ];
183
183
 
184
+ const require$1 = createRequire(import.meta.url);
185
+
186
+ function primitivesVariables(type) {
187
+ const variables = [];
188
+
189
+ const files = [];
190
+ switch (type) {
191
+ case 'spacing':
192
+ files.push('base/size/size.json');
193
+ break
194
+ case 'border':
195
+ files.push('functional/size/border.json');
196
+ break
197
+ }
198
+
199
+ for (const file of files) {
200
+ // eslint-disable-next-line import/no-dynamic-require
201
+ const data = require$1(`@primer/primitives/dist/styleLint/${file}`);
202
+
203
+ for (const key of Object.keys(data)) {
204
+ const size = data[key];
205
+ const values = typeof size['value'] === 'string' ? [size['value']] : size['value'];
206
+
207
+ variables.push({
208
+ name: `--${size['name']}`,
209
+ values,
210
+ });
211
+ }
212
+ }
213
+
214
+ return variables
215
+ }
216
+
217
+ function walkGroups$1(root, validate) {
218
+ for (const node of root.nodes) {
219
+ if (node.type === 'function') {
220
+ walkGroups$1(node, validate);
221
+ } else {
222
+ validate(node);
223
+ }
224
+ }
225
+ return root
226
+ }
227
+
228
+ const {
229
+ createPlugin: createPlugin$1,
230
+ utils: {report: report$1, ruleMessages: ruleMessages$1, validateOptions: validateOptions$1},
231
+ } = stylelint;
232
+
233
+ const ruleName$3 = 'primer/borders';
234
+ const messages$3 = ruleMessages$1(ruleName$3, {
235
+ rejected: (value, replacement, propName) => {
236
+ if (propName && propName.includes('radius') && value.includes('borderWidth')) {
237
+ return `Border radius variables can not be used for border widths`
238
+ }
239
+
240
+ if ((propName && propName.includes('width')) || (borderShorthand(propName) && value.includes('borderRadius'))) {
241
+ return `Border width variables can not be used for border radii`
242
+ }
243
+
244
+ if (!replacement) {
245
+ return `Please use a Primer border variable instead of '${value}'. Consult the primer docs for a suitable replacement. https://primer.style/foundations/primitives/size#border`
246
+ }
247
+
248
+ return `Please replace '${value}' with a Primer border variable '${replacement['name']}'. https://primer.style/foundations/primitives/size#border`
249
+ },
250
+ });
251
+
252
+ const variables = primitivesVariables('border');
253
+ const sizes$1 = [];
254
+ const radii = [];
255
+
256
+ // Props that we want to check
257
+ const propList$1 = ['border', 'border-width', 'border-radius'];
258
+ // Values that we want to ignore
259
+ const valueList$1 = ['${'];
260
+
261
+ const borderShorthand = prop =>
262
+ /^border(-(top|right|bottom|left|block-start|block-end|inline-start|inline-end))?$/.test(prop);
263
+
264
+ for (const variable of variables) {
265
+ const name = variable['name'];
266
+
267
+ if (name.includes('borderWidth')) {
268
+ const value = variable['values']
269
+ .pop()
270
+ .replace(/max|\(|\)/g, '')
271
+ .split(',')[0];
272
+ sizes$1.push({
273
+ name,
274
+ values: [value],
275
+ });
276
+ }
277
+
278
+ if (name.includes('borderRadius')) {
279
+ radii.push(variable);
280
+ }
281
+ }
282
+
283
+ /** @type {import('stylelint').Rule} */
284
+ const ruleFunction$1 = (primary, secondaryOptions, context) => {
285
+ return (root, result) => {
286
+ const validOptions = validateOptions$1(result, ruleName$3, {
287
+ actual: primary,
288
+ possible: [true],
289
+ });
290
+
291
+ if (!validOptions) return
292
+
293
+ root.walkDecls(declNode => {
294
+ const {prop, value} = declNode;
295
+
296
+ if (!propList$1.some(borderProp => prop.startsWith(borderProp))) return
297
+ if (/^border(-(top|right|bottom|left|block-start|block-end|inline-start|inline-end))?-color$/.test(prop)) return
298
+ if (valueList$1.some(valueToIgnore => value.includes(valueToIgnore))) return
299
+
300
+ const problems = [];
301
+
302
+ const parsedValue = walkGroups$1(valueParser(value), node => {
303
+ const checkForVariable = (vars, nodeValue) =>
304
+ vars.some(variable =>
305
+ new RegExp(`${variable['name'].replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(nodeValue),
306
+ );
307
+
308
+ // Only check word types. https://github.com/TrySound/postcss-value-parser#word
309
+ if (node.type !== 'word') {
310
+ return
311
+ }
312
+
313
+ // Exact values to ignore.
314
+ if (
315
+ [
316
+ '*',
317
+ '+',
318
+ '-',
319
+ '/',
320
+ '0',
321
+ 'none',
322
+ 'inherit',
323
+ 'initial',
324
+ 'revert',
325
+ 'revert-layer',
326
+ 'unset',
327
+ 'solid',
328
+ 'dashed',
329
+ 'dotted',
330
+ 'transparent',
331
+ ].includes(node.value)
332
+ ) {
333
+ return
334
+ }
335
+
336
+ const valueUnit = valueParser.unit(node.value);
337
+
338
+ if (valueUnit && (valueUnit.unit === '' || !/^-?[0-9.]+$/.test(valueUnit.number))) {
339
+ return
340
+ }
341
+
342
+ // Skip if the value unit isn't a supported unit.
343
+ if (valueUnit && !['px', 'rem', 'em'].includes(valueUnit.unit)) {
344
+ return
345
+ }
346
+
347
+ // if we're looking at the border property that sets color in shorthand, don't bother checking the color
348
+ if (
349
+ // using border shorthand
350
+ borderShorthand(prop) &&
351
+ // includes a color as a third space-separated value
352
+ value.split(' ').length > 2 &&
353
+ // the color in the third space-separated value includes `node.value`
354
+ value
355
+ .split(' ')
356
+ .slice(2)
357
+ .some(color => color.includes(node.value))
358
+ ) {
359
+ return
360
+ }
361
+
362
+ // If the variable is found in the value, skip it.
363
+ if (prop.includes('width') || borderShorthand(prop)) {
364
+ if (checkForVariable(sizes$1, node.value)) {
365
+ return
366
+ }
367
+ }
368
+
369
+ if (prop.includes('radius')) {
370
+ if (checkForVariable(radii, node.value)) {
371
+ return
372
+ }
373
+ }
374
+
375
+ const replacement = (prop.includes('radius') ? radii : sizes$1).find(variable =>
376
+ variable.values.includes(node.value.replace('-', '')),
377
+ );
378
+ const fixable = replacement && valueUnit && !valueUnit.number.includes('-');
379
+
380
+ if (fixable && context.fix) {
381
+ node.value = node.value.replace(node.value, `var(${replacement['name']})`);
382
+ } else {
383
+ problems.push({
384
+ index: declarationValueIndex(declNode) + node.sourceIndex,
385
+ endIndex: declarationValueIndex(declNode) + node.sourceIndex + node.value.length,
386
+ message: messages$3.rejected(node.value, replacement, prop),
387
+ });
388
+ }
389
+
390
+ return
391
+ });
392
+
393
+ if (context.fix) {
394
+ declNode.value = parsedValue.toString();
395
+ }
396
+
397
+ if (problems.length) {
398
+ for (const err of problems) {
399
+ report$1({
400
+ index: err.index,
401
+ endIndex: err.endIndex,
402
+ message: err.message,
403
+ node: declNode,
404
+ result,
405
+ ruleName: ruleName$3,
406
+ });
407
+ }
408
+ }
409
+ });
410
+ }
411
+ };
412
+
413
+ ruleFunction$1.ruleName = ruleName$3;
414
+ ruleFunction$1.messages = messages$3;
415
+ ruleFunction$1.meta = {
416
+ fixable: true,
417
+ };
418
+
419
+ var borders = createPlugin$1(ruleName$3, ruleFunction$1);
420
+
184
421
  const SKIP_VALUE_NODE_TYPES = new Set(['space', 'div']);
185
422
  const SKIP_AT_RULE_NAMES = new Set(['each', 'for', 'function', 'mixin']);
186
423
 
@@ -419,24 +656,24 @@ function closest(node, test) {
419
656
  function createVariableRule(ruleName, rules, url) {
420
657
  const plugin = stylelint.createPlugin(ruleName, (enabled, options = {}, context) => {
421
658
  if (enabled === false) {
422
- return noop$4
659
+ return noop$2
423
660
  }
424
661
 
425
662
  let actualRules = rules;
426
663
  let overrides = options.rules;
427
664
  if (typeof rules === 'function') {
428
- actualRules = rules({variables, options, ruleName});
665
+ actualRules = rules({variables: variables$1, options, ruleName});
429
666
  } else {
430
667
  actualRules = Object.assign({}, rules);
431
668
  }
432
669
  if (typeof overrides === 'function') {
433
670
  delete options.rules;
434
- overrides = overrides({rules: actualRules, options, ruleName, variables});
671
+ overrides = overrides({rules: actualRules, options, ruleName, variables: variables$1});
435
672
  }
436
673
  if (overrides) {
437
674
  Object.assign(actualRules, overrides);
438
675
  }
439
- const validate = declarationValidator(actualRules, {variables});
676
+ const validate = declarationValidator(actualRules, {variables: variables$1});
440
677
 
441
678
  // The stylelint docs suggest respecting a "disableFix" rule option that
442
679
  // overrides the "global" context.fix (--fix) linting option.
@@ -496,70 +733,7 @@ function createVariableRule(ruleName, rules, url) {
496
733
  return plugin
497
734
  }
498
735
 
499
- function noop$4() {}
500
-
501
- var borders = createVariableRule(
502
- 'primer/borders',
503
- {
504
- border: {
505
- expects: 'a border variable',
506
- props: 'border{,-top,-right,-bottom,-left}',
507
- values: ['$border', 'none', '0'],
508
- components: ['border-width', 'border-style', 'border-color'],
509
- replacements: {
510
- // because shorthand border properties ¯\_(ツ)_/¯
511
- '$border-width $border-style $border-gray': '$border',
512
- '$border-width $border-gray $border-style': '$border',
513
- '$border-style $border-width $border-gray': '$border',
514
- '$border-style $border-gray $border-width': '$border',
515
- '$border-gray $border-width $border-style': '$border',
516
- '$border-gray $border-style $border-width': '$border',
517
- '$border-width $border-style $border-color': '$border',
518
- '$border-width $border-color $border-style': '$border',
519
- '$border-style $border-width $border-color': '$border',
520
- '$border-style $border-color $border-width': '$border',
521
- '$border-color $border-width $border-style': '$border',
522
- '$border-color $border-style $border-width': '$border',
523
- },
524
- },
525
- 'border color': {
526
- expects: 'a border color variable',
527
- props: 'border{,-top,-right,-bottom,-left}-color',
528
- values: [
529
- '$border-*',
530
- 'transparent',
531
- 'currentColor',
532
- // Match variables in any of the following formats: --color-border-*, --color-*-border-*, --color-*-border, --borderColor-, *borderColor*
533
- /var\(--color-(.+-)*border(-.+)*\)/,
534
- /var\(--color-[^)]+\)/,
535
- /var\(--borderColor-[^)]+\)/,
536
- /var\((.+-)*borderColor(-.+)*\)/,
537
- ],
538
- replacements: {
539
- '$border-gray': '$border-color',
540
- },
541
- },
542
- 'border style': {
543
- expects: 'a border style variable',
544
- props: 'border{,-top,-right,-bottom,-left}-style',
545
- values: ['$border-style', 'none'],
546
- },
547
- 'border width': {
548
- expects: 'a border width variable',
549
- props: 'border{,-top,-right,-bottom,-left}-width',
550
- values: ['$border-width*', '0'],
551
- },
552
- 'border radius': {
553
- expects: 'a border radius variable',
554
- props: 'border{,-{top,bottom}-{left,right}}-radius',
555
- values: ['$border-radius', '0', '50%', 'inherit'],
556
- replacements: {
557
- '100%': '50%',
558
- },
559
- },
560
- },
561
- 'https://primer.style/css/utilities/borders',
562
- );
736
+ function noop$2() {}
563
737
 
564
738
  var boxShadow = createVariableRule(
565
739
  'primer/box-shadow',
@@ -624,9 +798,9 @@ var colors = createVariableRule(
624
798
  'https://primer.style/primitives/colors',
625
799
  );
626
800
 
627
- const ruleName$3 = 'primer/responsive-widths';
801
+ const ruleName$2 = 'primer/responsive-widths';
628
802
 
629
- const messages$3 = stylelint.utils.ruleMessages(ruleName$3, {
803
+ const messages$2 = stylelint.utils.ruleMessages(ruleName$2, {
630
804
  rejected: value => {
631
805
  return `A value larger than the smallest viewport could break responsive pages. Use a width value smaller than ${value}. https://primer.style/css/support/breakpoints`
632
806
  },
@@ -634,10 +808,10 @@ const messages$3 = stylelint.utils.ruleMessages(ruleName$3, {
634
808
 
635
809
  // 320px is the smallest viewport size that we support
636
810
 
637
- const walkGroups$1 = (root, validate) => {
811
+ const walkGroups = (root, validate) => {
638
812
  for (const node of root.nodes) {
639
813
  if (node.type === 'function') {
640
- walkGroups$1(node, validate);
814
+ walkGroups(node, validate);
641
815
  } else {
642
816
  validate(node);
643
817
  }
@@ -646,9 +820,9 @@ const walkGroups$1 = (root, validate) => {
646
820
  };
647
821
 
648
822
  // eslint-disable-next-line no-unused-vars
649
- var responsiveWidths = stylelint.createPlugin(ruleName$3, (enabled, options = {}, context) => {
823
+ var responsiveWidths = stylelint.createPlugin(ruleName$2, (enabled, options = {}, context) => {
650
824
  if (!enabled) {
651
- return noop$3
825
+ return noop$1
652
826
  }
653
827
 
654
828
  const lintResult = (root, result) => {
@@ -659,12 +833,12 @@ var responsiveWidths = stylelint.createPlugin(ruleName$3, (enabled, options = {}
659
833
  }
660
834
 
661
835
  if (decl.type !== 'decl' || !decl.prop.match(/^(min-width|width)/)) {
662
- return noop$3
836
+ return noop$1
663
837
  }
664
838
 
665
839
  const problems = [];
666
840
 
667
- walkGroups$1(valueParser(decl.value), node => {
841
+ walkGroups(valueParser(decl.value), node => {
668
842
  // Only check word types. https://github.com/TrySound/postcss-value-parser#word
669
843
  if (node.type !== 'word') {
670
844
  return
@@ -682,7 +856,7 @@ var responsiveWidths = stylelint.createPlugin(ruleName$3, (enabled, options = {}
682
856
  if (parseInt(valueUnit.number) > 320) {
683
857
  problems.push({
684
858
  index: declarationValueIndex(decl) + node.sourceIndex,
685
- message: messages$3.rejected(node.value),
859
+ message: messages$2.rejected(node.value),
686
860
  });
687
861
  }
688
862
  break
@@ -690,7 +864,7 @@ var responsiveWidths = stylelint.createPlugin(ruleName$3, (enabled, options = {}
690
864
  if (parseInt(valueUnit.number) > 100) {
691
865
  problems.push({
692
866
  index: declarationValueIndex(decl) + node.sourceIndex,
693
- message: messages$3.rejected(node.value),
867
+ message: messages$2.rejected(node.value),
694
868
  });
695
869
  }
696
870
  break
@@ -704,7 +878,7 @@ var responsiveWidths = stylelint.createPlugin(ruleName$3, (enabled, options = {}
704
878
  message: err.message,
705
879
  node: decl,
706
880
  result,
707
- ruleName: ruleName$3,
881
+ ruleName: ruleName$2,
708
882
  });
709
883
  }
710
884
  }
@@ -714,70 +888,60 @@ var responsiveWidths = stylelint.createPlugin(ruleName$3, (enabled, options = {}
714
888
  return lintResult
715
889
  });
716
890
 
717
- function noop$3() {}
718
-
719
- // TODO: Pull this in from primer/primitives
720
- const spacerValues = {
721
- '$spacer-1': '4px',
722
- '$spacer-2': '8px',
723
- '$spacer-3': '16px',
724
- '$spacer-4': '24px',
725
- '$spacer-5': '32px',
726
- '$spacer-6': '40px',
727
- '$spacer-7': '48px',
728
- '$spacer-8': '64px',
729
- '$spacer-9': '80px',
730
- '$spacer-10': '96px',
731
- '$spacer-11': '112px',
732
- '$spacer-12': '128px',
733
- '$em-spacer-1': '0.0625em',
734
- '$em-spacer-2': '0.125em',
735
- '$em-spacer-3': '0.25em',
736
- '$em-spacer-4': '0.375em',
737
- '$em-spacer-5': '0.5em',
738
- '$em-spacer-6': '0.75em',
739
- };
891
+ function noop$1() {}
740
892
 
741
- const ruleName$2 = 'primer/spacing';
742
- const messages$2 = stylelint.utils.ruleMessages(ruleName$2, {
893
+ const {
894
+ createPlugin,
895
+ utils: {report, ruleMessages, validateOptions},
896
+ } = stylelint;
897
+
898
+ const ruleName$1 = 'primer/spacing';
899
+ const messages$1 = ruleMessages(ruleName$1, {
743
900
  rejected: (value, replacement) => {
744
- if (replacement === null) {
745
- return `Please use a primer spacer variable instead of '${value}'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs`
901
+ if (!replacement) {
902
+ return `Please use a primer size variable instead of '${value}'. Consult the primer docs for a suitable replacement. https://primer.style/foundations/primitives/size`
746
903
  }
747
904
 
748
- return `Please replace ${value} with spacing variable '${replacement}'.`
905
+ return `Please replace '${value}' with size variable '${replacement['name']}'. https://primer.style/foundations/primitives/size`
749
906
  },
750
907
  });
751
908
 
752
- const walkGroups = (root, validate) => {
753
- for (const node of root.nodes) {
754
- if (node.type === 'function') {
755
- walkGroups(node, validate);
756
- } else {
757
- validate(node);
758
- }
759
- }
760
- return root
761
- };
909
+ // Props that we want to check
910
+ const propList = ['padding', 'margin', 'top', 'right', 'bottom', 'left'];
911
+ // Values that we want to ignore
912
+ const valueList = ['${'];
762
913
 
763
- // eslint-disable-next-line no-unused-vars
764
- var spacing = stylelint.createPlugin(ruleName$2, (enabled, options = {}, context) => {
765
- if (!enabled) {
766
- return noop$2
914
+ const sizes = primitivesVariables('spacing');
915
+
916
+ // Add +-1px to each value
917
+ for (const size of sizes) {
918
+ const values = size['values'];
919
+ const px = parseInt(values.find(value => value.includes('px')));
920
+ if (![2, 6].includes(px)) {
921
+ values.push(`${px + 1}px`);
922
+ values.push(`${px - 1}px`);
767
923
  }
924
+ }
768
925
 
769
- const lintResult = (root, result) => {
770
- root.walk(decl => {
771
- if (decl.type !== 'decl' || !decl.prop.match(/^(padding|margin)/)) {
772
- return noop$2
773
- }
926
+ /** @type {import('stylelint').Rule} */
927
+ const ruleFunction = (primary, secondaryOptions, context) => {
928
+ return (root, result) => {
929
+ const validOptions = validateOptions(result, ruleName$1, {
930
+ actual: primary,
931
+ possible: [true],
932
+ });
774
933
 
775
- const problems = [];
934
+ if (!validOptions) return
935
+
936
+ root.walkDecls(declNode => {
937
+ const {prop, value} = declNode;
776
938
 
777
- const parsedValue = walkGroups(valueParser(decl.value), node => {
778
- // Remove leading negative sign, if any.
779
- const cleanValue = node.value.replace(/^-/g, '');
939
+ if (!propList.some(spacingProp => prop.startsWith(spacingProp))) return
940
+ if (valueList.some(valueToIgnore => value.includes(valueToIgnore))) return
780
941
 
942
+ const problems = [];
943
+
944
+ const parsedValue = walkGroups$1(valueParser(value), node => {
781
945
  // Only check word types. https://github.com/TrySound/postcss-value-parser#word
782
946
  if (node.type !== 'word') {
783
947
  return
@@ -788,30 +952,36 @@ var spacing = stylelint.createPlugin(ruleName$2, (enabled, options = {}, context
788
952
  return
789
953
  }
790
954
 
791
- const valueUnit = valueParser.unit(cleanValue);
955
+ const valueUnit = valueParser.unit(node.value);
792
956
 
793
- if (valueUnit && (valueUnit.unit === '' || !/^[0-9.]+$/.test(valueUnit.number))) {
957
+ if (valueUnit && (valueUnit.unit === '' || !/^-?[0-9.]+$/.test(valueUnit.number))) {
794
958
  return
795
959
  }
796
960
 
797
- // If the a variable is found in the value, skip it.
961
+ // Skip if the value unit isn't a supported unit.
962
+ if (valueUnit && !['px', 'rem', 'em'].includes(valueUnit.unit)) {
963
+ return
964
+ }
965
+
966
+ // If the variable is found in the value, skip it.
798
967
  if (
799
- Object.keys(spacerValues).some(variable =>
800
- new RegExp(`${variable.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(cleanValue),
968
+ sizes.some(variable =>
969
+ new RegExp(`${variable['name'].replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(node.value),
801
970
  )
802
971
  ) {
803
972
  return
804
973
  }
805
974
 
806
- const replacement = Object.keys(spacerValues).find(spacer => spacerValues[spacer] === cleanValue) || null;
807
- const valueMatch = replacement ? spacerValues[replacement] : node.value;
975
+ const replacement = sizes.find(variable => variable.values.includes(node.value.replace('-', '')));
976
+ const fixable = replacement && valueUnit && !valueUnit.number.includes('-');
808
977
 
809
- if (replacement && context.fix) {
810
- node.value = node.value.replace(valueMatch, replacement);
978
+ if (fixable && context.fix) {
979
+ node.value = node.value.replace(node.value, `var(${replacement['name']})`);
811
980
  } else {
812
981
  problems.push({
813
- index: declarationValueIndex(decl) + node.sourceIndex,
814
- message: messages$2.rejected(valueMatch, replacement),
982
+ index: declarationValueIndex(declNode) + node.sourceIndex,
983
+ endIndex: declarationValueIndex(declNode) + node.sourceIndex + node.value.length,
984
+ message: messages$1.rejected(node.value, replacement),
815
985
  });
816
986
  }
817
987
 
@@ -819,27 +989,32 @@ var spacing = stylelint.createPlugin(ruleName$2, (enabled, options = {}, context
819
989
  });
820
990
 
821
991
  if (context.fix) {
822
- decl.value = parsedValue.toString();
992
+ declNode.value = parsedValue.toString();
823
993
  }
824
994
 
825
995
  if (problems.length) {
826
996
  for (const err of problems) {
827
- stylelint.utils.report({
997
+ report({
828
998
  index: err.index,
999
+ endIndex: err.endIndex,
829
1000
  message: err.message,
830
- node: decl,
1001
+ node: declNode,
831
1002
  result,
832
- ruleName: ruleName$2,
1003
+ ruleName: ruleName$1,
833
1004
  });
834
1005
  }
835
1006
  }
836
1007
  });
837
- };
1008
+ }
1009
+ };
838
1010
 
839
- return lintResult
840
- });
1011
+ ruleFunction.ruleName = ruleName$1;
1012
+ ruleFunction.messages = messages$1;
1013
+ ruleFunction.meta = {
1014
+ fixable: true,
1015
+ };
841
1016
 
842
- function noop$2() {}
1017
+ var spacing = createPlugin(ruleName$1, ruleFunction);
843
1018
 
844
1019
  var typography = createVariableRule(
845
1020
  'primer/typography',
@@ -864,583 +1039,6 @@ var typography = createVariableRule(
864
1039
  'https://primer.style/css/utilities/typography',
865
1040
  );
866
1041
 
867
- // Meant as temp until we can move to primitives or css
868
- const colorTypes = ['accent', 'success', 'attention', 'severe', 'danger', 'open', 'closed', 'done', 'sponsors'];
869
-
870
- var utilities$1 = {
871
- color: [
872
- {
873
- value: 'var(--color-fg-default)',
874
- utilityClass: 'color-fg-default',
875
- },
876
- {
877
- value: 'var(--color-fg-muted)',
878
- utilityClass: 'color-fg-muted',
879
- },
880
- {
881
- value: 'var(--color-fg-subtle)',
882
- utilityClass: 'color-fg-subtle',
883
- },
884
- ].concat(
885
- colorTypes.map(type => {
886
- return {
887
- value: `var(--color-${type}-fg)`,
888
- utilityClass: `color-fg-${type}`,
889
- }
890
- }),
891
- ),
892
- 'background-color': [
893
- {
894
- value: 'var(--color-canvas-default)',
895
- utilityClass: 'color-bg-default',
896
- },
897
- {
898
- value: 'var(--color-canvas-overlay)',
899
- utilityClass: 'color-bg-overlay',
900
- },
901
- {
902
- value: 'var(--color-canvas-inset)',
903
- utilityClass: 'color-bg-inset',
904
- },
905
- {
906
- value: 'var(--color-canvas-subtle)',
907
- utilityClass: 'color-bg-subtle',
908
- },
909
- {
910
- value: 'transparent',
911
- utilityClass: 'color-bg-transparent',
912
- },
913
- ]
914
- .concat(
915
- colorTypes.map(type => {
916
- return {
917
- value: `var(--color-${type}-subtle)`,
918
- utilityClass: `color-bg-${type}`,
919
- }
920
- }),
921
- )
922
- .concat(
923
- colorTypes.map(type => {
924
- return {
925
- value: `var(--color-${type}-emphasis)`,
926
- utilityClass: `color-bg-${type}-emphasis`,
927
- }
928
- }),
929
- ),
930
- 'border-color': [
931
- {
932
- value: 'var(--color-border-default',
933
- utilityClass: 'color-border-default',
934
- },
935
- {
936
- value: 'var(--color-border-muted',
937
- utilityClass: 'color-border-muted',
938
- },
939
- {
940
- value: 'var(--color-border-subtle',
941
- utilityClass: 'color-border-subtle',
942
- },
943
- ]
944
- .concat(
945
- colorTypes.map(type => {
946
- return {
947
- value: `var(--color-${type}-muted)`,
948
- utilityClass: `color-border-${type}`,
949
- }
950
- }),
951
- )
952
- .concat(
953
- colorTypes.map(type => {
954
- return {
955
- value: `var(--color-${type}-emphasis)`,
956
- utilityClass: `color-border-${type}-emphasis`,
957
- }
958
- }),
959
- ),
960
- margin: Array.from(new Array(6)).map((_, i) => {
961
- return {
962
- value: `$spacer-${i + 1}`,
963
- utilityClass: `m-${i + 1}`,
964
- }
965
- }),
966
- 'margin-top': Array.from(new Array(6)).map((_, i) => {
967
- return {
968
- value: `$spacer-${i + 1}`,
969
- utilityClass: `mt-${i + 1}`,
970
- }
971
- }),
972
- 'margin-right': Array.from(new Array(6)).map((_, i) => {
973
- return {
974
- value: `$spacer-${i + 1}`,
975
- utilityClass: `mr-${i + 1}`,
976
- }
977
- }),
978
- 'margin-bottom': Array.from(new Array(6)).map((_, i) => {
979
- return {
980
- value: `$spacer-${i + 1}`,
981
- utilityClass: `mb-${i + 1}`,
982
- }
983
- }),
984
- 'margin-left': Array.from(new Array(6)).map((_, i) => {
985
- return {
986
- value: `$spacer-${i + 1}`,
987
- utilityClass: `ml-${i + 1}`,
988
- }
989
- }),
990
- padding: Array.from(new Array(6)).map((_, i) => {
991
- return {
992
- value: `$spacer-${i + 1}`,
993
- utilityClass: `p-${i + 1}`,
994
- }
995
- }),
996
- 'padding-top': Array.from(new Array(6)).map((_, i) => {
997
- return {
998
- value: `$spacer-${i + 1}`,
999
- utilityClass: `pt-${i + 1}`,
1000
- }
1001
- }),
1002
- 'padding-right': Array.from(new Array(6)).map((_, i) => {
1003
- return {
1004
- value: `$spacer-${i + 1}`,
1005
- utilityClass: `pr-${i + 1}`,
1006
- }
1007
- }),
1008
- 'padding-bottom': Array.from(new Array(6)).map((_, i) => {
1009
- return {
1010
- value: `$spacer-${i + 1}`,
1011
- utilityClass: `pb-${i + 1}`,
1012
- }
1013
- }),
1014
- 'padding-left': Array.from(new Array(6)).map((_, i) => {
1015
- return {
1016
- value: `$spacer-${i + 1}`,
1017
- utilityClass: `pl-${i + 1}`,
1018
- }
1019
- }),
1020
- 'line-height': [
1021
- {
1022
- value: '$lh-condensed-ultra',
1023
- utilityClass: 'lh-condensed-ultra',
1024
- },
1025
- {
1026
- value: '$lh-condensed',
1027
- utilityClass: 'lh-condensed',
1028
- },
1029
- {
1030
- value: '$lh-default',
1031
- utilityClass: 'lh-default',
1032
- },
1033
- {
1034
- value: '0',
1035
- utilityClass: 'lh-0',
1036
- },
1037
- ],
1038
- 'text-align': [
1039
- {
1040
- value: 'left',
1041
- utilityClass: 'text-left',
1042
- },
1043
- {
1044
- value: 'right',
1045
- utilityClass: 'text-right',
1046
- },
1047
- {
1048
- value: 'center',
1049
- utilityClass: 'text-center',
1050
- },
1051
- ],
1052
- 'font-style': [
1053
- {
1054
- value: 'italic',
1055
- utilityClass: 'text-italic',
1056
- },
1057
- ],
1058
- 'text-transform': [
1059
- {
1060
- value: 'uppercase',
1061
- utilityClass: 'text-uppercase',
1062
- },
1063
- ],
1064
- 'text-decoration': [
1065
- {
1066
- value: 'underline',
1067
- utilityClass: 'text-underline',
1068
- },
1069
- {
1070
- value: 'none',
1071
- utilityClass: 'no-underline',
1072
- },
1073
- ],
1074
- 'white-space': [
1075
- {
1076
- value: 'nowrap',
1077
- utilityClass: 'no-wrap',
1078
- },
1079
- {
1080
- value: 'normal',
1081
- utilityClass: 'ws-normal',
1082
- },
1083
- ],
1084
- 'word-break': [
1085
- {
1086
- value: 'break-all',
1087
- utilityClass: 'wb-break-all',
1088
- },
1089
- ],
1090
- width: [
1091
- {
1092
- value: '100%',
1093
- utilityClass: 'width-full',
1094
- },
1095
- {
1096
- value: 'auto%',
1097
- utilityClass: 'width-auto',
1098
- },
1099
- ],
1100
- overflow: [
1101
- {
1102
- value: 'visible',
1103
- utilityClass: 'overflow-visible',
1104
- },
1105
- {
1106
- value: 'hidden',
1107
- utilityClass: 'overflow-hidden',
1108
- },
1109
- {
1110
- value: 'auto',
1111
- utilityClass: 'overflow-auto',
1112
- },
1113
- {
1114
- value: 'scroll',
1115
- utilityClass: 'overflow-scroll',
1116
- },
1117
- ],
1118
- 'overflow-x': [
1119
- {
1120
- value: 'visible',
1121
- utilityClass: 'overflow-x-visible',
1122
- },
1123
- {
1124
- value: 'hidden',
1125
- utilityClass: 'overflow-x-hidden',
1126
- },
1127
- {
1128
- value: 'auto',
1129
- utilityClass: 'overflow-x-auto',
1130
- },
1131
- {
1132
- value: 'scroll',
1133
- utilityClass: 'overflow-x-scroll',
1134
- },
1135
- ],
1136
- 'overflow-y': [
1137
- {
1138
- value: 'visible',
1139
- utilityClass: 'overflow-y-visible',
1140
- },
1141
- {
1142
- value: 'hidden',
1143
- utilityClass: 'overflow-y-hidden',
1144
- },
1145
- {
1146
- value: 'auto',
1147
- utilityClass: 'overflow-y-auto',
1148
- },
1149
- {
1150
- value: 'scroll',
1151
- utilityClass: 'overflow-y-scroll',
1152
- },
1153
- ],
1154
- height: [
1155
- {
1156
- value: '100%',
1157
- utilityClass: 'height-full',
1158
- },
1159
- ],
1160
- 'max-width': [
1161
- {
1162
- value: '100%',
1163
- utilityClass: 'width-fit',
1164
- },
1165
- ],
1166
- 'max-height': [
1167
- {
1168
- value: '100%',
1169
- utilityClass: 'height-fit',
1170
- },
1171
- ],
1172
- 'min-width': [
1173
- {
1174
- value: '0',
1175
- utilityClass: 'min-width-0',
1176
- },
1177
- ],
1178
- float: [
1179
- {
1180
- value: 'left',
1181
- utilityClass: 'float-left',
1182
- },
1183
- {
1184
- value: 'right',
1185
- utilityClass: 'float-right',
1186
- },
1187
- {
1188
- value: 'none',
1189
- utilityClass: 'float-none',
1190
- },
1191
- ],
1192
- 'list-style': [
1193
- {
1194
- value: 'none',
1195
- utilityClass: 'list-style-none',
1196
- },
1197
- ],
1198
- 'user-select': [
1199
- {
1200
- value: 'none',
1201
- utilityClass: 'user-select-none',
1202
- },
1203
- ],
1204
- visibility: [
1205
- {
1206
- value: 'hidden',
1207
- utilityClass: 'v-hidden',
1208
- },
1209
- {
1210
- value: 'visible',
1211
- utilityClass: 'v-visible',
1212
- },
1213
- ],
1214
- 'vertical-align': [
1215
- {
1216
- value: 'middle',
1217
- utilityClass: 'v-align-middle',
1218
- },
1219
- {
1220
- value: 'top',
1221
- utilityClass: 'v-align-top',
1222
- },
1223
- {
1224
- value: 'bottom',
1225
- utilityClass: 'v-align-bottom',
1226
- },
1227
- {
1228
- value: 'text-top',
1229
- utilityClass: 'v-align-text-top',
1230
- },
1231
- {
1232
- value: 'text-bottom',
1233
- utilityClass: 'v-align-text-bottom',
1234
- },
1235
- {
1236
- value: 'text-baseline',
1237
- utilityClass: 'v-align-baseline',
1238
- },
1239
- ],
1240
- 'font-weight': [
1241
- {
1242
- value: '$font-weight-normal',
1243
- utilityClass: 'text-normal',
1244
- },
1245
- {
1246
- value: '$font-weight-bold',
1247
- utilityClass: 'text-bold',
1248
- },
1249
- {
1250
- value: '$font-weight-semibold',
1251
- utilityClass: 'text-semibold',
1252
- },
1253
- {
1254
- value: '$font-weight-light',
1255
- utilityClass: 'text-light',
1256
- },
1257
- ],
1258
- top: [
1259
- {
1260
- value: '0',
1261
- utilityClass: 'top-0',
1262
- },
1263
- {
1264
- value: 'auto',
1265
- utilityClass: 'top-auto',
1266
- },
1267
- ],
1268
- right: [
1269
- {
1270
- value: '0',
1271
- utilityClass: 'right-0',
1272
- },
1273
- {
1274
- value: 'auto',
1275
- utilityClass: 'right-auto',
1276
- },
1277
- ],
1278
- bottom: [
1279
- {
1280
- value: '0',
1281
- utilityClass: 'bottom-0',
1282
- },
1283
- {
1284
- value: 'auto',
1285
- utilityClass: 'bottom-auto',
1286
- },
1287
- ],
1288
- left: [
1289
- {
1290
- value: '0',
1291
- utilityClass: 'left-0',
1292
- },
1293
- {
1294
- value: 'auto',
1295
- utilityClass: 'left-auto',
1296
- },
1297
- ],
1298
- position: [
1299
- {
1300
- value: 'static',
1301
- utilityClass: 'position-static',
1302
- },
1303
- {
1304
- value: 'relative',
1305
- utilityClass: 'position-relative',
1306
- },
1307
- {
1308
- value: 'absolute',
1309
- utilityClass: 'position-absolute',
1310
- },
1311
- {
1312
- value: 'fixed',
1313
- utilityClass: 'position-fixed',
1314
- },
1315
- {
1316
- value: 'sticky',
1317
- utilityClass: 'position-sticky',
1318
- },
1319
- ],
1320
- 'box-shadow': [
1321
- {
1322
- value: 'none',
1323
- utilityClass: 'box-shadow-none',
1324
- },
1325
- {
1326
- value: 'var(--color-shadow-small)',
1327
- utilityClass: 'box-shadow-small',
1328
- },
1329
- {
1330
- value: 'var(--color-shadow-medium)',
1331
- utilityClass: 'box-shadow-medium',
1332
- },
1333
- {
1334
- value: 'var(--color-shadow-large)',
1335
- utilityClass: 'box-shadow-large',
1336
- },
1337
- {
1338
- value: 'var(--color-shadow-extra-large)',
1339
- utilityClass: 'box-shadow-extra-large',
1340
- },
1341
- ],
1342
- border: [
1343
- {
1344
- value: '$border',
1345
- utilityClass: 'border',
1346
- },
1347
- {
1348
- value: '0',
1349
- utilityClass: 'border-0',
1350
- },
1351
- ],
1352
- 'border-top': [
1353
- {
1354
- value: '$border',
1355
- utilityClass: 'border-top',
1356
- },
1357
- {
1358
- value: '0',
1359
- utilityClass: 'border-top-0',
1360
- },
1361
- ],
1362
- 'border-right': [
1363
- {
1364
- value: '$border',
1365
- utilityClass: 'border-right',
1366
- },
1367
- {
1368
- value: '0',
1369
- utilityClass: 'border-right-0',
1370
- },
1371
- ],
1372
- 'border-bottom': [
1373
- {
1374
- value: '$border',
1375
- utilityClass: 'border-bottom',
1376
- },
1377
- {
1378
- value: '0',
1379
- utilityClass: 'border-bottom-0',
1380
- },
1381
- ],
1382
- 'border-left': [
1383
- {
1384
- value: '$border',
1385
- utilityClass: 'border-left',
1386
- },
1387
- {
1388
- value: '0',
1389
- utilityClass: 'border-left-0',
1390
- },
1391
- ],
1392
- };
1393
-
1394
- const ruleName$1 = 'primer/utilities';
1395
-
1396
- const messages$1 = stylelint.utils.ruleMessages(ruleName$1, {
1397
- rejected: (selector, utilityClass) => {
1398
- return `Consider using the Primer utility '.${utilityClass}' instead of the selector '${selector}' in your html. https://primer.style/css/utilities`
1399
- },
1400
- });
1401
-
1402
- // eslint-disable-next-line no-unused-vars
1403
- var utilities = stylelint.createPlugin(ruleName$1, (enabled, options = {}, context) => {
1404
- if (!enabled) {
1405
- return noop$1
1406
- }
1407
-
1408
- const utilityReplacement = (declaration, value) => {
1409
- const declarationUtilities = utilities$1[declaration];
1410
- if (declarationUtilities) {
1411
- return declarationUtilities.find(utility => {
1412
- return utility.value === value
1413
- })
1414
- }
1415
- };
1416
-
1417
- const lintResult = (root, result) => {
1418
- root.walkRules(rule => {
1419
- if (!/^\.[\w\-_]+$/.exec(rule.selector)) {
1420
- return
1421
- }
1422
- const decls = rule.nodes.filter(decl => decl.type === 'decl');
1423
-
1424
- if (decls.length === 1) {
1425
- const replacement = utilityReplacement(decls[0].prop, decls[0].value);
1426
- if (replacement) {
1427
- stylelint.utils.report({
1428
- index: rule.sourceIndex,
1429
- message: messages$1.rejected(rule.selector, replacement.utilityClass),
1430
- node: rule,
1431
- result,
1432
- ruleName: ruleName$1,
1433
- });
1434
- }
1435
- }
1436
- });
1437
- };
1438
-
1439
- return lintResult
1440
- });
1441
-
1442
- function noop$1() {}
1443
-
1444
1042
  const ruleName = 'primer/no-display-colors';
1445
1043
  const messages = stylelint.utils.ruleMessages(ruleName, {
1446
1044
  rejected: varName => `${varName} is in alpha and should be used with caution with approval from the Primer team`,
@@ -1506,7 +1104,6 @@ var index = {
1506
1104
  responsiveWidths,
1507
1105
  spacing,
1508
1106
  typography,
1509
- utilities,
1510
1107
  noDisplayColors,
1511
1108
  ],
1512
1109
  rules: {
@@ -1574,7 +1171,6 @@ var index = {
1574
1171
  'primer/responsive-widths': true,
1575
1172
  'primer/spacing': true,
1576
1173
  'primer/typography': true,
1577
- 'primer/utilities': null,
1578
1174
  'primer/no-display-colors': true,
1579
1175
  'property-no-unknown': [
1580
1176
  true,
@@ -1625,12 +1221,9 @@ var index = {
1625
1221
  'comment-empty-line-before': null,
1626
1222
  'length-zero-no-unit': null,
1627
1223
  'selector-max-type': null,
1628
- 'primer/spacing': null,
1629
1224
  'primer/colors': null,
1630
- 'primer/borders': null,
1631
1225
  'primer/typography': null,
1632
1226
  'primer/box-shadow': null,
1633
- 'primer/utilities': null,
1634
1227
  },
1635
1228
  },
1636
1229
  {
@@ -1655,6 +1248,7 @@ var index = {
1655
1248
  },
1656
1249
  {
1657
1250
  files: ['**/*.module.css'],
1251
+ plugins: ['stylelint-css-modules-no-global-scoped-selector'],
1658
1252
  rules: {
1659
1253
  'property-no-unknown': [
1660
1254
  true,
@@ -1679,12 +1273,10 @@ var index = {
1679
1273
  ignoreFunctions: ['global'],
1680
1274
  },
1681
1275
  ],
1276
+ 'css-modules/no-global-scoped-selector': true,
1682
1277
  // temporarily disabiling Primer plugins while we work on upgrades https://github.com/github/primer/issues/3165
1683
- 'primer/spacing': null,
1684
- 'primer/borders': null,
1685
1278
  'primer/typography': null,
1686
1279
  'primer/box-shadow': null,
1687
- 'primer/utilities': null,
1688
1280
  },
1689
1281
  },
1690
1282
  ],