@primer/stylelint-config 13.5.0 → 13.6.0-rc.55219cf

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 CHANGED
@@ -10,13 +10,16 @@ var matchAll = require('string.prototype.matchall');
10
10
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
11
11
  const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
12
12
 
13
- function primitivesVariables(type) {
13
+ function primitivesVariables(type, options = {}) {
14
14
  const variables = [];
15
15
 
16
16
  const files = [];
17
17
  switch (type) {
18
18
  case 'spacing':
19
19
  files.push('base/size/size.json');
20
+ if (options.includeFunctional) {
21
+ files.push('functional/size/size.json');
22
+ }
20
23
  break
21
24
  case 'border':
22
25
  files.push('functional/size/border.json');
@@ -669,8 +672,18 @@ const messages$2 = ruleMessages$1(ruleName$2, {
669
672
  const propList$1 = ['padding', 'margin', 'top', 'right', 'bottom', 'left'];
670
673
  // Values that we want to ignore
671
674
  const valueList = ['${'];
675
+ // Exact keyword values that we want to ignore (remain as-is, e.g. `padding: unset`)
676
+ const ignoredExactValues = ['*', '+', '-', '/', '0', 'auto', 'inherit', 'initial', 'unset'];
672
677
 
673
678
  const sizes = primitivesVariables('spacing');
679
+ const allowedSizeVars = primitivesVariables('spacing', {includeFunctional: true});
680
+
681
+ const escapeForRegExp = string => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
682
+
683
+ const allowedSizeVarMatchers = allowedSizeVars.map(variable => {
684
+ const escapedName = escapeForRegExp(variable['name']);
685
+ return new RegExp(`${escapedName}\\b`)
686
+ });
674
687
 
675
688
  // Add +-1px to each value
676
689
  for (const size of sizes) {
@@ -705,7 +718,7 @@ const ruleFunction$1 = primary => {
705
718
  }
706
719
 
707
720
  // Exact values to ignore.
708
- if (['*', '+', '-', '/', '0', 'auto', 'inherit', 'initial'].includes(node.value)) {
721
+ if (ignoredExactValues.includes(node.value)) {
709
722
  return
710
723
  }
711
724
 
@@ -721,11 +734,7 @@ const ruleFunction$1 = primary => {
721
734
  }
722
735
 
723
736
  // If the variable is found in the value, skip it.
724
- if (
725
- sizes.some(variable =>
726
- new RegExp(`${variable['name'].replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(node.value),
727
- )
728
- ) {
737
+ if (allowedSizeVarMatchers.some(matcher => matcher.test(node.value))) {
729
738
  return
730
739
  }
731
740
 
package/dist/index.mjs CHANGED
@@ -7,13 +7,16 @@ import matchAll from 'string.prototype.matchall';
7
7
 
8
8
  const require$2 = createRequire(import.meta.url);
9
9
 
10
- function primitivesVariables(type) {
10
+ function primitivesVariables(type, options = {}) {
11
11
  const variables = [];
12
12
 
13
13
  const files = [];
14
14
  switch (type) {
15
15
  case 'spacing':
16
16
  files.push('base/size/size.json');
17
+ if (options.includeFunctional) {
18
+ files.push('functional/size/size.json');
19
+ }
17
20
  break
18
21
  case 'border':
19
22
  files.push('functional/size/border.json');
@@ -666,8 +669,18 @@ const messages$2 = ruleMessages$1(ruleName$2, {
666
669
  const propList$1 = ['padding', 'margin', 'top', 'right', 'bottom', 'left'];
667
670
  // Values that we want to ignore
668
671
  const valueList = ['${'];
672
+ // Exact keyword values that we want to ignore (remain as-is, e.g. `padding: unset`)
673
+ const ignoredExactValues = ['*', '+', '-', '/', '0', 'auto', 'inherit', 'initial', 'unset'];
669
674
 
670
675
  const sizes = primitivesVariables('spacing');
676
+ const allowedSizeVars = primitivesVariables('spacing', {includeFunctional: true});
677
+
678
+ const escapeForRegExp = string => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
679
+
680
+ const allowedSizeVarMatchers = allowedSizeVars.map(variable => {
681
+ const escapedName = escapeForRegExp(variable['name']);
682
+ return new RegExp(`${escapedName}\\b`)
683
+ });
671
684
 
672
685
  // Add +-1px to each value
673
686
  for (const size of sizes) {
@@ -702,7 +715,7 @@ const ruleFunction$1 = primary => {
702
715
  }
703
716
 
704
717
  // Exact values to ignore.
705
- if (['*', '+', '-', '/', '0', 'auto', 'inherit', 'initial'].includes(node.value)) {
718
+ if (ignoredExactValues.includes(node.value)) {
706
719
  return
707
720
  }
708
721
 
@@ -718,11 +731,7 @@ const ruleFunction$1 = primary => {
718
731
  }
719
732
 
720
733
  // If the variable is found in the value, skip it.
721
- if (
722
- sizes.some(variable =>
723
- new RegExp(`${variable['name'].replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(node.value),
724
- )
725
- ) {
734
+ if (allowedSizeVarMatchers.some(matcher => matcher.test(node.value))) {
726
735
  return
727
736
  }
728
737
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/stylelint-config",
3
- "version": "13.5.0",
3
+ "version": "13.6.0-rc.55219cf",
4
4
  "description": "Sharable stylelint config used by GitHub's CSS",
5
5
  "author": "GitHub, Inc.",
6
6
  "license": "MIT",
@@ -2,13 +2,16 @@ import {createRequire} from 'node:module'
2
2
 
3
3
  const require = createRequire(import.meta.url)
4
4
 
5
- export function primitivesVariables(type) {
5
+ export function primitivesVariables(type, options = {}) {
6
6
  const variables = []
7
7
 
8
8
  const files = []
9
9
  switch (type) {
10
10
  case 'spacing':
11
11
  files.push('base/size/size.json')
12
+ if (options.includeFunctional) {
13
+ files.push('functional/size/size.json')
14
+ }
12
15
  break
13
16
  case 'border':
14
17
  files.push('functional/size/border.json')
@@ -23,8 +23,18 @@ export const messages = ruleMessages(ruleName, {
23
23
  const propList = ['padding', 'margin', 'top', 'right', 'bottom', 'left']
24
24
  // Values that we want to ignore
25
25
  const valueList = ['${']
26
+ // Exact keyword values that we want to ignore (remain as-is, e.g. `padding: unset`)
27
+ const ignoredExactValues = ['*', '+', '-', '/', '0', 'auto', 'inherit', 'initial', 'unset']
26
28
 
27
29
  const sizes = primitivesVariables('spacing')
30
+ const allowedSizeVars = primitivesVariables('spacing', {includeFunctional: true})
31
+
32
+ const escapeForRegExp = string => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
33
+
34
+ const allowedSizeVarMatchers = allowedSizeVars.map(variable => {
35
+ const escapedName = escapeForRegExp(variable['name'])
36
+ return new RegExp(`${escapedName}\\b`)
37
+ })
28
38
 
29
39
  // Add +-1px to each value
30
40
  for (const size of sizes) {
@@ -59,7 +69,7 @@ const ruleFunction = primary => {
59
69
  }
60
70
 
61
71
  // Exact values to ignore.
62
- if (['*', '+', '-', '/', '0', 'auto', 'inherit', 'initial'].includes(node.value)) {
72
+ if (ignoredExactValues.includes(node.value)) {
63
73
  return
64
74
  }
65
75
 
@@ -75,11 +85,7 @@ const ruleFunction = primary => {
75
85
  }
76
86
 
77
87
  // If the variable is found in the value, skip it.
78
- if (
79
- sizes.some(variable =>
80
- new RegExp(`${variable['name'].replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(node.value),
81
- )
82
- ) {
88
+ if (allowedSizeVarMatchers.some(matcher => matcher.test(node.value))) {
83
89
  return
84
90
  }
85
91