@nordcraft/search 1.0.79 → 1.0.80

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.
Files changed (140) hide show
  1. package/dist/rules/issues/actions/duplicateActionArgumentNameRule.test.js +3 -3
  2. package/dist/rules/issues/actions/duplicateActionArgumentNameRule.test.js.map +1 -1
  3. package/dist/rules/issues/actions/legacyActionRule.test.js +1 -1
  4. package/dist/rules/issues/actions/legacyActionRule.test.js.map +1 -1
  5. package/dist/rules/issues/actions/noReferenceProjectActionRule.test.js +1 -1
  6. package/dist/rules/issues/actions/noReferenceProjectActionRule.test.js.map +1 -1
  7. package/dist/rules/issues/actions/unknownActionArgumentRule.test.js +1 -1
  8. package/dist/rules/issues/actions/unknownActionArgumentRule.test.js.map +1 -1
  9. package/dist/rules/issues/actions/unknownActionEventRule.test.js +1 -1
  10. package/dist/rules/issues/actions/unknownActionEventRule.test.js.map +1 -1
  11. package/dist/rules/issues/actions/unknownProjectActionRule.test.js +1 -1
  12. package/dist/rules/issues/actions/unknownProjectActionRule.test.js.map +1 -1
  13. package/dist/rules/issues/apis/legacyApiRule.test.js +1 -1
  14. package/dist/rules/issues/apis/legacyApiRule.test.js.map +1 -1
  15. package/dist/rules/issues/apis/noReferenceApiRule.js +21 -1
  16. package/dist/rules/issues/apis/noReferenceApiRule.js.map +1 -1
  17. package/dist/rules/issues/apis/noReferenceApiRule.test.js +274 -0
  18. package/dist/rules/issues/apis/noReferenceApiRule.test.js.map +1 -1
  19. package/dist/rules/issues/context/noContextConsumersRule.test.js +3 -3
  20. package/dist/rules/issues/context/noContextConsumersRule.test.js.map +1 -1
  21. package/dist/rules/issues/context/unknownContextFormulaRule.test.js +1 -1
  22. package/dist/rules/issues/context/unknownContextFormulaRule.test.js.map +1 -1
  23. package/dist/rules/issues/context/unknownContextProviderFormulaRule.test.js +1 -1
  24. package/dist/rules/issues/context/unknownContextProviderFormulaRule.test.js.map +1 -1
  25. package/dist/rules/issues/context/unknownContextProviderRule.test.js +1 -1
  26. package/dist/rules/issues/context/unknownContextProviderRule.test.js.map +1 -1
  27. package/dist/rules/issues/dom/createRequiredDirectChildRule.test.js +1 -1
  28. package/dist/rules/issues/dom/createRequiredDirectChildRule.test.js.map +1 -1
  29. package/dist/rules/issues/dom/createRequiredDirectParentRule.test.js +1 -1
  30. package/dist/rules/issues/dom/createRequiredDirectParentRule.test.js.map +1 -1
  31. package/dist/rules/issues/dom/createRequiredElementAttributeRule.test.js +3 -3
  32. package/dist/rules/issues/dom/createRequiredElementAttributeRule.test.js.map +1 -1
  33. package/dist/rules/issues/dom/elementWithoutInteractiveContentRule.test.js +3 -3
  34. package/dist/rules/issues/dom/elementWithoutInteractiveContentRule.test.js.map +1 -1
  35. package/dist/rules/issues/dom/imageWithoutDimensionRule.test.js +4 -4
  36. package/dist/rules/issues/dom/imageWithoutDimensionRule.test.js.map +1 -1
  37. package/dist/rules/issues/dom/nonEmptyVoidElementRule.test.js +1 -1
  38. package/dist/rules/issues/dom/nonEmptyVoidElementRule.test.js.map +1 -1
  39. package/dist/rules/issues/events/duplicateEventTriggerRule.test.js +1 -1
  40. package/dist/rules/issues/events/duplicateEventTriggerRule.test.js.map +1 -1
  41. package/dist/rules/issues/formulas/duplicateFormulaArgumentNameRule.test.js +2 -2
  42. package/dist/rules/issues/formulas/duplicateFormulaArgumentNameRule.test.js.map +1 -1
  43. package/dist/rules/issues/formulas/noReferenceProjectFormulaRule.test.js +1 -1
  44. package/dist/rules/issues/formulas/noReferenceProjectFormulaRule.test.js.map +1 -1
  45. package/dist/rules/issues/formulas/unknownComponentFormulaInputRule.test.js +2 -2
  46. package/dist/rules/issues/formulas/unknownComponentFormulaInputRule.test.js.map +1 -1
  47. package/dist/rules/issues/formulas/unknownProjectFormulaInputRule.test.js +2 -2
  48. package/dist/rules/issues/formulas/unknownProjectFormulaInputRule.test.js.map +1 -1
  49. package/dist/rules/issues/formulas/unknownProjectFormulaRule.test.js +1 -1
  50. package/dist/rules/issues/formulas/unknownProjectFormulaRule.test.js.map +1 -1
  51. package/dist/rules/issues/formulas/unknownRepeatIndexFormulaRule.test.js +1 -1
  52. package/dist/rules/issues/formulas/unknownRepeatIndexFormulaRule.test.js.map +1 -1
  53. package/dist/rules/issues/formulas/unknownRepeatItemFormulaRule.test.js +1 -1
  54. package/dist/rules/issues/formulas/unknownRepeatItemFormulaRule.test.js.map +1 -1
  55. package/dist/rules/issues/logic/noStaticNodeCondition.test.js +1 -1
  56. package/dist/rules/issues/logic/noStaticNodeCondition.test.js.map +1 -1
  57. package/dist/rules/issues/logic/noUnnecessaryConditionFalsy.test.js +1 -1
  58. package/dist/rules/issues/logic/noUnnecessaryConditionFalsy.test.js.map +1 -1
  59. package/dist/rules/issues/logic/noUnnecessaryConditionTruthy.test.js +1 -1
  60. package/dist/rules/issues/logic/noUnnecessaryConditionTruthy.test.js.map +1 -1
  61. package/dist/rules/issues/miscellaneous/requireExtensionRule.test.js +1 -1
  62. package/dist/rules/issues/miscellaneous/requireExtensionRule.test.js.map +1 -1
  63. package/dist/rules/issues/miscellaneous/unknownCookieRule.test.js +1 -1
  64. package/dist/rules/issues/miscellaneous/unknownCookieRule.test.js.map +1 -1
  65. package/dist/rules/issues/routing/duplicateRouteRule.test.js +1 -1
  66. package/dist/rules/issues/routing/duplicateRouteRule.test.js.map +1 -1
  67. package/dist/rules/issues/routing/duplicateUrlParameterRule.test.js +1 -1
  68. package/dist/rules/issues/routing/duplicateUrlParameterRule.test.js.map +1 -1
  69. package/dist/rules/issues/style/noReferenceGlobalCSSVariable.js +32 -11
  70. package/dist/rules/issues/style/noReferenceGlobalCSSVariable.js.map +1 -1
  71. package/dist/rules/issues/style/noReferenceGlobalCSSVariable.test.js +55 -1
  72. package/dist/rules/issues/style/noReferenceGlobalCSSVariable.test.js.map +1 -1
  73. package/dist/rules/issues/style/styleRules.index.js +2 -0
  74. package/dist/rules/issues/style/styleRules.index.js.map +1 -1
  75. package/dist/rules/issues/style/unknownCSSVariable.js +78 -0
  76. package/dist/rules/issues/style/unknownCSSVariable.js.map +1 -0
  77. package/dist/rules/issues/style/unknownCSSVariable.test.js +337 -0
  78. package/dist/rules/issues/style/unknownCSSVariable.test.js.map +1 -0
  79. package/dist/rules/issues/workflows/duplicateWorkflowParameterRule.test.js +1 -1
  80. package/dist/rules/issues/workflows/duplicateWorkflowParameterRule.test.js.map +1 -1
  81. package/dist/rules/issues/workflows/noPostNavigateAction.test.js +1 -1
  82. package/dist/rules/issues/workflows/noPostNavigateAction.test.js.map +1 -1
  83. package/dist/rules/issues/workflows/unknownContextProviderWorkflowRule.test.js +1 -1
  84. package/dist/rules/issues/workflows/unknownContextProviderWorkflowRule.test.js.map +1 -1
  85. package/dist/rules/issues/workflows/unknownContextWorkflowRule.test.js +1 -1
  86. package/dist/rules/issues/workflows/unknownContextWorkflowRule.test.js.map +1 -1
  87. package/dist/rules/issues/workflows/unknownTriggerWorkflowParameterRule.test.js +3 -3
  88. package/dist/rules/issues/workflows/unknownTriggerWorkflowParameterRule.test.js.map +1 -1
  89. package/dist/rules/issues/workflows/unknownTriggerWorkflowRule.test.js +1 -1
  90. package/dist/rules/issues/workflows/unknownTriggerWorkflowRule.test.js.map +1 -1
  91. package/dist/rules/issues/workflows/unknownWorkflowParameterRule.test.js +1 -1
  92. package/dist/rules/issues/workflows/unknownWorkflowParameterRule.test.js.map +1 -1
  93. package/package.json +3 -3
  94. package/src/rules/issues/actions/duplicateActionArgumentNameRule.test.ts +3 -3
  95. package/src/rules/issues/actions/legacyActionRule.test.ts +1 -1
  96. package/src/rules/issues/actions/noReferenceProjectActionRule.test.ts +1 -1
  97. package/src/rules/issues/actions/unknownActionArgumentRule.test.ts +1 -1
  98. package/src/rules/issues/actions/unknownActionEventRule.test.ts +1 -1
  99. package/src/rules/issues/actions/unknownProjectActionRule.test.ts +1 -1
  100. package/src/rules/issues/apis/legacyApiRule.test.ts +1 -1
  101. package/src/rules/issues/apis/noReferenceApiRule.test.ts +283 -0
  102. package/src/rules/issues/apis/noReferenceApiRule.ts +29 -1
  103. package/src/rules/issues/context/noContextConsumersRule.test.ts +3 -3
  104. package/src/rules/issues/context/unknownContextFormulaRule.test.ts +1 -1
  105. package/src/rules/issues/context/unknownContextProviderFormulaRule.test.ts +1 -1
  106. package/src/rules/issues/context/unknownContextProviderRule.test.ts +1 -1
  107. package/src/rules/issues/dom/createRequiredDirectChildRule.test.ts +1 -1
  108. package/src/rules/issues/dom/createRequiredDirectParentRule.test.ts +1 -1
  109. package/src/rules/issues/dom/createRequiredElementAttributeRule.test.ts +3 -3
  110. package/src/rules/issues/dom/elementWithoutInteractiveContentRule.test.ts +3 -3
  111. package/src/rules/issues/dom/imageWithoutDimensionRule.test.ts +4 -4
  112. package/src/rules/issues/dom/nonEmptyVoidElementRule.test.ts +1 -1
  113. package/src/rules/issues/events/duplicateEventTriggerRule.test.ts +1 -1
  114. package/src/rules/issues/formulas/duplicateFormulaArgumentNameRule.test.ts +2 -2
  115. package/src/rules/issues/formulas/noReferenceProjectFormulaRule.test.ts +1 -1
  116. package/src/rules/issues/formulas/unknownComponentFormulaInputRule.test.ts +2 -2
  117. package/src/rules/issues/formulas/unknownProjectFormulaInputRule.test.ts +2 -2
  118. package/src/rules/issues/formulas/unknownProjectFormulaRule.test.ts +1 -1
  119. package/src/rules/issues/formulas/unknownRepeatIndexFormulaRule.test.ts +1 -1
  120. package/src/rules/issues/formulas/unknownRepeatItemFormulaRule.test.ts +1 -1
  121. package/src/rules/issues/logic/noStaticNodeCondition.test.ts +1 -1
  122. package/src/rules/issues/logic/noUnnecessaryConditionFalsy.test.ts +1 -1
  123. package/src/rules/issues/logic/noUnnecessaryConditionTruthy.test.ts +1 -1
  124. package/src/rules/issues/miscellaneous/requireExtensionRule.test.ts +1 -1
  125. package/src/rules/issues/miscellaneous/unknownCookieRule.test.ts +1 -1
  126. package/src/rules/issues/routing/duplicateRouteRule.test.ts +1 -1
  127. package/src/rules/issues/routing/duplicateUrlParameterRule.test.ts +1 -1
  128. package/src/rules/issues/style/noReferenceGlobalCSSVariable.test.ts +59 -1
  129. package/src/rules/issues/style/noReferenceGlobalCSSVariable.ts +38 -12
  130. package/src/rules/issues/style/styleRules.index.ts +2 -0
  131. package/src/rules/issues/style/unknownCSSVariable.test.ts +364 -0
  132. package/src/rules/issues/style/unknownCSSVariable.ts +101 -0
  133. package/src/rules/issues/workflows/duplicateWorkflowParameterRule.test.ts +1 -1
  134. package/src/rules/issues/workflows/noPostNavigateAction.test.ts +1 -1
  135. package/src/rules/issues/workflows/unknownContextProviderWorkflowRule.test.ts +1 -1
  136. package/src/rules/issues/workflows/unknownContextWorkflowRule.test.ts +1 -1
  137. package/src/rules/issues/workflows/unknownTriggerWorkflowParameterRule.test.ts +3 -3
  138. package/src/rules/issues/workflows/unknownTriggerWorkflowRule.test.ts +1 -1
  139. package/src/rules/issues/workflows/unknownWorkflowParameterRule.test.ts +1 -1
  140. package/src/types.d.ts +1 -0
@@ -93,6 +93,6 @@ describe('duplicateEventTriggerRule', () => {
93
93
  }),
94
94
  )
95
95
 
96
- expect(problems).toHaveLength(0)
96
+ expect(problems).toBeEmpty()
97
97
  })
98
98
  })
@@ -106,7 +106,7 @@ describe('duplicateFormulaArgumentNameRule', () => {
106
106
  }),
107
107
  )
108
108
 
109
- expect(problems).toHaveLength(0)
109
+ expect(problems).toBeEmpty()
110
110
  })
111
111
 
112
112
  test('should detect multiple duplicates', () => {
@@ -175,6 +175,6 @@ describe('duplicateFormulaArgumentNameRule', () => {
175
175
  }),
176
176
  )
177
177
 
178
- expect(problems).toHaveLength(0)
178
+ expect(problems).toBeEmpty()
179
179
  })
180
180
  })
@@ -288,7 +288,7 @@ describe('find noReferenceFormulaRule', () => {
288
288
  }),
289
289
  )
290
290
 
291
- expect(problems).toHaveLength(0)
291
+ expect(problems).toBeEmpty()
292
292
  })
293
293
  })
294
294
 
@@ -89,7 +89,7 @@ describe('unknownComponentFormulaInput', () => {
89
89
  }),
90
90
  )
91
91
 
92
- expect(problems).toHaveLength(0)
92
+ expect(problems).toBeEmpty()
93
93
  })
94
94
  test('should not detect @toddle.parent/item path formulas', () => {
95
95
  const problems = Array.from(
@@ -136,6 +136,6 @@ describe('unknownComponentFormulaInput', () => {
136
136
  }),
137
137
  )
138
138
 
139
- expect(problems).toHaveLength(0)
139
+ expect(problems).toBeEmpty()
140
140
  })
141
141
  })
@@ -70,7 +70,7 @@ describe('unknownProjectFormulaInput', () => {
70
70
  }),
71
71
  )
72
72
 
73
- expect(problems).toHaveLength(0)
73
+ expect(problems).toBeEmpty()
74
74
  })
75
75
  test('should not detect @toddle.parent/item path formulas', () => {
76
76
  const problems = Array.from(
@@ -107,6 +107,6 @@ describe('unknownProjectFormulaInput', () => {
107
107
  }),
108
108
  )
109
109
 
110
- expect(problems).toHaveLength(0)
110
+ expect(problems).toBeEmpty()
111
111
  })
112
112
  })
@@ -121,6 +121,6 @@ describe('unknownProjectFormulaRule', () => {
121
121
  }),
122
122
  )
123
123
 
124
- expect(problems).toHaveLength(0)
124
+ expect(problems).toBeEmpty()
125
125
  })
126
126
  })
@@ -262,6 +262,6 @@ describe('unknownRepeatIndexFormulaRule', () => {
262
262
  }),
263
263
  )
264
264
 
265
- expect(problems).toHaveLength(0)
265
+ expect(problems).toBeEmpty()
266
266
  })
267
267
  })
@@ -277,6 +277,6 @@ describe('unknownRepeatItemFormulaRule', () => {
277
277
  }),
278
278
  )
279
279
 
280
- expect(problems).toHaveLength(0)
280
+ expect(problems).toBeEmpty()
281
281
  })
282
282
  })
@@ -127,7 +127,7 @@ describe('noStaticNodeCondition', () => {
127
127
  }),
128
128
  )
129
129
 
130
- expect(problems).toHaveLength(0)
130
+ expect(problems).toBeEmpty()
131
131
  })
132
132
 
133
133
  test('should fix static truthy condition by removing the condition', () => {
@@ -97,6 +97,6 @@ describe('noUnnecessaryConditionFalsy', () => {
97
97
  }),
98
98
  )
99
99
 
100
- expect(problems).toHaveLength(0)
100
+ expect(problems).toBeEmpty()
101
101
  })
102
102
  })
@@ -154,6 +154,6 @@ describe('noUnnecessaryConditionTruthy', () => {
154
154
  }),
155
155
  )
156
156
 
157
- expect(problems).toHaveLength(0)
157
+ expect(problems).toBeEmpty()
158
158
  })
159
159
  })
@@ -69,6 +69,6 @@ describe('requireExtension', () => {
69
69
  }),
70
70
  )
71
71
 
72
- expect(problems).toHaveLength(0)
72
+ expect(problems).toBeEmpty()
73
73
  })
74
74
  })
@@ -107,6 +107,6 @@ describe('unknownCookie', () => {
107
107
  }),
108
108
  )
109
109
 
110
- expect(problems).toHaveLength(0)
110
+ expect(problems).toBeEmpty()
111
111
  })
112
112
  })
@@ -142,6 +142,6 @@ describe('duplicateRouteRule', () => {
142
142
  }),
143
143
  )
144
144
 
145
- expect(problems).toHaveLength(0)
145
+ expect(problems).toBeEmpty()
146
146
  })
147
147
  })
@@ -130,6 +130,6 @@ describe('duplicateUrlParameterRule', () => {
130
130
  rules: [duplicateUrlParameterRule],
131
131
  }),
132
132
  )
133
- expect(problems).toHaveLength(0)
133
+ expect(problems).toBeEmpty()
134
134
  })
135
135
  })
@@ -57,7 +57,7 @@ describe('noReferenceGlobalCSSVariableRule', () => {
57
57
  }),
58
58
  )
59
59
 
60
- expect(problems).toHaveLength(0)
60
+ expect(problems).toBeEmpty()
61
61
  })
62
62
 
63
63
  test('should report global CSS variables that are never used', () => {
@@ -243,4 +243,62 @@ describe('noReferenceGlobalCSSVariableRule', () => {
243
243
  expect(problems[0].details).toEqual({ name: '--local-color' })
244
244
  expect(problems[1].details).toEqual({ name: '--a-third-local-color' })
245
245
  })
246
+
247
+ test('should not report when variable is used in package components', () => {
248
+ const problems = Array.from(
249
+ searchProject({
250
+ files: {
251
+ themes: {
252
+ Default: {
253
+ fonts: [],
254
+ propertyDefinitions: {
255
+ '--global-color': {
256
+ syntax: { type: 'primitive', name: 'color' },
257
+ description: 'A global color',
258
+ inherits: true,
259
+ initialValue: 'blue',
260
+ values: {},
261
+ },
262
+ },
263
+ },
264
+ },
265
+ formulas: {},
266
+ components: {},
267
+ packages: [
268
+ {
269
+ manifest: {
270
+ name: 'Test Package',
271
+ commit: '',
272
+ },
273
+ components: {
274
+ PackageComponent: {
275
+ name: 'PackageComponent',
276
+ nodes: {
277
+ root: {
278
+ tag: 'div',
279
+ type: 'element',
280
+ attrs: {},
281
+ style: {
282
+ color: 'var(--global-color)',
283
+ },
284
+ events: {},
285
+ classes: {},
286
+ children: [],
287
+ },
288
+ },
289
+ formulas: {},
290
+ apis: {},
291
+ attributes: {},
292
+ variables: {},
293
+ },
294
+ },
295
+ },
296
+ ] as any,
297
+ },
298
+ rules: [noReferenceGlobalCSSVariableRule],
299
+ }),
300
+ )
301
+
302
+ expect(problems).toBeEmpty()
303
+ })
246
304
  })
@@ -28,12 +28,11 @@ export const noReferenceGlobalCSSVariableRule: Rule<{
28
28
  ;[{ style: node.style }, ...(node.variants ?? [])].forEach(
29
29
  ({ style }) => {
30
30
  Object.values(style ?? {}).forEach((styleValue) => {
31
- if (typeof styleValue !== 'string') {
32
- return
31
+ if (typeof styleValue === 'string') {
32
+ styleValue.matchAll(REGEX).forEach(([_, varName]) => {
33
+ vars.add(varName)
34
+ })
33
35
  }
34
- styleValue.matchAll(REGEX).forEach(([_, varName]) => {
35
- vars.add(varName)
36
- })
37
36
  })
38
37
  },
39
38
  )
@@ -45,6 +44,34 @@ export const noReferenceGlobalCSSVariableRule: Rule<{
45
44
  },
46
45
  )
47
46
 
47
+ const usedCSSVariablesInPackageComponents = memo(
48
+ 'css-variables-used-in-package-components',
49
+ () => {
50
+ const vars = new Set<string>()
51
+ Object.values(files.packages ?? {}).forEach((pkg) => {
52
+ Object.values(pkg?.components ?? {}).forEach((component) => {
53
+ Object.values(component?.nodes ?? {}).forEach((node) => {
54
+ if (node.type === 'element' || node.type === 'component') {
55
+ ;[{ style: node.style }, ...(node.variants ?? [])].forEach(
56
+ ({ style }) => {
57
+ Object.values(style ?? {}).forEach((styleValue) => {
58
+ if (typeof styleValue === 'string') {
59
+ styleValue.matchAll(REGEX).forEach(([_, varName]) => {
60
+ vars.add(varName)
61
+ })
62
+ }
63
+ })
64
+ },
65
+ )
66
+ }
67
+ })
68
+ })
69
+ })
70
+
71
+ return vars
72
+ },
73
+ )
74
+
48
75
  const usedCSSVariablesInCSSVariables = memo(
49
76
  'css-variables-used-in-css-variables',
50
77
  () => {
@@ -52,13 +79,11 @@ export const noReferenceGlobalCSSVariableRule: Rule<{
52
79
  Object.values(theme.propertyDefinitions ?? {}).forEach((propDef) => {
53
80
  ;[...Object.values(propDef.values), propDef.initialValue].forEach(
54
81
  (val) => {
55
- if (typeof val !== 'string') {
56
- return
82
+ if (typeof val === 'string') {
83
+ val.matchAll(REGEX).forEach(([_, varName]) => {
84
+ vars.add(varName)
85
+ })
57
86
  }
58
-
59
- val.matchAll(REGEX).forEach(([_, varName]) => {
60
- vars.add(varName)
61
- })
62
87
  },
63
88
  )
64
89
  })
@@ -69,7 +94,8 @@ export const noReferenceGlobalCSSVariableRule: Rule<{
69
94
 
70
95
  if (
71
96
  usedCSSVariablesInCSSVariables.has(value.key) ||
72
- usedCSSVariablesInComponents.has(value.key)
97
+ usedCSSVariablesInComponents.has(value.key) ||
98
+ usedCSSVariablesInPackageComponents.has(value.key)
73
99
  ) {
74
100
  return
75
101
  }
@@ -1,9 +1,11 @@
1
1
  import { invalidStyleSyntaxRule } from './invalidStyleSyntaxRule'
2
2
  import { noReferenceGlobalCSSVariableRule } from './noReferenceGlobalCSSVariable'
3
3
  import { unknownClassnameRule } from './unknownClassnameRule'
4
+ import { unknownCSSVariableRule } from './unknownCSSVariable'
4
5
 
5
6
  export default [
6
7
  invalidStyleSyntaxRule,
7
8
  unknownClassnameRule,
9
+ unknownCSSVariableRule,
8
10
  noReferenceGlobalCSSVariableRule,
9
11
  ]
@@ -0,0 +1,364 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { searchProject } from '../../../searchProject'
3
+ import { unknownCSSVariableRule } from './unknownCSSVariable'
4
+
5
+ describe('unknownCSSVariableRule', () => {
6
+ test('should not report CSS variables that are defined in the global theme', () => {
7
+ const problems = Array.from(
8
+ searchProject({
9
+ files: {
10
+ themes: {
11
+ Default: {
12
+ fonts: [],
13
+ propertyDefinitions: {
14
+ '--global-color': {
15
+ syntax: { type: 'primitive', name: 'color' },
16
+ description: 'A global color',
17
+ inherits: true,
18
+ initialValue: 'blue',
19
+ values: {},
20
+ },
21
+ '--local-margin': {
22
+ syntax: { type: 'primitive', name: 'length-percentage' },
23
+ description: 'A local margin',
24
+ inherits: true,
25
+ initialValue: '10px',
26
+ values: {},
27
+ },
28
+ },
29
+ },
30
+ },
31
+ formulas: {},
32
+ components: {
33
+ test: {
34
+ name: 'test',
35
+ nodes: {
36
+ root: {
37
+ tag: 'div',
38
+ type: 'element',
39
+ attrs: {},
40
+ style: {
41
+ color: 'var(--global-color)',
42
+ margin: 'calc(var(--local-margin) + 5px)',
43
+ },
44
+ events: {},
45
+ classes: {},
46
+ children: [],
47
+ },
48
+ },
49
+ formulas: {},
50
+ apis: {},
51
+ attributes: {},
52
+ variables: {},
53
+ },
54
+ },
55
+ },
56
+ rules: [unknownCSSVariableRule],
57
+ }),
58
+ )
59
+
60
+ expect(problems).toBeEmpty()
61
+ })
62
+
63
+ test('should not report CSS variables that are defined in ancestors', () => {
64
+ const problems = Array.from(
65
+ searchProject({
66
+ files: {
67
+ themes: {
68
+ Default: {
69
+ fonts: [],
70
+ propertyDefinitions: {},
71
+ },
72
+ },
73
+ formulas: {},
74
+ components: {
75
+ test: {
76
+ name: 'test',
77
+ nodes: {
78
+ root: {
79
+ tag: 'div',
80
+ type: 'element',
81
+ attrs: {},
82
+ style: {},
83
+ events: {},
84
+ classes: {},
85
+ children: ['child'],
86
+ customProperties: {
87
+ '--local-color': {
88
+ formula: {
89
+ type: 'value',
90
+ value: 'blue',
91
+ },
92
+ },
93
+ },
94
+ },
95
+ child: {
96
+ tag: 'div',
97
+ type: 'element',
98
+ attrs: {},
99
+ customProperties: {
100
+ '--own-color': {
101
+ formula: {
102
+ type: 'value',
103
+ value: 'red',
104
+ },
105
+ },
106
+ },
107
+ style: {
108
+ margin: 'var(--local-color)',
109
+ color: 'var(--own-color)',
110
+ },
111
+ events: {},
112
+ classes: {},
113
+ children: [],
114
+ },
115
+ },
116
+ formulas: {},
117
+ apis: {},
118
+ attributes: {},
119
+ variables: {},
120
+ },
121
+ },
122
+ },
123
+ rules: [unknownCSSVariableRule],
124
+ }),
125
+ )
126
+
127
+ expect(problems).toBeEmpty()
128
+ })
129
+
130
+ test('should report CSS variables that are not defined globally or locally', () => {
131
+ const problems = Array.from(
132
+ searchProject({
133
+ files: {
134
+ themes: {
135
+ Default: {
136
+ fonts: [],
137
+ propertyDefinitions: {},
138
+ },
139
+ },
140
+ formulas: {},
141
+ components: {
142
+ test: {
143
+ name: 'test',
144
+ nodes: {
145
+ root: {
146
+ tag: 'div',
147
+ type: 'element',
148
+ attrs: {},
149
+ style: {
150
+ color: 'var(--undefined-global)',
151
+ margin: 'var(--undefined-local)',
152
+ },
153
+ events: {},
154
+ classes: {},
155
+ children: [],
156
+ },
157
+ },
158
+ formulas: {},
159
+ apis: {},
160
+ attributes: {},
161
+ variables: {},
162
+ },
163
+ },
164
+ },
165
+ rules: [unknownCSSVariableRule],
166
+ }),
167
+ )
168
+
169
+ expect(problems).toHaveLength(2)
170
+ expect(problems[0].details).toEqual({ name: '--undefined-global' })
171
+ expect(problems[1].details).toEqual({ name: '--undefined-local' })
172
+ })
173
+
174
+ test('should report problem if local variable is used in parent but only defined in child', () => {
175
+ const problems = Array.from(
176
+ searchProject({
177
+ files: {
178
+ themes: {
179
+ Default: {
180
+ fonts: [],
181
+ propertyDefinitions: {},
182
+ },
183
+ },
184
+ formulas: {},
185
+ components: {
186
+ test: {
187
+ name: 'test',
188
+ nodes: {
189
+ root: {
190
+ tag: 'div',
191
+ type: 'element',
192
+ attrs: {},
193
+ style: {
194
+ color: 'var(--child-only-variable)',
195
+ },
196
+ events: {},
197
+ classes: {},
198
+ children: ['child'],
199
+ },
200
+ child: {
201
+ tag: 'div',
202
+ type: 'element',
203
+ attrs: {},
204
+ customProperties: {
205
+ '--child-only-variable': {
206
+ formula: {
207
+ type: 'value',
208
+ value: 'red',
209
+ },
210
+ },
211
+ },
212
+ style: {},
213
+ events: {},
214
+ classes: {},
215
+ children: [],
216
+ },
217
+ },
218
+ formulas: {},
219
+ apis: {},
220
+ attributes: {},
221
+ variables: {},
222
+ },
223
+ },
224
+ },
225
+ rules: [unknownCSSVariableRule],
226
+ }),
227
+ )
228
+
229
+ expect(problems).toHaveLength(1)
230
+ })
231
+
232
+ test('should not report when legacy style variables are used', () => {
233
+ const problems = Array.from(
234
+ searchProject({
235
+ files: {
236
+ themes: {
237
+ Default: {
238
+ fonts: [],
239
+ propertyDefinitions: {},
240
+ },
241
+ },
242
+ formulas: {},
243
+ components: {
244
+ test: {
245
+ name: 'test',
246
+ nodes: {
247
+ root: {
248
+ tag: 'div',
249
+ type: 'element',
250
+ attrs: {},
251
+ 'style-variables': [
252
+ {
253
+ name: 'legacy-variable',
254
+ formula: {
255
+ type: 'value',
256
+ value: '10px',
257
+ },
258
+ category: 'spacing',
259
+ },
260
+ ],
261
+ style: {
262
+ margin: 'var(--legacy-variable)',
263
+ },
264
+ events: {},
265
+ classes: {},
266
+ children: [],
267
+ },
268
+ },
269
+ formulas: {},
270
+ apis: {},
271
+ attributes: {},
272
+ variables: {},
273
+ },
274
+ },
275
+ },
276
+ rules: [unknownCSSVariableRule],
277
+ }),
278
+ )
279
+
280
+ expect(problems).toBeEmpty()
281
+ })
282
+
283
+ test('should not report when declared in a style', () => {
284
+ const problems = Array.from(
285
+ searchProject({
286
+ files: {
287
+ themes: {
288
+ Default: {
289
+ fonts: [],
290
+ propertyDefinitions: {},
291
+ },
292
+ },
293
+ formulas: {},
294
+ components: {
295
+ test: {
296
+ name: 'test',
297
+ nodes: {
298
+ root: {
299
+ tag: 'div',
300
+ type: 'element',
301
+ attrs: {},
302
+ style: {
303
+ '--declared-in-style': '10px',
304
+ margin: 'var(--declared-in-style)',
305
+ },
306
+ events: {},
307
+ classes: {},
308
+ children: [],
309
+ },
310
+ },
311
+ formulas: {},
312
+ apis: {},
313
+ attributes: {},
314
+ variables: {},
315
+ },
316
+ },
317
+ },
318
+ rules: [unknownCSSVariableRule],
319
+ }),
320
+ )
321
+
322
+ expect(problems).toBeEmpty()
323
+ })
324
+
325
+ test('should not report when a legacy theme exists (no propertyDefinitions)', () => {
326
+ const problems = Array.from(
327
+ searchProject({
328
+ files: {
329
+ themes: {
330
+ Default: {
331
+ fonts: [],
332
+ },
333
+ },
334
+ formulas: {},
335
+ components: {
336
+ test: {
337
+ name: 'test',
338
+ nodes: {
339
+ root: {
340
+ tag: 'div',
341
+ type: 'element',
342
+ attrs: {},
343
+ style: {
344
+ color: 'var(--legacy-theme-variable)',
345
+ },
346
+ events: {},
347
+ classes: {},
348
+ children: [],
349
+ },
350
+ },
351
+ formulas: {},
352
+ apis: {},
353
+ attributes: {},
354
+ variables: {},
355
+ },
356
+ },
357
+ },
358
+ rules: [unknownCSSVariableRule],
359
+ }),
360
+ )
361
+
362
+ expect(problems).toBeEmpty()
363
+ })
364
+ })