@nordcraft/search 1.0.43 → 1.0.45

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 (80) hide show
  1. package/dist/problems.worker.js +4 -2
  2. package/dist/problems.worker.js.map +1 -1
  3. package/dist/rules/actions/legacyActionRule.fix.js +140 -0
  4. package/dist/rules/actions/legacyActionRule.fix.js.map +1 -0
  5. package/dist/rules/actions/legacyActionRule.js +3 -144
  6. package/dist/rules/actions/legacyActionRule.js.map +1 -1
  7. package/dist/rules/actions/legacyActionRule.test.js +4 -3
  8. package/dist/rules/actions/legacyActionRule.test.js.map +1 -1
  9. package/dist/rules/actions/noReferenceProjectActionRule.js +33 -40
  10. package/dist/rules/actions/noReferenceProjectActionRule.js.map +1 -1
  11. package/dist/rules/apis/noReferenceApiRule.js +7 -2
  12. package/dist/rules/apis/noReferenceApiRule.js.map +1 -1
  13. package/dist/rules/apis/noReferenceApiRule.test.js +65 -1
  14. package/dist/rules/apis/noReferenceApiRule.test.js.map +1 -1
  15. package/dist/rules/attributes/noReferenceAttributeRule.js +5 -1
  16. package/dist/rules/attributes/noReferenceAttributeRule.js.map +1 -1
  17. package/dist/rules/attributes/noReferenceAttributeRule.test.js +33 -1
  18. package/dist/rules/attributes/noReferenceAttributeRule.test.js.map +1 -1
  19. package/dist/rules/components/noReferenceComponentRule.js +18 -28
  20. package/dist/rules/components/noReferenceComponentRule.js.map +1 -1
  21. package/dist/rules/events/duplicateEventTriggerRule.js +2 -1
  22. package/dist/rules/events/duplicateEventTriggerRule.js.map +1 -1
  23. package/dist/rules/events/noReferenceEventRule.js +6 -2
  24. package/dist/rules/events/noReferenceEventRule.js.map +1 -1
  25. package/dist/rules/events/noReferenceEventRule.test.js +57 -1
  26. package/dist/rules/events/noReferenceEventRule.test.js.map +1 -1
  27. package/dist/rules/formulas/legacyFormulaRule.fix.js +574 -0
  28. package/dist/rules/formulas/legacyFormulaRule.fix.js.map +1 -0
  29. package/dist/rules/formulas/legacyFormulaRule.js +5 -580
  30. package/dist/rules/formulas/legacyFormulaRule.js.map +1 -1
  31. package/dist/rules/formulas/noReferenceComponentFormulaRule.js +8 -1
  32. package/dist/rules/formulas/noReferenceComponentFormulaRule.js.map +1 -1
  33. package/dist/rules/formulas/noReferenceProjectFormulaRule.js +63 -72
  34. package/dist/rules/formulas/noReferenceProjectFormulaRule.js.map +1 -1
  35. package/dist/rules/noReferenceNodeRule.js +22 -0
  36. package/dist/rules/noReferenceNodeRule.js.map +1 -0
  37. package/dist/rules/noReferenceNodeRule.test.js +131 -0
  38. package/dist/rules/noReferenceNodeRule.test.js.map +1 -0
  39. package/dist/rules/style/invalidStyleSyntaxRule.js +28 -0
  40. package/dist/rules/style/invalidStyleSyntaxRule.js.map +1 -0
  41. package/dist/rules/style/invalidStyleSyntaxRule.test.js +100 -0
  42. package/dist/rules/style/invalidStyleSyntaxRule.test.js.map +1 -0
  43. package/dist/searchProject.js +57 -16
  44. package/dist/searchProject.js.map +1 -1
  45. package/dist/util/removeUnused.fix.js +3 -0
  46. package/dist/util/removeUnused.fix.js.map +1 -0
  47. package/package.json +4 -3
  48. package/src/problems.worker.ts +4 -2
  49. package/src/rules/actions/legacyActionRule.fix.ts +157 -0
  50. package/src/rules/actions/legacyActionRule.test.ts +4 -3
  51. package/src/rules/actions/legacyActionRule.ts +3 -159
  52. package/src/rules/actions/noReferenceProjectActionRule.ts +39 -47
  53. package/src/rules/apis/noReferenceApiRule.test.ts +67 -1
  54. package/src/rules/apis/noReferenceApiRule.ts +9 -2
  55. package/src/rules/attributes/noReferenceAttributeRule.test.ts +35 -1
  56. package/src/rules/attributes/noReferenceAttributeRule.ts +7 -2
  57. package/src/rules/components/noReferenceComponentRule.ts +23 -34
  58. package/src/rules/events/duplicateEventTriggerRule.ts +2 -1
  59. package/src/rules/events/noReferenceEventRule.test.ts +59 -1
  60. package/src/rules/events/noReferenceEventRule.ts +8 -3
  61. package/src/rules/formulas/legacyFormulaRule.fix.ts +661 -0
  62. package/src/rules/formulas/legacyFormulaRule.ts +9 -670
  63. package/src/rules/formulas/noReferenceComponentFormulaRule.ts +15 -3
  64. package/src/rules/formulas/noReferenceProjectFormulaRule.ts +70 -77
  65. package/src/rules/noReferenceNodeRule.test.ts +140 -0
  66. package/src/rules/noReferenceNodeRule.ts +27 -0
  67. package/src/rules/style/invalidStyleSyntaxRule.test.ts +106 -0
  68. package/src/rules/style/invalidStyleSyntaxRule.ts +35 -0
  69. package/src/searchProject.ts +66 -22
  70. package/src/types.d.ts +33 -10
  71. package/src/util/removeUnused.fix.ts +5 -0
  72. package/dist/memos/getAllCustomPropertiesBySyntax.js +0 -43
  73. package/dist/memos/getAllCustomPropertiesBySyntax.js.map +0 -1
  74. package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.js +0 -50
  75. package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.js.map +0 -1
  76. package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.js +0 -265
  77. package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.js.map +0 -1
  78. package/src/memos/getAllCustomPropertiesBySyntax.ts +0 -68
  79. package/src/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.ts +0 -278
  80. package/src/rules/style-variables/ambiguousStyleVariableSyntaxRule.ts +0 -65
@@ -1,4 +1,5 @@
1
1
  import type { Rule } from '../../types'
2
+ import { removeFromPathFix } from '../../util/removeUnused.fix'
2
3
 
3
4
  export const noReferenceApiRule: Rule<void> = {
4
5
  code: 'no-reference api',
@@ -8,7 +9,8 @@ export const noReferenceApiRule: Rule<void> = {
8
9
  if (args.nodeType !== 'component-api') {
9
10
  return
10
11
  }
11
- const { path, value, memo, component } = args
12
+ const { value, memo, component } = args
13
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
14
  if (!component) {
13
15
  return
14
16
  }
@@ -37,6 +39,11 @@ export const noReferenceApiRule: Rule<void> = {
37
39
  if (componentApiReferences.has(value.name)) {
38
40
  return
39
41
  }
40
- report(path)
42
+ report(args.path, undefined, ['delete-api'])
43
+ },
44
+ fixes: {
45
+ 'delete-api': removeFromPathFix,
41
46
  },
42
47
  }
48
+
49
+ export type NoReferenceApiRuleFix = 'delete-api'
@@ -1,8 +1,10 @@
1
+ import type { ProjectFiles } from '@nordcraft/ssr/dist/ssr.types'
1
2
  import { describe, expect, test } from 'bun:test'
3
+ import { fixProject } from '../../fixProject'
2
4
  import { searchProject } from '../../searchProject'
3
5
  import { noReferenceAttributeRule } from './noReferenceAttributeRule'
4
6
 
5
- describe('noReferenceAttributeRule', () => {
7
+ describe('find noReferenceAttributeRule', () => {
6
8
  test('should detect attributes with no references', () => {
7
9
  const problems = Array.from(
8
10
  searchProject({
@@ -137,3 +139,35 @@ describe('noReferenceAttributeRule', () => {
137
139
  expect(problems).toEqual([])
138
140
  })
139
141
  })
142
+
143
+ describe('fix noReferenceAttributeRule', () => {
144
+ test('should remove attributes with no references', () => {
145
+ const files: ProjectFiles = {
146
+ formulas: {},
147
+ components: {
148
+ test: {
149
+ name: 'test',
150
+ nodes: {},
151
+ formulas: {},
152
+ apis: {},
153
+ attributes: {
154
+ 'my-attribute': {
155
+ name: 'my-attribute-name',
156
+ testValue: { type: 'value', value: null },
157
+ '@nordcraft/metadata': {
158
+ comments: null,
159
+ },
160
+ },
161
+ },
162
+ variables: {},
163
+ },
164
+ },
165
+ }
166
+ const fixedFiles = fixProject({
167
+ files,
168
+ rule: noReferenceAttributeRule,
169
+ fixType: 'delete-attribute',
170
+ })
171
+ expect(fixedFiles.components['test']?.attributes).toEqual({})
172
+ })
173
+ })
@@ -1,4 +1,5 @@
1
1
  import type { Rule } from '../../types'
2
+ import { removeFromPathFix } from '../../util/removeUnused.fix'
2
3
 
3
4
  export const noReferenceAttributeRule: Rule<void> = {
4
5
  code: 'no-reference attribute',
@@ -26,7 +27,11 @@ export const noReferenceAttributeRule: Rule<void> = {
26
27
  if (attrs.has(attributeKey)) {
27
28
  return
28
29
  }
29
-
30
- report(path)
30
+ report(args.path, undefined, ['delete-attribute'])
31
+ },
32
+ fixes: {
33
+ 'delete-attribute': removeFromPathFix,
31
34
  },
32
35
  }
36
+
37
+ export type NoReferenceAttributeRuleFix = 'delete-attribute'
@@ -1,53 +1,42 @@
1
1
  import type { Component } from '@nordcraft/core/dist/component/component.types'
2
- import { omit } from '@nordcraft/core/dist/utils/collections'
3
2
  import { isDefined } from '@nordcraft/core/dist/utils/util'
4
- import type { ApplicationState, NodeType, Rule } from '../../types'
3
+ import type { Rule } from '../../types'
4
+ import { removeFromPathFix } from '../../util/removeUnused.fix'
5
5
 
6
6
  export const noReferenceComponentRule: Rule<void> = {
7
7
  code: 'no-reference component',
8
8
  level: 'warning',
9
9
  category: 'No References',
10
10
  visit: (report, data, state) => {
11
- if (hasReferences(data, state)) {
11
+ if (
12
+ data.nodeType !== 'component' ||
13
+ isPage(data.value) ||
14
+ (state?.projectDetails?.type === 'package' &&
15
+ data.value.exported === true)
16
+ ) {
12
17
  return
13
18
  }
19
+ for (const component of Object.values(data.files.components)) {
20
+ // Enforce that the component is not undefined since we're iterating
21
+ for (const node of Object.values(component!.nodes ?? {})) {
22
+ if (
23
+ node.type === 'component' &&
24
+ node.name === data.value.name &&
25
+ // Circular references from a component to itself should
26
+ // not count as a reference
27
+ node.name !== component!.name
28
+ ) {
29
+ return
30
+ }
31
+ }
32
+ }
14
33
  report(data.path, undefined, ['delete-component'])
15
34
  },
16
35
  fixes: {
17
- 'delete-component': (data, state) => {
18
- if (hasReferences(data, state)) {
19
- return
20
- }
21
- return omit(data.files, data.path)
22
- },
36
+ 'delete-component': removeFromPathFix,
23
37
  },
24
38
  }
25
39
 
26
- const hasReferences = (data: NodeType, state?: ApplicationState) => {
27
- if (
28
- data.nodeType !== 'component' ||
29
- isPage(data.value) ||
30
- (state?.projectDetails?.type === 'package' && data.value.exported === true)
31
- ) {
32
- return true
33
- }
34
- for (const component of Object.values(data.files.components)) {
35
- // Enforce that the component is not undefined since we're iterating
36
- for (const node of Object.values(component!.nodes ?? {})) {
37
- if (
38
- node.type === 'component' &&
39
- node.name === data.value.name &&
40
- // Circular references from a component to itself should
41
- // not count as a reference
42
- node.name !== component!.name
43
- ) {
44
- return true
45
- }
46
- }
47
- }
48
- return false
49
- }
50
-
51
40
  export type NoReferenceComponentRuleFix = 'delete-component'
52
41
 
53
42
  const isPage = (
@@ -10,8 +10,9 @@ export const duplicateEventTriggerRule: Rule<{ trigger: string }> = {
10
10
  }
11
11
  const eventTriggers = new Set<string>()
12
12
 
13
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
13
14
  Object.entries(value.events ?? {}).forEach(([key, event]) => {
14
- if (typeof event.trigger !== 'string') {
15
+ if (typeof event?.trigger !== 'string') {
15
16
  return
16
17
  }
17
18
  if (eventTriggers.has(event.trigger)) {
@@ -1,9 +1,11 @@
1
1
  import { valueFormula } from '@nordcraft/core/dist/formula/formulaUtils'
2
+ import type { ProjectFiles } from '@nordcraft/ssr/dist/ssr.types'
2
3
  import { describe, expect, test } from 'bun:test'
4
+ import { fixProject } from '../../fixProject'
3
5
  import { searchProject } from '../../searchProject'
4
6
  import { noReferenceEventRule } from './noReferenceEventRule'
5
7
 
6
- describe('noReferenceEventRule', () => {
8
+ describe('find noReferenceEventRule', () => {
7
9
  test('should detect events with no references', () => {
8
10
  const problems = Array.from(
9
11
  searchProject({
@@ -146,3 +148,59 @@ describe('noReferenceEventRule', () => {
146
148
  expect(problems).toEqual([])
147
149
  })
148
150
  })
151
+
152
+ describe('fix noReferenceEventRule', () => {
153
+ test('should remove events with no references', () => {
154
+ const files: ProjectFiles = {
155
+ components: {
156
+ test: {
157
+ name: 'test',
158
+ nodes: {
159
+ root: {
160
+ type: 'element',
161
+ attrs: {},
162
+ classes: {},
163
+ events: {
164
+ click: {
165
+ trigger: 'click',
166
+ actions: [
167
+ {
168
+ type: 'TriggerEvent',
169
+ event: 'unknown-event',
170
+ data: valueFormula(null),
171
+ },
172
+ ],
173
+ },
174
+ },
175
+ tag: 'div',
176
+ children: [],
177
+ style: {},
178
+ },
179
+ },
180
+ formulas: {},
181
+ apis: {},
182
+ attributes: {},
183
+ variables: {},
184
+ events: [
185
+ {
186
+ name: 'unused-event',
187
+ // eslint-disable-next-line inclusive-language/use-inclusive-words
188
+ dummyEvent: {
189
+ name: 'Name',
190
+ },
191
+ '@nordcraft/metadata': {
192
+ comments: null,
193
+ },
194
+ },
195
+ ],
196
+ },
197
+ },
198
+ }
199
+ const fixedFiles = fixProject({
200
+ files,
201
+ rule: noReferenceEventRule,
202
+ fixType: 'delete-event',
203
+ })
204
+ expect(fixedFiles.components['test']?.events).toEqual([])
205
+ })
206
+ })
@@ -1,5 +1,6 @@
1
1
  import type { Rule } from '../../types'
2
2
  import { isLegacyAction } from '../../util/helpers'
3
+ import { removeFromPathFix } from '../../util/removeUnused.fix'
3
4
 
4
5
  export const noReferenceEventRule: Rule<{ name: string }> = {
5
6
  code: 'no-reference event',
@@ -9,7 +10,7 @@ export const noReferenceEventRule: Rule<{ name: string }> = {
9
10
  if (args.nodeType !== 'component-event') {
10
11
  return
11
12
  }
12
- const { path, memo, value } = args
13
+ const { memo, value } = args
13
14
  const { component, event } = value
14
15
  const events = memo(`${component.name}-events`, () => {
15
16
  const events = new Set<string>()
@@ -40,7 +41,11 @@ export const noReferenceEventRule: Rule<{ name: string }> = {
40
41
  if (events.has(event.name)) {
41
42
  return
42
43
  }
43
-
44
- report(path, { name: event.name })
44
+ report(args.path, { name: args.value.event.name }, ['delete-event'])
45
+ },
46
+ fixes: {
47
+ 'delete-event': removeFromPathFix,
45
48
  },
46
49
  }
50
+
51
+ export type NoReferenceEventRuleFix = 'delete-event'