@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.
- package/dist/problems.worker.js +4 -2
- package/dist/problems.worker.js.map +1 -1
- package/dist/rules/actions/legacyActionRule.fix.js +140 -0
- package/dist/rules/actions/legacyActionRule.fix.js.map +1 -0
- package/dist/rules/actions/legacyActionRule.js +3 -144
- package/dist/rules/actions/legacyActionRule.js.map +1 -1
- package/dist/rules/actions/legacyActionRule.test.js +4 -3
- package/dist/rules/actions/legacyActionRule.test.js.map +1 -1
- package/dist/rules/actions/noReferenceProjectActionRule.js +33 -40
- package/dist/rules/actions/noReferenceProjectActionRule.js.map +1 -1
- package/dist/rules/apis/noReferenceApiRule.js +7 -2
- package/dist/rules/apis/noReferenceApiRule.js.map +1 -1
- package/dist/rules/apis/noReferenceApiRule.test.js +65 -1
- package/dist/rules/apis/noReferenceApiRule.test.js.map +1 -1
- package/dist/rules/attributes/noReferenceAttributeRule.js +5 -1
- package/dist/rules/attributes/noReferenceAttributeRule.js.map +1 -1
- package/dist/rules/attributes/noReferenceAttributeRule.test.js +33 -1
- package/dist/rules/attributes/noReferenceAttributeRule.test.js.map +1 -1
- package/dist/rules/components/noReferenceComponentRule.js +18 -28
- package/dist/rules/components/noReferenceComponentRule.js.map +1 -1
- package/dist/rules/events/duplicateEventTriggerRule.js +2 -1
- package/dist/rules/events/duplicateEventTriggerRule.js.map +1 -1
- package/dist/rules/events/noReferenceEventRule.js +6 -2
- package/dist/rules/events/noReferenceEventRule.js.map +1 -1
- package/dist/rules/events/noReferenceEventRule.test.js +57 -1
- package/dist/rules/events/noReferenceEventRule.test.js.map +1 -1
- package/dist/rules/formulas/legacyFormulaRule.fix.js +574 -0
- package/dist/rules/formulas/legacyFormulaRule.fix.js.map +1 -0
- package/dist/rules/formulas/legacyFormulaRule.js +5 -580
- package/dist/rules/formulas/legacyFormulaRule.js.map +1 -1
- package/dist/rules/formulas/noReferenceComponentFormulaRule.js +8 -1
- package/dist/rules/formulas/noReferenceComponentFormulaRule.js.map +1 -1
- package/dist/rules/formulas/noReferenceProjectFormulaRule.js +63 -72
- package/dist/rules/formulas/noReferenceProjectFormulaRule.js.map +1 -1
- package/dist/rules/noReferenceNodeRule.js +22 -0
- package/dist/rules/noReferenceNodeRule.js.map +1 -0
- package/dist/rules/noReferenceNodeRule.test.js +131 -0
- package/dist/rules/noReferenceNodeRule.test.js.map +1 -0
- package/dist/rules/style/invalidStyleSyntaxRule.js +28 -0
- package/dist/rules/style/invalidStyleSyntaxRule.js.map +1 -0
- package/dist/rules/style/invalidStyleSyntaxRule.test.js +100 -0
- package/dist/rules/style/invalidStyleSyntaxRule.test.js.map +1 -0
- package/dist/searchProject.js +57 -16
- package/dist/searchProject.js.map +1 -1
- package/dist/util/removeUnused.fix.js +3 -0
- package/dist/util/removeUnused.fix.js.map +1 -0
- package/package.json +4 -3
- package/src/problems.worker.ts +4 -2
- package/src/rules/actions/legacyActionRule.fix.ts +157 -0
- package/src/rules/actions/legacyActionRule.test.ts +4 -3
- package/src/rules/actions/legacyActionRule.ts +3 -159
- package/src/rules/actions/noReferenceProjectActionRule.ts +39 -47
- package/src/rules/apis/noReferenceApiRule.test.ts +67 -1
- package/src/rules/apis/noReferenceApiRule.ts +9 -2
- package/src/rules/attributes/noReferenceAttributeRule.test.ts +35 -1
- package/src/rules/attributes/noReferenceAttributeRule.ts +7 -2
- package/src/rules/components/noReferenceComponentRule.ts +23 -34
- package/src/rules/events/duplicateEventTriggerRule.ts +2 -1
- package/src/rules/events/noReferenceEventRule.test.ts +59 -1
- package/src/rules/events/noReferenceEventRule.ts +8 -3
- package/src/rules/formulas/legacyFormulaRule.fix.ts +661 -0
- package/src/rules/formulas/legacyFormulaRule.ts +9 -670
- package/src/rules/formulas/noReferenceComponentFormulaRule.ts +15 -3
- package/src/rules/formulas/noReferenceProjectFormulaRule.ts +70 -77
- package/src/rules/noReferenceNodeRule.test.ts +140 -0
- package/src/rules/noReferenceNodeRule.ts +27 -0
- package/src/rules/style/invalidStyleSyntaxRule.test.ts +106 -0
- package/src/rules/style/invalidStyleSyntaxRule.ts +35 -0
- package/src/searchProject.ts +66 -22
- package/src/types.d.ts +33 -10
- package/src/util/removeUnused.fix.ts +5 -0
- package/dist/memos/getAllCustomPropertiesBySyntax.js +0 -43
- package/dist/memos/getAllCustomPropertiesBySyntax.js.map +0 -1
- package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.js +0 -50
- package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.js.map +0 -1
- package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.js +0 -265
- package/dist/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.js.map +0 -1
- package/src/memos/getAllCustomPropertiesBySyntax.ts +0 -68
- package/src/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.ts +0 -278
- 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 {
|
|
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
|
-
|
|
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 {
|
|
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 (
|
|
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':
|
|
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
|
|
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 {
|
|
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
|
-
|
|
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'
|