@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.
- package/dist/problems.worker.js +13 -5
- package/dist/problems.worker.js.map +1 -1
- package/dist/rules/actions/legacyActionRule.test.js +3 -3
- package/dist/rules/actions/legacyActionRule.test.js.map +1 -1
- package/dist/rules/events/duplicateEventTriggerRule.js +2 -1
- package/dist/rules/events/duplicateEventTriggerRule.js.map +1 -1
- package/dist/rules/logic/noStaticNodeCondition.js +29 -0
- package/dist/rules/logic/noStaticNodeCondition.js.map +1 -0
- package/dist/rules/logic/noStaticNodeCondition.test.js +274 -0
- package/dist/rules/logic/noStaticNodeCondition.test.js.map +1 -0
- package/dist/rules/logic/noUnnecessaryConditionFalsy.js +5 -1
- package/dist/rules/logic/noUnnecessaryConditionFalsy.js.map +1 -1
- package/dist/rules/logic/noUnnecessaryConditionTruthy.js +8 -4
- package/dist/rules/logic/noUnnecessaryConditionTruthy.js.map +1 -1
- package/dist/rules/logic/noUnnecessaryConditionTruthy.test.js +33 -4
- package/dist/rules/logic/noUnnecessaryConditionTruthy.test.js.map +1 -1
- package/dist/rules/noReferenceNodeRule.js +24 -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 +22 -1
- package/dist/searchProject.js.map +1 -1
- package/dist/util/contextlessEvaluateFormula.js +77 -0
- package/dist/util/contextlessEvaluateFormula.js.map +1 -0
- package/dist/util/contextlessEvaluateFormula.test.js +152 -0
- package/dist/util/contextlessEvaluateFormula.test.js.map +1 -0
- package/dist/util/removeUnused.fix.js +18 -1
- package/dist/util/removeUnused.fix.js.map +1 -1
- package/package.json +4 -3
- package/src/problems.worker.ts +20 -7
- package/src/rules/actions/legacyActionRule.test.ts +3 -3
- package/src/rules/events/duplicateEventTriggerRule.ts +2 -1
- package/src/rules/logic/noStaticNodeCondition.test.ts +290 -0
- package/src/rules/logic/noStaticNodeCondition.ts +43 -0
- package/src/rules/logic/noUnnecessaryConditionFalsy.ts +5 -4
- package/src/rules/logic/noUnnecessaryConditionTruthy.test.ts +37 -4
- package/src/rules/logic/noUnnecessaryConditionTruthy.ts +10 -8
- package/src/rules/noReferenceNodeRule.test.ts +140 -0
- package/src/rules/noReferenceNodeRule.ts +34 -0
- package/src/rules/style/invalidStyleSyntaxRule.test.ts +106 -0
- package/src/rules/style/invalidStyleSyntaxRule.ts +35 -0
- package/src/searchProject.ts +25 -1
- package/src/types.d.ts +20 -2
- package/src/util/contextlessEvaluateFormula.test.ts +190 -0
- package/src/util/contextlessEvaluateFormula.ts +110 -0
- package/src/util/removeUnused.fix.ts +29 -1
- 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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type Formula } from '@nordcraft/core/dist/formula/formula'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Static evaluation of a formula.
|
|
5
|
+
*
|
|
6
|
+
* Can be used by issues to determine if a formula or sub-formula can be reduced to a static value.
|
|
7
|
+
* When sophisticated enough, it can be used during compile-time to reduce all static subgraphs of a formula to static values, greatly reducing payload and improving runtime performance.
|
|
8
|
+
*
|
|
9
|
+
* @returns {
|
|
10
|
+
* isStatic: boolean; // Whether the formula is static (i.e., does not depend on any variables, context AND only use pure formulas (no Random, Date, etc.))
|
|
11
|
+
* result: unknown; // The evaluated value of the formula
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* TODO: Make this function more capable of evaluating pure core formulas.
|
|
15
|
+
* TODO: Memoize the results (using path or a fast hash) to avoid re-evaluating any similar sub-graphs multiple times.
|
|
16
|
+
* TODO: Add a complex test-suite to ensure it works and develops as expected.
|
|
17
|
+
*/
|
|
18
|
+
export const contextlessEvaluateFormula = (
|
|
19
|
+
formula: Formula,
|
|
20
|
+
): {
|
|
21
|
+
isStatic: boolean
|
|
22
|
+
result: unknown
|
|
23
|
+
} => {
|
|
24
|
+
// Very basic implementation, just to get started.
|
|
25
|
+
switch (formula.type) {
|
|
26
|
+
case 'value': {
|
|
27
|
+
return {
|
|
28
|
+
isStatic: true,
|
|
29
|
+
result: formula.value,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
case 'array': {
|
|
34
|
+
const results = formula.arguments.map((arg) =>
|
|
35
|
+
contextlessEvaluateFormula(arg.formula),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
isStatic: results.every((res) => res.isStatic),
|
|
40
|
+
result: results.map((res) => res.result),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
case 'record': {
|
|
45
|
+
const entries = Object.entries(formula.entries).map(
|
|
46
|
+
([key, arg]) => [key, contextlessEvaluateFormula(arg.formula)] as const,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const results = entries.map(([, res]) => res)
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
isStatic: results.every((res) => res.isStatic),
|
|
53
|
+
result: Object.fromEntries(
|
|
54
|
+
entries.map(([key, res]) => [key, res.result]),
|
|
55
|
+
),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Static if:
|
|
60
|
+
// - ALL conditions are static AND truthy
|
|
61
|
+
// - ANY condition is static and falsy
|
|
62
|
+
// - EMPTY argument list is always true
|
|
63
|
+
case 'and': {
|
|
64
|
+
const results = formula.arguments.map((arg) =>
|
|
65
|
+
contextlessEvaluateFormula(arg.formula),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const alwaysTrue =
|
|
69
|
+
results.length === 0 ||
|
|
70
|
+
results.every((res) => res.isStatic && Boolean(res.result) === true)
|
|
71
|
+
const alwaysFalsy = results.some(
|
|
72
|
+
(res) => res.isStatic && Boolean(res.result) === false,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
isStatic: alwaysTrue || alwaysFalsy,
|
|
77
|
+
result: alwaysTrue ? true : alwaysFalsy ? false : undefined,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Static if:
|
|
82
|
+
// - ANY condition is static AND truthy
|
|
83
|
+
// - ALL conditions are static AND falsy
|
|
84
|
+
// - EMPTY argument list is always false
|
|
85
|
+
case 'or': {
|
|
86
|
+
const results = formula.arguments.map((arg) =>
|
|
87
|
+
contextlessEvaluateFormula(arg.formula),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
const alwaysFalsy =
|
|
91
|
+
results.length === 0 ||
|
|
92
|
+
results.every((res) => res.isStatic && Boolean(res.result) === false)
|
|
93
|
+
const alwaysTrue = results.some(
|
|
94
|
+
(res) => res.isStatic && Boolean(res.result) === true,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
isStatic: alwaysTrue || alwaysFalsy,
|
|
99
|
+
result: alwaysFalsy ? false : alwaysTrue ? true : undefined,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
default:
|
|
104
|
+
// For now, we assume that any other formula is not static.
|
|
105
|
+
return {
|
|
106
|
+
isStatic: false,
|
|
107
|
+
result: undefined,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NodeModel } from '@nordcraft/core/dist/component/component.types'
|
|
2
|
+
import { get, omit, set } from '@nordcraft/core/dist/utils/collections'
|
|
2
3
|
import type { FixFunction, NodeType } from '../types'
|
|
3
4
|
|
|
4
5
|
export const removeFromPathFix: FixFunction<NodeType> = ({ path, files }) =>
|
|
5
6
|
omit(files, path)
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Same as removeFromPathFix, but also removes the node from its parent's children.
|
|
10
|
+
*/
|
|
11
|
+
export const removeNodeFromPathFix: FixFunction<NodeType> = (data) => {
|
|
12
|
+
if (data.nodeType !== 'component-node') {
|
|
13
|
+
throw new Error('removeNodeFromPathFix can only be used on component nodes')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const componentNodesPath = data.path.slice(0, -1).map(String)
|
|
17
|
+
const filesWithoutNode = removeFromPathFix(data)
|
|
18
|
+
const nodes = get(filesWithoutNode, componentNodesPath) as Record<
|
|
19
|
+
string,
|
|
20
|
+
NodeModel
|
|
21
|
+
>
|
|
22
|
+
for (const key in nodes) {
|
|
23
|
+
if (
|
|
24
|
+
nodes[key].children?.includes(data.path[data.path.length - 1] as string)
|
|
25
|
+
) {
|
|
26
|
+
nodes[key].children = nodes[key].children.filter(
|
|
27
|
+
(p) => p !== data.path[data.path.length - 1],
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return set(filesWithoutNode, componentNodesPath, nodes)
|
|
33
|
+
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export const getAllCustomPropertiesBySyntax = (memo, { files, }) => memo('allCustomPropertiesBySyntax', () => {
|
|
2
|
-
const store = {};
|
|
3
|
-
const add = (propName, syntax, fullPath) => {
|
|
4
|
-
if (syntax.type !== 'primitive')
|
|
5
|
-
return;
|
|
6
|
-
const sName = syntax.name;
|
|
7
|
-
store[propName] ??= {};
|
|
8
|
-
store[propName][sName] ??= [];
|
|
9
|
-
store[propName][sName].push({ syntax, path: fullPath });
|
|
10
|
-
};
|
|
11
|
-
for (const [componentKey, component] of Object.entries(files.components)) {
|
|
12
|
-
for (const [nodeKey, node] of Object.entries(component?.nodes ?? {})) {
|
|
13
|
-
if (node.type !== 'element' && node.type !== 'component')
|
|
14
|
-
continue;
|
|
15
|
-
for (const [propName, prop] of Object.entries(node.customProperties ?? {})) {
|
|
16
|
-
add(propName, prop.syntax, [
|
|
17
|
-
'components',
|
|
18
|
-
componentKey,
|
|
19
|
-
'nodes',
|
|
20
|
-
nodeKey,
|
|
21
|
-
'customProperties',
|
|
22
|
-
propName,
|
|
23
|
-
]);
|
|
24
|
-
}
|
|
25
|
-
node.variants?.forEach((variant, variantIndex) => {
|
|
26
|
-
for (const [propName, prop] of Object.entries(variant.customProperties ?? {})) {
|
|
27
|
-
add(propName, prop.syntax, [
|
|
28
|
-
'components',
|
|
29
|
-
componentKey,
|
|
30
|
-
'nodes',
|
|
31
|
-
nodeKey,
|
|
32
|
-
'variants',
|
|
33
|
-
String(variantIndex),
|
|
34
|
-
'customProperties',
|
|
35
|
-
propName,
|
|
36
|
-
]);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return store;
|
|
42
|
-
});
|
|
43
|
-
//# sourceMappingURL=getAllCustomPropertiesBySyntax.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getAllCustomPropertiesBySyntax.js","sourceRoot":"","sources":["../../src/memos/getAllCustomPropertiesBySyntax.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,IAAY,EACZ,EACE,KAAK,GA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AAE;gBAC/C,KAAK,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAC3C,OAAO,CAAC,gBAAgB,IAAI,EAAE,CAC/B,EAAE,CAAC;oBACF,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE;wBACzB,YAAY;wBACZ,YAAY;wBACZ,OAAO;wBACP,OAAO;wBACP,UAAU;wBACV,MAAM,CAAC,YAAY,CAAC;wBACpB,kBAAkB;wBAClB,QAAQ;qBACT,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAC,CAAA"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { getAllCustomPropertiesBySyntax } from '../../memos/getAllCustomPropertiesBySyntax';
|
|
2
|
-
export const ambiguousStyleVariableSyntaxRule = {
|
|
3
|
-
code: 'ambiguous style variable syntax',
|
|
4
|
-
level: 'error',
|
|
5
|
-
category: 'Other',
|
|
6
|
-
visit: (report, args) => {
|
|
7
|
-
const { nodeType, value, files, memo, path } = args;
|
|
8
|
-
if (nodeType !== 'component-node')
|
|
9
|
-
return;
|
|
10
|
-
if (value.type !== 'element' && value.type !== 'component')
|
|
11
|
-
return;
|
|
12
|
-
const check = (propName, syntax, basePath) => {
|
|
13
|
-
if (syntax.type !== 'primitive')
|
|
14
|
-
return;
|
|
15
|
-
const allCustomPropertiesBySyntax = getAllCustomPropertiesBySyntax(memo, {
|
|
16
|
-
files,
|
|
17
|
-
})[propName];
|
|
18
|
-
const conflicts = Object.entries(allCustomPropertiesBySyntax)
|
|
19
|
-
.filter(([name]) => name !== syntax.name)
|
|
20
|
-
.flatMap(([, entries]) => entries);
|
|
21
|
-
if (conflicts.length > 0) {
|
|
22
|
-
report(basePath, {
|
|
23
|
-
name: propName,
|
|
24
|
-
duplicates: conflicts,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
for (const [propName, prop] of Object.entries(value.customProperties ?? {})) {
|
|
29
|
-
check(propName, prop.syntax, [
|
|
30
|
-
...path,
|
|
31
|
-
'customProperties',
|
|
32
|
-
propName,
|
|
33
|
-
'name',
|
|
34
|
-
]);
|
|
35
|
-
}
|
|
36
|
-
value.variants?.forEach((variant, variantIndex) => {
|
|
37
|
-
for (const [propName, prop] of Object.entries(variant.customProperties ?? {})) {
|
|
38
|
-
check(propName, prop.syntax, [
|
|
39
|
-
...path,
|
|
40
|
-
'variants',
|
|
41
|
-
String(variantIndex),
|
|
42
|
-
'customProperties',
|
|
43
|
-
propName,
|
|
44
|
-
'name',
|
|
45
|
-
]);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=ambiguousStyleVariableSyntaxRule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ambiguousStyleVariableSyntaxRule.js","sourceRoot":"","sources":["../../../src/rules/style-variables/ambiguousStyleVariableSyntaxRule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAA;AAG3F,MAAM,CAAC,MAAM,gCAAgC,GAGxC;IACH,IAAI,EAAE,iCAAiC;IACvC,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,OAAO;IACjB,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACtB,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;QACnD,IAAI,QAAQ,KAAK,gBAAgB;YAAE,OAAM;QACzC,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;YAAE,OAAM;QAElE,MAAM,KAAK,GAAG,CACZ,QAAgB,EAChB,MAAqB,EACrB,QAAgC,EAChC,EAAE;YACF,IAAI,MAAM,C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AA;YACJ,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { searchProject } from '../../searchProject';
|
|
3
|
-
import { ambiguousStyleVariableSyntaxRule } from './ambiguousStyleVariableSyntaxRule';
|
|
4
|
-
describe('ambiguousStyleVariableSyntaxRule', () => {
|
|
5
|
-
test('should report when there are style variables with the same name but different syntax', () => {
|
|
6
|
-
const problems = Array.from(searchProject({
|
|
7
|
-
files: {
|
|
8
|
-
components: {
|
|
9
|
-
component1: {
|
|
10
|
-
name: 'component1',
|
|
11
|
-
nodes: {
|
|
12
|
-
node1: {
|
|
13
|
-
type: 'element',
|
|
14
|
-
customProperties: {
|
|
15
|
-
'--my-variable': {
|
|
16
|
-
syntax: { type: 'primitive', name: 'length' },
|
|
17
|
-
formula: { type: 'value', value: '10px' },
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
attrs: {},
|
|
21
|
-
style: {},
|
|
22
|
-
children: [],
|
|
23
|
-
events: {},
|
|
24
|
-
classes: {},
|
|
25
|
-
tag: 'div',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
apis: {},
|
|
29
|
-
attributes: {},
|
|
30
|
-
variables: {},
|
|
31
|
-
formulas: {},
|
|
32
|
-
},
|
|
33
|
-
component2: {
|
|
34
|
-
name: 'component2',
|
|
35
|
-
nodes: {
|
|
36
|
-
node2: {
|
|
37
|
-
type: 'element',
|
|
38
|
-
customProperties: {
|
|
39
|
-
'--my-variable': {
|
|
40
|
-
syntax: { type: 'primitive', name: 'color' },
|
|
41
|
-
formula: { type: 'value', value: '#ff0000' },
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
attrs: {},
|
|
45
|
-
style: {},
|
|
46
|
-
children: [],
|
|
47
|
-
events: {},
|
|
48
|
-
classes: {},
|
|
49
|
-
tag: 'div',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
apis: {},
|
|
53
|
-
attributes: {},
|
|
54
|
-
variables: {},
|
|
55
|
-
formulas: {},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
rules: [ambiguousStyleVariableSyntaxRule],
|
|
60
|
-
}));
|
|
61
|
-
expect(problems).toHaveLength(2);
|
|
62
|
-
expect(problems[0].code).toBe('ambiguous style variable syntax');
|
|
63
|
-
expect(problems[1].code).toBe('ambiguous style variable syntax');
|
|
64
|
-
expect(problems[0].details.name).toBe('--my-variable');
|
|
65
|
-
expect(problems[1].details.name).toBe('--my-variable');
|
|
66
|
-
expect(problems[0].details.duplicates).toEqual([
|
|
67
|
-
{
|
|
68
|
-
path: [
|
|
69
|
-
'components',
|
|
70
|
-
'component2',
|
|
71
|
-
'nodes',
|
|
72
|
-
'node2',
|
|
73
|
-
'customProperties',
|
|
74
|
-
'--my-variable',
|
|
75
|
-
],
|
|
76
|
-
syntax: { type: 'primitive', name: 'color' },
|
|
77
|
-
},
|
|
78
|
-
]);
|
|
79
|
-
expect(problems[1].details.duplicates).toEqual([
|
|
80
|
-
{
|
|
81
|
-
path: [
|
|
82
|
-
'components',
|
|
83
|
-
'component1',
|
|
84
|
-
'nodes',
|
|
85
|
-
'node1',
|
|
86
|
-
'customProperties',
|
|
87
|
-
'--my-variable',
|
|
88
|
-
],
|
|
89
|
-
syntax: { type: 'primitive', name: 'length' },
|
|
90
|
-
},
|
|
91
|
-
]);
|
|
92
|
-
});
|
|
93
|
-
test('should not report when style variables have same name and same syntax', () => {
|
|
94
|
-
const problems = Array.from(searchProject({
|
|
95
|
-
files: {
|
|
96
|
-
components: {
|
|
97
|
-
component1: {
|
|
98
|
-
name: 'component1',
|
|
99
|
-
nodes: {
|
|
100
|
-
node1: {
|
|
101
|
-
type: 'element',
|
|
102
|
-
customProperties: {
|
|
103
|
-
'--my-variable': {
|
|
104
|
-
syntax: { type: 'primitive', name: 'length' },
|
|
105
|
-
formula: { type: 'value', value: '10px' },
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
attrs: {},
|
|
109
|
-
style: {},
|
|
110
|
-
children: [],
|
|
111
|
-
events: {},
|
|
112
|
-
classes: {},
|
|
113
|
-
tag: 'div',
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
apis: {},
|
|
117
|
-
attributes: {},
|
|
118
|
-
variables: {},
|
|
119
|
-
formulas: {},
|
|
120
|
-
},
|
|
121
|
-
component2: {
|
|
122
|
-
name: 'component2',
|
|
123
|
-
nodes: {
|
|
124
|
-
node2: {
|
|
125
|
-
type: 'element',
|
|
126
|
-
customProperties: {
|
|
127
|
-
'--my-variable': {
|
|
128
|
-
syntax: { type: 'primitive', name: 'length' },
|
|
129
|
-
formula: { type: 'value', value: '20px' },
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
attrs: {},
|
|
133
|
-
style: {},
|
|
134
|
-
children: [],
|
|
135
|
-
events: {},
|
|
136
|
-
classes: {},
|
|
137
|
-
tag: 'div',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
apis: {},
|
|
141
|
-
attributes: {},
|
|
142
|
-
variables: {},
|
|
143
|
-
formulas: {},
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
rules: [ambiguousStyleVariableSyntaxRule],
|
|
148
|
-
}));
|
|
149
|
-
expect(problems).toHaveLength(0);
|
|
150
|
-
});
|
|
151
|
-
test('should handle variant customProperties too', () => {
|
|
152
|
-
const problems = Array.from(searchProject({
|
|
153
|
-
files: {
|
|
154
|
-
components: {
|
|
155
|
-
component1: {
|
|
156
|
-
name: 'component1',
|
|
157
|
-
nodes: {
|
|
158
|
-
node1: {
|
|
159
|
-
type: 'element',
|
|
160
|
-
customProperties: {
|
|
161
|
-
'--my-variable': {
|
|
162
|
-
syntax: { type: 'primitive', name: 'length' },
|
|
163
|
-
formula: { type: 'value', value: '10px' },
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
variants: [
|
|
167
|
-
{
|
|
168
|
-
breakpoint: 'medium',
|
|
169
|
-
style: {},
|
|
170
|
-
customProperties: {
|
|
171
|
-
'--my-variable': {
|
|
172
|
-
syntax: { type: 'primitive', name: 'color' },
|
|
173
|
-
formula: { type: 'value', value: '#ff0000' },
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
attrs: {},
|
|
179
|
-
style: {},
|
|
180
|
-
children: [],
|
|
181
|
-
events: {},
|
|
182
|
-
classes: {},
|
|
183
|
-
tag: 'div',
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
apis: {},
|
|
187
|
-
attributes: {},
|
|
188
|
-
variables: {},
|
|
189
|
-
formulas: {},
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
rules: [ambiguousStyleVariableSyntaxRule],
|
|
194
|
-
}));
|
|
195
|
-
// Should flag both the base and the variant for conflicting syntax
|
|
196
|
-
expect(problems).toHaveLength(2);
|
|
197
|
-
expect(problems.map((p) => p.details.name)).toEqual([
|
|
198
|
-
'--my-variable',
|
|
199
|
-
'--my-variable',
|
|
200
|
-
]);
|
|
201
|
-
});
|
|
202
|
-
test('should ignore non-primitive syntax', () => {
|
|
203
|
-
const problems = Array.from(searchProject({
|
|
204
|
-
files: {
|
|
205
|
-
components: {
|
|
206
|
-
component1: {
|
|
207
|
-
name: 'component1',
|
|
208
|
-
nodes: {
|
|
209
|
-
node1: {
|
|
210
|
-
type: 'element',
|
|
211
|
-
customProperties: {
|
|
212
|
-
'--my-variable': {
|
|
213
|
-
syntax: {
|
|
214
|
-
type: 'keyword',
|
|
215
|
-
keywords: ['auto', 'inherit'],
|
|
216
|
-
},
|
|
217
|
-
formula: { type: 'value', value: '10px' },
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
attrs: {},
|
|
221
|
-
style: {},
|
|
222
|
-
children: [],
|
|
223
|
-
events: {},
|
|
224
|
-
classes: {},
|
|
225
|
-
tag: 'div',
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
apis: {},
|
|
229
|
-
attributes: {},
|
|
230
|
-
variables: {},
|
|
231
|
-
formulas: {},
|
|
232
|
-
},
|
|
233
|
-
component2: {
|
|
234
|
-
name: 'component2',
|
|
235
|
-
nodes: {
|
|
236
|
-
node2: {
|
|
237
|
-
type: 'element',
|
|
238
|
-
customProperties: {
|
|
239
|
-
'--my-variable': {
|
|
240
|
-
syntax: { type: 'primitive', name: 'color' },
|
|
241
|
-
formula: { type: 'value', value: '#ff0000' },
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
attrs: {},
|
|
245
|
-
style: {},
|
|
246
|
-
children: [],
|
|
247
|
-
events: {},
|
|
248
|
-
classes: {},
|
|
249
|
-
tag: 'div',
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
apis: {},
|
|
253
|
-
attributes: {},
|
|
254
|
-
variables: {},
|
|
255
|
-
formulas: {},
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
rules: [ambiguousStyleVariableSyntaxRule],
|
|
260
|
-
}));
|
|
261
|
-
// Should not report because non-primitive should be skipped
|
|
262
|
-
expect(problems).toHaveLength(0);
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
//# sourceMappingURL=ambiguousStyleVariableSyntaxRule.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ambiguousStyleVariableSyntaxRule.test.js","sourceRoot":"","sources":["../../../src/rules/style-variables/ambiguousStyleVariableSyntaxRule.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAA;AAErF,QAAQ,CAAC,kCAAkC,EAAE,GAAG,E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EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE;wCAC5C,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE;qCAC7C;iCACF;gCACD,KAAK,EAAE,EAAE;gCACT,KAAK,EAAE,EAAE;gCACT,QAAQ,EAAE,EAAE;gCACZ,MAAM,EAAE,EAAE;gCACV,OAAO,EAAE,EAAE;gCACX,GAAG,EAAE,KAAK;6BACX;yBACF;wBACD,IAAI,EAAE,EAAE;wBACR,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;wBACb,QAAQ,EAAE,EAAE;qBACb;iBACF;aACF;YACD,KAAK,EAAE,CAAC,gCAAgC,CAAC;SAC1C,CAAC,CACH,CAAA;QAED,4DAA4D;QAC5D,MAAM,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { CssSyntaxNode } from '@nordcraft/core/dist/styling/customProperty'
|
|
2
|
-
import type { ProjectFiles } from '@nordcraft/ssr/dist/ssr.types'
|
|
3
|
-
import type { MemoFn } from '../types'
|
|
4
|
-
|
|
5
|
-
export const getAllCustomPropertiesBySyntax = (
|
|
6
|
-
memo: MemoFn,
|
|
7
|
-
{
|
|
8
|
-
files,
|
|
9
|
-
}: {
|
|
10
|
-
files: Omit<ProjectFiles, 'config'> & Partial<Pick<ProjectFiles, 'config'>>
|
|
11
|
-
},
|
|
12
|
-
) =>
|
|
13
|
-
memo('allCustomPropertiesBySyntax', () => {
|
|
14
|
-
const store: Record<
|
|
15
|
-
string,
|
|
16
|
-
Record<string, Array<{ syntax: CssSyntaxNode; path: string[] }>>
|
|
17
|
-
> = {}
|
|
18
|
-
|
|
19
|
-
const add = (
|
|
20
|
-
propName: string,
|
|
21
|
-
syntax: CssSyntaxNode,
|
|
22
|
-
fullPath: string[],
|
|
23
|
-
) => {
|
|
24
|
-
if (syntax.type !== 'primitive') return
|
|
25
|
-
const sName = syntax.name
|
|
26
|
-
store[propName] ??= {}
|
|
27
|
-
store[propName][sName] ??= []
|
|
28
|
-
store[propName][sName].push({ syntax, path: fullPath })
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
for (const [componentKey, component] of Object.entries(files.components)) {
|
|
32
|
-
for (const [nodeKey, node] of Object.entries(component?.nodes ?? {})) {
|
|
33
|
-
if (node.type !== 'element' && node.type !== 'component') continue
|
|
34
|
-
|
|
35
|
-
for (const [propName, prop] of Object.entries(
|
|
36
|
-
node.customProperties ?? {},
|
|
37
|
-
)) {
|
|
38
|
-
add(propName, prop.syntax, [
|
|
39
|
-
'components',
|
|
40
|
-
componentKey,
|
|
41
|
-
'nodes',
|
|
42
|
-
nodeKey,
|
|
43
|
-
'customProperties',
|
|
44
|
-
propName,
|
|
45
|
-
])
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
node.variants?.forEach((variant, variantIndex) => {
|
|
49
|
-
for (const [propName, prop] of Object.entries(
|
|
50
|
-
variant.customProperties ?? {},
|
|
51
|
-
)) {
|
|
52
|
-
add(propName, prop.syntax, [
|
|
53
|
-
'components',
|
|
54
|
-
componentKey,
|
|
55
|
-
'nodes',
|
|
56
|
-
nodeKey,
|
|
57
|
-
'variants',
|
|
58
|
-
String(variantIndex),
|
|
59
|
-
'customProperties',
|
|
60
|
-
propName,
|
|
61
|
-
])
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return store
|
|
68
|
-
})
|