@primer/stylelint-config 12.7.1-rc.59e46db → 12.7.1-rc.7ed22ed

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.
@@ -3,12 +3,12 @@ const matchAll = require('string.prototype.matchall')
3
3
 
4
4
  const ruleName = 'primer/no-deprecated-colors'
5
5
  const messages = stylelint.utils.ruleMessages(ruleName, {
6
- rejected: (varName, replacement) => {
6
+ rejected: (varName, replacement, property) => {
7
7
  if (replacement === null) {
8
- return `${varName} is a deprecated color variable. Please consult the primer color docs for a replacement. https://primer.style/primitives/storybook/?path=/story/migration-tables`
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`
9
9
  }
10
10
 
11
- 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}.`
12
12
  }
13
13
  })
14
14
 
@@ -32,7 +32,7 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
32
32
  const seen = new WeakMap()
33
33
 
34
34
  // eslint-disable-next-line import/no-dynamic-require
35
- const variableChecks = require(options.deprecatedFile || '../__tests__/__fixtures__/primitives-v8.json')
35
+ const variableChecks = require(options.deprecatedFile || './lib/primitives-v8.json')
36
36
 
37
37
  const lintResult = (root, result) => {
38
38
  // Walk all declarations
@@ -44,21 +44,21 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
44
44
  }
45
45
 
46
46
  // walk these nodes
47
- if (!(node.type === 'decl' || node.type === 'atrule')) {
47
+ if (node.type !== 'decl') {
48
48
  return
49
49
  }
50
50
 
51
- for (const [, variableName] of matchAll(
52
- node.type === 'atrule' ? node.params : node.value,
53
- variableReferenceRegex
54
- )) {
51
+ for (const [, variableName] of matchAll(node.value, variableReferenceRegex)) {
55
52
  if (variableName in variableChecks) {
56
53
  let replacement = variableChecks[variableName]
57
54
  if (typeof replacement === 'object') {
58
- for (const property of Object.keys(replacement)) {
59
- if (node.prop.includes(property)) {
60
- replacement = replacement[property]
61
- break
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
62
  }
63
63
  }
64
64
  if (typeof replacement === 'object') {
@@ -67,7 +67,7 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
67
67
  }
68
68
 
69
69
  if (context.fix && replacement !== null) {
70
- replacement = `${replacement}, var(${variableName})`
70
+ replacement = `${replacement}`
71
71
  replacedVars[variableName] = true
72
72
  newVars[replacement] = true
73
73
  if (node.type === 'atrule') {
@@ -79,7 +79,7 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
79
79
  }
80
80
 
81
81
  stylelint.utils.report({
82
- message: messages.rejected(variableName, replacement),
82
+ message: messages.rejected(variableName, replacement, node.prop),
83
83
  node,
84
84
  ruleName,
85
85
  result