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

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,6 +42,7 @@ 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
47
  if (!(node.type === 'decl' || node.type === 'atrule')) {
67
48
  return
@@ -71,11 +52,25 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
71
52
  node.type === 'atrule' ? node.params : node.value,
72
53
  variableReferenceRegex
73
54
  )) {
74
- if (variableName in convertedCSSVars) {
75
- let replacement = convertedCSSVars[variableName]
55
+ if (variableName in variableChecks) {
56
+ let replacement = variableChecks[variableName]
57
+ if (typeof replacement === 'object') {
58
+ if (node.prop) {
59
+ for (const prop of replacement) {
60
+ // Check if node.prop starts with one of the props array elements
61
+ if (prop['props'].some(p => node.prop.startsWith(p))) {
62
+ replacement = prop['replacement']
63
+ break
64
+ }
65
+ }
66
+ }
67
+ if (typeof replacement === 'object') {
68
+ replacement = null
69
+ }
70
+ }
76
71
 
77
- if (context.fix && replacement !== null && !Array.isArray(replacement)) {
78
- replacement = `--color-${kebabCase(replacement)}`
72
+ if (context.fix && replacement !== null) {
73
+ replacement = `${replacement}, var(${variableName})`
79
74
  replacedVars[variableName] = true
80
75
  newVars[replacement] = true
81
76
  if (node.type === 'atrule') {
@@ -87,7 +82,7 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
87
82
  }
88
83
 
89
84
  stylelint.utils.report({
90
- message: messages.rejected(variableName, replacement),
85
+ message: messages.rejected(variableName, replacement, node.prop),
91
86
  node,
92
87
  ruleName,
93
88
  result