@nordcraft/search 1.0.44 → 1.0.46

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 (59) hide show
  1. package/dist/problems.worker.js +13 -5
  2. package/dist/problems.worker.js.map +1 -1
  3. package/dist/rules/actions/legacyActionRule.test.js +3 -3
  4. package/dist/rules/actions/legacyActionRule.test.js.map +1 -1
  5. package/dist/rules/events/duplicateEventTriggerRule.js +2 -1
  6. package/dist/rules/events/duplicateEventTriggerRule.js.map +1 -1
  7. package/dist/rules/logic/noStaticNodeCondition.js +29 -0
  8. package/dist/rules/logic/noStaticNodeCondition.js.map +1 -0
  9. package/dist/rules/logic/noStaticNodeCondition.test.js +274 -0
  10. package/dist/rules/logic/noStaticNodeCondition.test.js.map +1 -0
  11. package/dist/rules/logic/noUnnecessaryConditionFalsy.js +5 -1
  12. package/dist/rules/logic/noUnnecessaryConditionFalsy.js.map +1 -1
  13. package/dist/rules/logic/noUnnecessaryConditionTruthy.js +8 -4
  14. package/dist/rules/logic/noUnnecessaryConditionTruthy.js.map +1 -1
  15. package/dist/rules/logic/noUnnecessaryConditionTruthy.test.js +33 -4
  16. package/dist/rules/logic/noUnnecessaryConditionTruthy.test.js.map +1 -1
  17. package/dist/rules/noReferenceNodeRule.js +24 -0
  18. package/dist/rules/noReferenceNodeRule.js.map +1 -0
  19. package/dist/rules/noReferenceNodeRule.test.js +131 -0
  20. package/dist/rules/noReferenceNodeRule.test.js.map +1 -0
  21. package/dist/rules/style/invalidStyleSyntaxRule.js +28 -0
  22. package/dist/rules/style/invalidStyleSyntaxRule.js.map +1 -0
  23. package/dist/rules/style/invalidStyleSyntaxRule.test.js +100 -0
  24. package/dist/rules/style/invalidStyleSyntaxRule.test.js.map +1 -0
  25. package/dist/searchProject.js +22 -1
  26. package/dist/searchProject.js.map +1 -1
  27. package/dist/util/contextlessEvaluateFormula.js +77 -0
  28. package/dist/util/contextlessEvaluateFormula.js.map +1 -0
  29. package/dist/util/contextlessEvaluateFormula.test.js +152 -0
  30. package/dist/util/contextlessEvaluateFormula.test.js.map +1 -0
  31. package/dist/util/removeUnused.fix.js +18 -1
  32. package/dist/util/removeUnused.fix.js.map +1 -1
  33. package/package.json +4 -3
  34. package/src/problems.worker.ts +20 -7
  35. package/src/rules/actions/legacyActionRule.test.ts +3 -3
  36. package/src/rules/events/duplicateEventTriggerRule.ts +2 -1
  37. package/src/rules/logic/noStaticNodeCondition.test.ts +290 -0
  38. package/src/rules/logic/noStaticNodeCondition.ts +43 -0
  39. package/src/rules/logic/noUnnecessaryConditionFalsy.ts +5 -4
  40. package/src/rules/logic/noUnnecessaryConditionTruthy.test.ts +37 -4
  41. package/src/rules/logic/noUnnecessaryConditionTruthy.ts +10 -8
  42. package/src/rules/noReferenceNodeRule.test.ts +140 -0
  43. package/src/rules/noReferenceNodeRule.ts +34 -0
  44. package/src/rules/style/invalidStyleSyntaxRule.test.ts +106 -0
  45. package/src/rules/style/invalidStyleSyntaxRule.ts +35 -0
  46. package/src/searchProject.ts +25 -1
  47. package/src/types.d.ts +20 -2
  48. package/src/util/contextlessEvaluateFormula.test.ts +190 -0
  49. package/src/util/contextlessEvaluateFormula.ts +110 -0
  50. package/src/util/removeUnused.fix.ts +29 -1
  51. package/dist/memos/getAllCustomPropertiesBySyntax.js +0 -43
  52. package/dist/memos/getAllCustomPropertiesBySyntax.js.map +0 -1
  53. package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.js +0 -50
  54. package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.js.map +0 -1
  55. package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.js +0 -265
  56. package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.js.map +0 -1
  57. package/src/memos/getAllCustomPropertiesBySyntax.ts +0 -68
  58. package/src/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.ts +0 -278
  59. package/src/rules/style-variables/ambiguousStyleVariableSyntaxRule.ts +0 -65
@@ -1,278 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
- import { searchProject } from '../../searchProject'
3
- import { ambiguousStyleVariableSyntaxRule } from './ambiguousStyleVariableSyntaxRule'
4
-
5
- describe('ambiguousStyleVariableSyntaxRule', () => {
6
- test('should report when there are style variables with the same name but different syntax', () => {
7
- const problems = Array.from(
8
- searchProject({
9
- files: {
10
- components: {
11
- component1: {
12
- name: 'component1',
13
- nodes: {
14
- node1: {
15
- type: 'element',
16
- customProperties: {
17
- '--my-variable': {
18
- syntax: { type: 'primitive', name: 'length' },
19
- formula: { type: 'value', value: '10px' },
20
- },
21
- },
22
- attrs: {},
23
- style: {},
24
- children: [],
25
- events: {},
26
- classes: {},
27
- tag: 'div',
28
- },
29
- },
30
- apis: {},
31
- attributes: {},
32
- variables: {},
33
- formulas: {},
34
- },
35
- component2: {
36
- name: 'component2',
37
- nodes: {
38
- node2: {
39
- type: 'element',
40
- customProperties: {
41
- '--my-variable': {
42
- syntax: { type: 'primitive', name: 'color' },
43
- formula: { type: 'value', value: '#ff0000' },
44
- },
45
- },
46
- attrs: {},
47
- style: {},
48
- children: [],
49
- events: {},
50
- classes: {},
51
- tag: 'div',
52
- },
53
- },
54
- apis: {},
55
- attributes: {},
56
- variables: {},
57
- formulas: {},
58
- },
59
- },
60
- },
61
- rules: [ambiguousStyleVariableSyntaxRule],
62
- }),
63
- )
64
- expect(problems).toHaveLength(2)
65
- expect(problems[0].code).toBe('ambiguous style variable syntax')
66
- expect(problems[1].code).toBe('ambiguous style variable syntax')
67
- expect(problems[0].details.name).toBe('--my-variable')
68
- expect(problems[1].details.name).toBe('--my-variable')
69
- expect(problems[0].details.duplicates).toEqual([
70
- {
71
- path: [
72
- 'components',
73
- 'component2',
74
- 'nodes',
75
- 'node2',
76
- 'customProperties',
77
- '--my-variable',
78
- ],
79
- syntax: { type: 'primitive', name: 'color' },
80
- },
81
- ])
82
- expect(problems[1].details.duplicates).toEqual([
83
- {
84
- path: [
85
- 'components',
86
- 'component1',
87
- 'nodes',
88
- 'node1',
89
- 'customProperties',
90
- '--my-variable',
91
- ],
92
- syntax: { type: 'primitive', name: 'length' },
93
- },
94
- ])
95
- })
96
-
97
- test('should not report when style variables have same name and same syntax', () => {
98
- const problems = Array.from(
99
- searchProject({
100
- files: {
101
- components: {
102
- component1: {
103
- name: 'component1',
104
- nodes: {
105
- node1: {
106
- type: 'element',
107
- customProperties: {
108
- '--my-variable': {
109
- syntax: { type: 'primitive', name: 'length' },
110
- formula: { type: 'value', value: '10px' },
111
- },
112
- },
113
- attrs: {},
114
- style: {},
115
- children: [],
116
- events: {},
117
- classes: {},
118
- tag: 'div',
119
- },
120
- },
121
- apis: {},
122
- attributes: {},
123
- variables: {},
124
- formulas: {},
125
- },
126
- component2: {
127
- name: 'component2',
128
- nodes: {
129
- node2: {
130
- type: 'element',
131
- customProperties: {
132
- '--my-variable': {
133
- syntax: { type: 'primitive', name: 'length' },
134
- formula: { type: 'value', value: '20px' },
135
- },
136
- },
137
- attrs: {},
138
- style: {},
139
- children: [],
140
- events: {},
141
- classes: {},
142
- tag: 'div',
143
- },
144
- },
145
- apis: {},
146
- attributes: {},
147
- variables: {},
148
- formulas: {},
149
- },
150
- },
151
- },
152
- rules: [ambiguousStyleVariableSyntaxRule],
153
- }),
154
- )
155
- expect(problems).toHaveLength(0)
156
- })
157
-
158
- test('should handle variant customProperties too', () => {
159
- const problems = Array.from(
160
- searchProject({
161
- files: {
162
- components: {
163
- component1: {
164
- name: 'component1',
165
- nodes: {
166
- node1: {
167
- type: 'element',
168
- customProperties: {
169
- '--my-variable': {
170
- syntax: { type: 'primitive', name: 'length' },
171
- formula: { type: 'value', value: '10px' },
172
- },
173
- },
174
- variants: [
175
- {
176
- breakpoint: 'medium',
177
- style: {},
178
- customProperties: {
179
- '--my-variable': {
180
- syntax: { type: 'primitive', name: 'color' },
181
- formula: { type: 'value', value: '#ff0000' },
182
- },
183
- },
184
- },
185
- ],
186
- attrs: {},
187
- style: {},
188
- children: [],
189
- events: {},
190
- classes: {},
191
- tag: 'div',
192
- },
193
- },
194
- apis: {},
195
- attributes: {},
196
- variables: {},
197
- formulas: {},
198
- },
199
- },
200
- },
201
- rules: [ambiguousStyleVariableSyntaxRule],
202
- }),
203
- )
204
-
205
- // Should flag both the base and the variant for conflicting syntax
206
- expect(problems).toHaveLength(2)
207
- expect(problems.map((p) => p.details.name)).toEqual([
208
- '--my-variable',
209
- '--my-variable',
210
- ])
211
- })
212
-
213
- test('should ignore non-primitive syntax', () => {
214
- const problems = Array.from(
215
- searchProject({
216
- files: {
217
- components: {
218
- component1: {
219
- name: 'component1',
220
- nodes: {
221
- node1: {
222
- type: 'element',
223
- customProperties: {
224
- '--my-variable': {
225
- syntax: {
226
- type: 'keyword',
227
- keywords: ['auto', 'inherit'],
228
- },
229
- formula: { type: 'value', value: '10px' },
230
- },
231
- },
232
- attrs: {},
233
- style: {},
234
- children: [],
235
- events: {},
236
- classes: {},
237
- tag: 'div',
238
- },
239
- },
240
- apis: {},
241
- attributes: {},
242
- variables: {},
243
- formulas: {},
244
- },
245
- component2: {
246
- name: 'component2',
247
- nodes: {
248
- node2: {
249
- type: 'element',
250
- customProperties: {
251
- '--my-variable': {
252
- syntax: { type: 'primitive', name: 'color' },
253
- formula: { type: 'value', value: '#ff0000' },
254
- },
255
- },
256
- attrs: {},
257
- style: {},
258
- children: [],
259
- events: {},
260
- classes: {},
261
- tag: 'div',
262
- },
263
- },
264
- apis: {},
265
- attributes: {},
266
- variables: {},
267
- formulas: {},
268
- },
269
- },
270
- },
271
- rules: [ambiguousStyleVariableSyntaxRule],
272
- }),
273
- )
274
-
275
- // Should not report because non-primitive should be skipped
276
- expect(problems).toHaveLength(0)
277
- })
278
- })
@@ -1,65 +0,0 @@
1
- import type { CssSyntaxNode } from '@nordcraft/core/dist/styling/customProperty'
2
- import { getAllCustomPropertiesBySyntax } from '../../memos/getAllCustomPropertiesBySyntax'
3
- import type { Rule } from '../../types'
4
-
5
- export const ambiguousStyleVariableSyntaxRule: Rule<{
6
- name: string
7
- duplicates: Array<{ path: string[]; syntax: CssSyntaxNode }>
8
- }> = {
9
- code: 'ambiguous style variable syntax',
10
- level: 'error',
11
- category: 'Other',
12
- visit: (report, args) => {
13
- const { nodeType, value, files, memo, path } = args
14
- if (nodeType !== 'component-node') return
15
- if (value.type !== 'element' && value.type !== 'component') return
16
-
17
- const check = (
18
- propName: string,
19
- syntax: CssSyntaxNode,
20
- basePath: Array<string | number>,
21
- ) => {
22
- if (syntax.type !== 'primitive') return
23
- const allCustomPropertiesBySyntax = getAllCustomPropertiesBySyntax(memo, {
24
- files,
25
- })[propName]
26
-
27
- const conflicts = Object.entries(allCustomPropertiesBySyntax)
28
- .filter(([name]) => name !== syntax.name)
29
- .flatMap(([, entries]) => entries)
30
-
31
- if (conflicts.length > 0) {
32
- report(basePath, {
33
- name: propName,
34
- duplicates: conflicts,
35
- })
36
- }
37
- }
38
-
39
- for (const [propName, prop] of Object.entries(
40
- value.customProperties ?? {},
41
- )) {
42
- check(propName, prop.syntax, [
43
- ...path,
44
- 'customProperties',
45
- propName,
46
- 'name',
47
- ])
48
- }
49
-
50
- value.variants?.forEach((variant, variantIndex) => {
51
- for (const [propName, prop] of Object.entries(
52
- variant.customProperties ?? {},
53
- )) {
54
- check(propName, prop.syntax, [
55
- ...path,
56
- 'variants',
57
- String(variantIndex),
58
- 'customProperties',
59
- propName,
60
- 'name',
61
- ])
62
- }
63
- })
64
- },
65
- }