@primer/stylelint-config 12.7.0-rc.f3bb1ab → 12.7.1-rc.1402572

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.
@@ -1,21 +1,14 @@
1
1
  const stylelint = require('stylelint')
2
- const kebabCase = require('lodash.kebabcase')
3
2
  const matchAll = require('string.prototype.matchall')
4
3
 
5
4
  const ruleName = 'primer/no-deprecated-colors'
6
5
  const messages = stylelint.utils.ruleMessages(ruleName, {
7
- rejected: (varName, replacement) => {
6
+ rejected: (varName, replacement, property) => {
8
7
  if (replacement === null) {
9
- return `${varName} is a deprecated color variable. Please consult the primer color docs for a replacement. https://primer.style/primitives`
8
+ return `Variable ${varName} is deprecated for property ${property}. Please consult the primer color docs for a replacement. https://primer.style/primitives/storybook/?path=/story/migration-tables`
10
9
  }
11
10
 
12
- if (Array.isArray(replacement)) {
13
- replacement = replacement.map(r => `--color-${kebabCase(r)}`)
14
- return `${varName} is a deprecated color variable. Please use one of (${replacement.join(', ')}).`
15
- }
16
-
17
- replacement = `--color-${kebabCase(replacement)}`
18
- return `${varName} is a deprecated color variable. Please use the replacement ${replacement}.`
11
+ return `Variable ${varName} is deprecated for property ${property}. Please use the replacement ${replacement}.`
19
12
  }
20
13
  })
21
14
 
@@ -39,20 +32,7 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
39
32
  const seen = new WeakMap()
40
33
 
41
34
  // eslint-disable-next-line import/no-dynamic-require
42
- const deprecatedColors = require(options.deprecatedFile || '@primer/primitives/dist/deprecated/colors.json')
43
- // eslint-disable-next-line import/no-dynamic-require
44
- const removedColors = require(options.removedFile || '@primer/primitives/dist/removed/colors.json')
45
-
46
- const variableChecks = Object.assign(deprecatedColors, removedColors)
47
-
48
- const convertedCSSVars = Object.entries(variableChecks)
49
- .map(([k, v]) => {
50
- return [`--color-${kebabCase(k)}`, v]
51
- })
52
- .reduce((acc, [key, value]) => {
53
- acc[key] = value
54
- return acc
55
- }, {})
35
+ const variableChecks = require(options.deprecatedFile || './lib/primitives-v8.json')
56
36
 
57
37
  const lintResult = (root, result) => {
58
38
  // Walk all declarations
@@ -62,20 +42,32 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
62
42
  } else {
63
43
  seen.set(node, true)
64
44
  }
45
+
65
46
  // walk these nodes
66
- if (!(node.type === 'decl' || node.type === 'atrule')) {
47
+ if (node.type !== 'decl') {
67
48
  return
68
49
  }
69
50
 
70
- for (const [, variableName] of matchAll(
71
- node.type === 'atrule' ? node.params : node.value,
72
- variableReferenceRegex
73
- )) {
74
- if (variableName in convertedCSSVars) {
75
- let replacement = convertedCSSVars[variableName]
51
+ for (const [, variableName] of matchAll(node.value, variableReferenceRegex)) {
52
+ if (variableName in variableChecks) {
53
+ let replacement = variableChecks[variableName]
54
+ if (typeof replacement === 'object') {
55
+ if (node.prop) {
56
+ for (const prop of replacement) {
57
+ // Check if node.prop starts with one of the props array elements
58
+ if (prop['props'].some(p => node.prop.startsWith(p))) {
59
+ replacement = prop['replacement']
60
+ break
61
+ }
62
+ }
63
+ }
64
+ if (typeof replacement === 'object') {
65
+ replacement = null
66
+ }
67
+ }
76
68
 
77
- if (context.fix && replacement !== null && !Array.isArray(replacement)) {
78
- replacement = `--color-${kebabCase(replacement)}`
69
+ if (context.fix && replacement !== null) {
70
+ replacement = `${replacement}`
79
71
  replacedVars[variableName] = true
80
72
  newVars[replacement] = true
81
73
  if (node.type === 'atrule') {
@@ -87,7 +79,7 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
87
79
  }
88
80
 
89
81
  stylelint.utils.report({
90
- message: messages.rejected(variableName, replacement),
82
+ message: messages.rejected(variableName, replacement, node.prop),
91
83
  node,
92
84
  ruleName,
93
85
  result