@nordcraft/search 1.0.89 → 1.0.90
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/rules/issues/actions/noReferenceProjectActionRule.js +2 -27
- package/dist/rules/issues/actions/noReferenceProjectActionRule.js.map +1 -1
- package/dist/rules/issues/actions/projectActionIsReferenced.memo.d.ts +3 -0
- package/dist/rules/issues/actions/projectActionIsReferenced.memo.js +38 -0
- package/dist/rules/issues/actions/projectActionIsReferenced.memo.js.map +1 -0
- package/dist/rules/issues/attributes/noReferenceAttributeInInstanceRule.js +2 -2
- package/dist/rules/issues/attributes/noReferenceAttributeInInstanceRule.js.map +1 -1
- package/dist/rules/issues/components/componentIsReferenced.memo.d.ts +3 -0
- package/dist/rules/issues/components/componentIsReferenced.memo.js +25 -0
- package/dist/rules/issues/components/componentIsReferenced.memo.js.map +1 -0
- package/dist/rules/issues/components/noReferenceComponentRule.d.ts +1 -3
- package/dist/rules/issues/components/noReferenceComponentRule.js +8 -26
- package/dist/rules/issues/components/noReferenceComponentRule.js.map +1 -1
- package/dist/rules/issues/formulas/noReferenceProjectFormulaRule.js +2 -85
- package/dist/rules/issues/formulas/noReferenceProjectFormulaRule.js.map +1 -1
- package/dist/rules/issues/formulas/projectFormulaIsReferenced.memo.d.ts +3 -0
- package/dist/rules/issues/formulas/projectFormulaIsReferenced.memo.js +84 -0
- package/dist/rules/issues/formulas/projectFormulaIsReferenced.memo.js.map +1 -0
- package/dist/rules/issues/miscellaneous/miscRules.index.js +2 -0
- package/dist/rules/issues/miscellaneous/miscRules.index.js.map +1 -1
- package/dist/rules/issues/miscellaneous/noReferencePackageRule.d.ts +5 -0
- package/dist/rules/issues/miscellaneous/noReferencePackageRule.js +54 -0
- package/dist/rules/issues/miscellaneous/noReferencePackageRule.js.map +1 -0
- package/dist/searchProject.js +23 -0
- package/dist/searchProject.js.map +1 -1
- package/dist/types.d.ts +10 -4
- package/package.json +3 -3
- package/src/rules/issues/actions/noReferenceProjectActionRule.ts +2 -32
- package/src/rules/issues/actions/projectActionIsReferenced.memo.ts +52 -0
- package/src/rules/issues/attributes/noReferenceAttributeInInstanceRule.ts +2 -2
- package/src/rules/issues/components/componentIsReferenced.memo.ts +39 -0
- package/src/rules/issues/components/noReferenceComponentRule.ts +10 -39
- package/src/rules/issues/formulas/noReferenceProjectFormulaRule.test.ts +33 -0
- package/src/rules/issues/formulas/noReferenceProjectFormulaRule.ts +2 -102
- package/src/rules/issues/formulas/projectFormulaIsReferenced.memo.ts +112 -0
- package/src/rules/issues/miscellaneous/miscRules.index.ts +2 -0
- package/src/rules/issues/miscellaneous/noReferencePackageRule.test.ts +289 -0
- package/src/rules/issues/miscellaneous/noReferencePackageRule.ts +72 -0
- package/src/searchProject.ts +24 -0
- package/src/types.ts +11 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isLegacyPluginAction } from '@nordcraft/core/dist/component/actionUtils';
|
|
2
|
-
import { ToddleComponent } from '@nordcraft/core/dist/component/ToddleComponent';
|
|
3
2
|
import { removeFromPathFix } from '../../../util/removeUnused.fix';
|
|
3
|
+
import { projectActionIsReferenced } from './projectActionIsReferenced.memo';
|
|
4
4
|
export const noReferenceProjectActionRule = {
|
|
5
5
|
code: 'no-reference project action',
|
|
6
6
|
level: 'warning',
|
|
@@ -10,32 +10,7 @@ export const noReferenceProjectActionRule = {
|
|
|
10
10
|
(!isLegacyPluginAction(value) && value.exported === true)) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
const usedActions = new Set();
|
|
15
|
-
for (const component of Object.values(files.components)) {
|
|
16
|
-
const c = new ToddleComponent({
|
|
17
|
-
// Enforce that the component is not undefined since we're iterating
|
|
18
|
-
component: component,
|
|
19
|
-
getComponent: (name, packageName) => packageName
|
|
20
|
-
? files.packages?.[packageName]?.components[name]
|
|
21
|
-
: files.components[name],
|
|
22
|
-
packageName: undefined,
|
|
23
|
-
globalFormulas: {
|
|
24
|
-
formulas: files.formulas,
|
|
25
|
-
packages: files.packages,
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
for (const [, action] of c.actionModelsInComponent()) {
|
|
29
|
-
if (action.type === 'Custom' ||
|
|
30
|
-
action.type === 'function' ||
|
|
31
|
-
action.type === undefined) {
|
|
32
|
-
usedActions.add(action.name);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return usedActions;
|
|
37
|
-
});
|
|
38
|
-
if (!projectActionReferences.has(value.name)) {
|
|
13
|
+
if (!projectActionIsReferenced(files, memo)(value.name)) {
|
|
39
14
|
report({
|
|
40
15
|
path,
|
|
41
16
|
info: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noReferenceProjectActionRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/actions/noReferenceProjectActionRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AAEjF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"noReferenceProjectActionRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/actions/noReferenceProjectActionRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AAEjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAE5E,MAAM,CAAC,MAAM,4BAA4B,GAAe;IACtD,IAAI,EAAE,6BAA6B;IACnC,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QACzD,IACE,QAAQ,KAAK,gBAAgB;YAC7B,CAAC,CAAC,oBAAoB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,EACzD,CAAC;YACD,OAAM;QACR,CAAC;QAED,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACxD,MAAM,CAAC;gBACL,IAAI;gBACJ,IAAI,EAAE;oBACJ,KAAK,EAAE,sBAAsB;oBAC7B,WAAW,EAAE,6DAA6D;iBAC3E;gBACD,KAAK,EAAE,CAAC,uBAAuB,CAAC;aACjC,CAAC,CAAA;QACJ,CAAC;IAAA,CACF;IACD,KAAK,EAAE;QACL,uBAAuB,EAAE,iBAAiB;KAC3C;CACF,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProjectFiles } from '@nordcraft/ssr/dist/ssr.types';
|
|
2
|
+
import type { MemoFn } from '../../../types';
|
|
3
|
+
export declare const projectActionIsReferenced: (files: Omit<ProjectFiles, "config"> & Partial<Pick<ProjectFiles, "config">>, memo: MemoFn) => (actionName: string, packageName?: string | undefined) => boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ToddleComponent } from '@nordcraft/core/dist/component/ToddleComponent';
|
|
2
|
+
import { isDefined } from '@nordcraft/core/dist/utils/util';
|
|
3
|
+
export const projectActionIsReferenced = (files, memo) => {
|
|
4
|
+
const usedActions = memo('all-used-project-actions', () => {
|
|
5
|
+
const usedActions = new Set();
|
|
6
|
+
for (const component of Object.values(files.components)) {
|
|
7
|
+
const c = new ToddleComponent({
|
|
8
|
+
// Enforce that the component is not undefined since we're iterating
|
|
9
|
+
component: component,
|
|
10
|
+
getComponent: (name, packageName) => packageName
|
|
11
|
+
? files.packages?.[packageName]?.components[name]
|
|
12
|
+
: files.components[name],
|
|
13
|
+
packageName: undefined,
|
|
14
|
+
globalFormulas: {
|
|
15
|
+
formulas: files.formulas,
|
|
16
|
+
packages: files.packages,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
for (const [, action] of c.actionModelsInComponent()) {
|
|
20
|
+
if (action.type === 'Custom' ||
|
|
21
|
+
action.type === 'function' ||
|
|
22
|
+
action.type === undefined) {
|
|
23
|
+
usedActions.add([
|
|
24
|
+
action.package,
|
|
25
|
+
action.name,
|
|
26
|
+
]
|
|
27
|
+
.filter(isDefined)
|
|
28
|
+
.join('/'));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return usedActions;
|
|
33
|
+
});
|
|
34
|
+
return (actionName, packageName) => {
|
|
35
|
+
return usedActions.has([packageName, actionName].filter(isDefined).join('/'));
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=projectActionIsReferenced.memo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectActionIsReferenced.memo.js","sourceRoot":"","sources":["../../../../src/rules/issues/actions/projectActionIsReferenced.memo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAI3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,KAA2E,EAC3E,IAAY,EACZ,EAAE,CAAC;IACH,MAAM,WAAW,GAAG,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC;QACzD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAA;QACrC,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;YACxD,MAAM,CAAC,GAAG,IAAI,eAAe,CAAC;gBAC5B,oEAAoE;gBACpE,SAAS,EAAE,SAAU;gBACrB,YAAY,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,CAClC,WAAW;oBACT,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC;oBACjD,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;gBAC5B,WAAW,EAAE,SAAS;gBACtB,cAAc,EAAE;oBACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;iBACzB;aACF,CAAC,CAAA;YACF,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,uBAAuB,EAAE,EAAE,CAAC;gBACrD,IACE,MAAM,CAAC,IAAI,KAAK,QAAQ;oBACxB,MAAM,CAAC,IAAI,KAAM,UAAkB;oBACnC,MAAM,CAAC,IAAI,KAAK,SAAS,EACzB,CAAC;oBACD,WAAW,CAAC,GAAG,CACb;wBACG,MAA4B,CAAC,OAAO;wBACpC,MAA4B,CAAC,IAAI;qBACnC;yBACE,MAAM,CAAC,SAAS,CAAC;yBACjB,IAAI,CAAC,GAAG,CAAC,CACb,CAAA;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,WAAW,CAAA;IAAA,CACnB,CAAC,CAAA;IAEF,OAAO,CAAC,UAAkB,EAAE,WAAoB,EAAE,EAAE,CAAC;QACnD,OAAO,WAAW,CAAC,GAAG,CACpB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CACtD,CAAA;IAAA,CACF,CAAA;AAAA,CACF,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { contextlessEvaluateFormula } from '../../../util/contextlessEvaluateFormula';
|
|
2
2
|
import { removeFromPathFix } from '../../../util/removeUnused.fix';
|
|
3
|
-
import { componentIsReferenced } from '../components/
|
|
3
|
+
import { componentIsReferenced } from '../components/componentIsReferenced.memo';
|
|
4
4
|
export const noReferenceAttributeInInstanceRule = {
|
|
5
5
|
code: 'no-reference attribute in instance',
|
|
6
6
|
level: 'info',
|
|
@@ -19,7 +19,7 @@ export const noReferenceAttributeInInstanceRule = {
|
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
// If component is never used, skip this rule as we have another rule to find unused components (no-reference component)
|
|
22
|
-
if (!componentIsReferenced(args.files
|
|
22
|
+
if (!componentIsReferenced(args.files, memo)(component.name)) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
// Gather all instead of only used in this component for optimization purposes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noReferenceAttributeInInstanceRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/attributes/noReferenceAttributeInInstanceRule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAA;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"noReferenceAttributeInInstanceRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/attributes/noReferenceAttributeInInstanceRule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAA;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAEhF,MAAM,CAAC,MAAM,kCAAkC,GAAe;IAC5D,IAAI,EAAE,oCAAoC;IAC1C,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC9B,IACE,IAAI,CAAC,QAAQ,KAAK,qBAAqB;YACvC,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,KAAK,SAAS;gBACxC,IAAI,CAAC,SAAS,CAAC,QAAQ,KAAK,IAAI,CAAC;YACnC,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC;iBAC9D,MAAM,KAAK,IAAI,EAClB,CAAC;YACD,OAAM;QACR,CAA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C,EAAE,CAAC;YACxD,OAAM;QACR,CAAC;QACD,MAAM,CAAC;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE;gBACJ,KAAK,EAAE,wCAAwC;gBAC/C,WAAW,EAAE,mBAAmB,YAAY,gHAAgH;aAC7J;YACD,KAAK,EAAE,CAAC,kBAAkB,CAAC;SAC5B,CAAC,CAAA;IAAA,CACH;IACD,KAAK,EAAE;QACL,kBAAkB,EAAE,iBAAiB;KACtC;CACF,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProjectFiles } from '@nordcraft/ssr/dist/ssr.types';
|
|
2
|
+
import type { MemoFn } from '../../../types';
|
|
3
|
+
export declare const componentIsReferenced: (files: Omit<ProjectFiles, "config"> & Partial<Pick<ProjectFiles, "config">>, memo: MemoFn) => (componentName: string, packageName?: string | undefined) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isDefined } from '@nordcraft/core/dist/utils/util';
|
|
2
|
+
export const componentIsReferenced = (files, memo) => {
|
|
3
|
+
const usedComponents = memo('all-used-components', () => {
|
|
4
|
+
const used = new Set();
|
|
5
|
+
Object.values(files.components).forEach((component) => {
|
|
6
|
+
Object.values(component?.nodes ?? {})
|
|
7
|
+
.filter((node) => node.type === 'component' &&
|
|
8
|
+
// Do not add cyclical references
|
|
9
|
+
node.name !== component?.name)
|
|
10
|
+
.forEach((instance) => {
|
|
11
|
+
used.add([
|
|
12
|
+
instance.package,
|
|
13
|
+
instance.name,
|
|
14
|
+
]
|
|
15
|
+
.filter(isDefined)
|
|
16
|
+
.join('/'));
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return used;
|
|
20
|
+
});
|
|
21
|
+
return (componentName, packageName) => {
|
|
22
|
+
return usedComponents.has([packageName, componentName].filter(isDefined).join('/'));
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=componentIsReferenced.memo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentIsReferenced.memo.js","sourceRoot":"","sources":["../../../../src/rules/issues/components/componentIsReferenced.memo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAI3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAA2E,EAC3E,IAAY,EACZ,EAAE,CAAC;IACH,MAAM,cAAc,GAAG,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE,CAAC;QACvD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;QAC9B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC;YACrD,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC;iBAClC,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,IAAI,KAAK,WAAW;gBACzB,iCAAiC;gBACjC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,IAAI,CAChC;iBACA,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACrB,IAAI,CAAC,GAAG,CACN;oBACG,QAA+B,CAAC,OAAO;oBACvC,QAA+B,CAAC,IAAI;iBACtC;qBACE,MAAM,CAAC,SAAS,CAAC;qBACjB,IAAI,CAAC,GAAG,CAAC,CACb,CAAA;YAAA,CACF,CAAC,CAAA;QAAA,CACL,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IAAA,CACZ,CAAC,CAAA;IAEF,OAAO,CAAC,aAAqB,EAAE,WAAoB,EAAE,EAAE,CAAC;QACtD,OAAO,cAAc,CAAC,GAAG,CACvB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CACzD,CAAA;IAAA,CACF,CAAA;AAAA,CACF,CAAA"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { MemoFn, Rule } from '../../../types';
|
|
1
|
+
import type { Rule } from '../../../types';
|
|
3
2
|
export declare const noReferenceComponentRule: Rule<void>;
|
|
4
3
|
export type NoReferenceComponentRuleFix = 'delete-component';
|
|
5
|
-
export declare const componentIsReferenced: (components: Partial<Record<string, Component>>, memo: MemoFn) => (componentName: string) => boolean;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { isDefined } from '@nordcraft/core/dist/utils/util';
|
|
2
2
|
import { contextlessEvaluateFormula } from '../../../util/contextlessEvaluateFormula';
|
|
3
3
|
import { removeFromPathFix } from '../../../util/removeUnused.fix';
|
|
4
|
+
import { componentIsReferenced } from './componentIsReferenced.memo';
|
|
4
5
|
export const noReferenceComponentRule = {
|
|
5
6
|
code: 'no-reference component',
|
|
6
7
|
level: 'warning',
|
|
7
8
|
category: 'No References',
|
|
8
|
-
visit: (report,
|
|
9
|
-
if (
|
|
10
|
-
isPage(
|
|
11
|
-
(state?.projectDetails?.type === 'package' &&
|
|
12
|
-
|
|
13
|
-
contextlessEvaluateFormula(data.value.customElement?.enabled).result ===
|
|
9
|
+
visit: (report, { files, nodeType, value, path, memo }, state) => {
|
|
10
|
+
if (nodeType !== 'component' ||
|
|
11
|
+
isPage(value) ||
|
|
12
|
+
(state?.projectDetails?.type === 'package' && value.exported === true) ||
|
|
13
|
+
contextlessEvaluateFormula(value.customElement?.enabled).result ===
|
|
14
14
|
true ||
|
|
15
|
-
componentIsReferenced(
|
|
15
|
+
componentIsReferenced(files, memo)(value.name)) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
report({
|
|
19
|
-
path
|
|
19
|
+
path,
|
|
20
20
|
info: {
|
|
21
21
|
title: 'Unused component',
|
|
22
22
|
description: '**Component** is never used by any page or component. Consider removing it.',
|
|
@@ -28,23 +28,5 @@ export const noReferenceComponentRule = {
|
|
|
28
28
|
'delete-component': removeFromPathFix,
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
|
-
export const componentIsReferenced = (components, memo) => {
|
|
32
|
-
const usedComponents = memo('all-used-components', () => {
|
|
33
|
-
const used = new Set();
|
|
34
|
-
Object.values(components).forEach((component) => {
|
|
35
|
-
Object.values(component?.nodes ?? {})
|
|
36
|
-
.filter((node) => node.type === 'component' &&
|
|
37
|
-
// Do not add cyclical references
|
|
38
|
-
node.name !== component?.name)
|
|
39
|
-
.forEach((instance) => {
|
|
40
|
-
used.add(instance.name);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
return used;
|
|
44
|
-
});
|
|
45
|
-
return (componentName) => {
|
|
46
|
-
return usedComponents.has(componentName);
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
31
|
const isPage = (value) => isDefined(value.route);
|
|
50
32
|
//# sourceMappingURL=noReferenceComponentRule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noReferenceComponentRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/components/noReferenceComponentRule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"noReferenceComponentRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/components/noReferenceComponentRule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAE3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAA;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAEpE,MAAM,CAAC,MAAM,wBAAwB,GAAe;IAClD,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC;QAChE,IACE,QAAQ,KAAK,WAAW;YACxB,MAAM,CAAC,KAAK,CAAC;YACb,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC;YACtE,0BAA0B,CAAC,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,MAAM;gBAC7D,IAAI;YACN,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAC9C,CAAC;YACD,OAAM;QACR,CAAC;QAED,MAAM,CAAC;YACL,IAAI;YACJ,IAAI,EAAE;gBACJ,KAAK,EAAE,kBAAkB;gBACzB,WAAW,EACT,6EAA6E;aAChF;YACD,KAAK,EAAE,CAAC,kBAAkB,CAAC;SAC5B,CAAC,CAAA;IAAA,CACH;IACD,KAAK,EAAE;QACL,kBAAkB,EAAE,iBAAiB;KACtC;CACF,CAAA;AAID,MAAM,MAAM,GAAG,CACb,KAAgB,EAC8C,EAAE,CAChE,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ToddleComponent } from '@nordcraft/core/dist/component/ToddleComponent';
|
|
2
|
-
import { isToddleFormula } from '@nordcraft/core/dist/formula/formula';
|
|
3
|
-
import { ToddleApiService } from '@nordcraft/ssr/dist/ToddleApiService';
|
|
4
|
-
import { ToddleRoute } from '@nordcraft/ssr/dist/ToddleRoute';
|
|
5
1
|
import { removeFromPathFix } from '../../../util/removeUnused.fix';
|
|
2
|
+
import { projectFormulaIsReferenced } from './projectFormulaIsReferenced.memo';
|
|
6
3
|
export const noReferenceProjectFormulaRule = {
|
|
7
4
|
code: 'no-reference project formula',
|
|
8
5
|
level: 'warning',
|
|
@@ -11,68 +8,9 @@ export const noReferenceProjectFormulaRule = {
|
|
|
11
8
|
if (nodeType !== 'project-formula' || value.exported === true) {
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
for (const apiService of Object.values(files.services ?? {})) {
|
|
16
|
-
const service = new ToddleApiService({
|
|
17
|
-
service: apiService,
|
|
18
|
-
globalFormulas: { formulas: files.formulas, packages: files.packages },
|
|
19
|
-
});
|
|
20
|
-
const formulas = service.formulasInService();
|
|
21
|
-
for (const { path: _formulaPath, formula } of formulas) {
|
|
22
|
-
// Check if the formula is used in the formula
|
|
23
|
-
if (checkFormula(formula, value.name)) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// Check routes before components, since they should be quicker
|
|
29
|
-
for (const projectRoute of Object.values(files.routes ?? {})) {
|
|
30
|
-
const route = new ToddleRoute({
|
|
31
|
-
route: projectRoute,
|
|
32
|
-
globalFormulas: { formulas: files.formulas, packages: files.packages },
|
|
33
|
-
});
|
|
34
|
-
const formulas = route.formulasInRoute();
|
|
35
|
-
for (const { path: _formulaPath, formula } of formulas) {
|
|
36
|
-
// Check if the formula is used in the formula
|
|
37
|
-
if (checkFormula(formula, value.name)) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const componentFormulaReferences = memo('componentFormulaReferences', () => {
|
|
43
|
-
const usedFormulas = new Set();
|
|
44
|
-
for (const component of Object.values(files.components)) {
|
|
45
|
-
const c = new ToddleComponent({
|
|
46
|
-
// Enforce that the component is not undefined since we're iterating
|
|
47
|
-
component: component,
|
|
48
|
-
getComponent: (name) => files.components[name],
|
|
49
|
-
packageName: undefined,
|
|
50
|
-
globalFormulas: {
|
|
51
|
-
formulas: files.formulas,
|
|
52
|
-
packages: files.packages,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
for (const { formula } of c.formulasInComponent()) {
|
|
56
|
-
if (formula.type === 'function') {
|
|
57
|
-
usedFormulas.add(formula.name);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return usedFormulas;
|
|
62
|
-
});
|
|
63
|
-
if (componentFormulaReferences.has(value.name)) {
|
|
11
|
+
if (projectFormulaIsReferenced(files, memo)(value.name)) {
|
|
64
12
|
return;
|
|
65
13
|
}
|
|
66
|
-
// TODO: Memoize similar to above. We need have a helper class `ToddleFormula` with `ToddleFormula.normalizeFormulas()`
|
|
67
|
-
for (const f of Object.values(files.formulas ?? {})) {
|
|
68
|
-
if (f.name === value.name) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
// Check if the formula is used in the formula
|
|
72
|
-
if (isToddleFormula(f) && checkFormula(f.formula, value.name)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
14
|
report({
|
|
77
15
|
path,
|
|
78
16
|
info: {
|
|
@@ -86,25 +24,4 @@ export const noReferenceProjectFormulaRule = {
|
|
|
86
24
|
'delete-project-formula': removeFromPathFix,
|
|
87
25
|
},
|
|
88
26
|
};
|
|
89
|
-
const checkArguments = (args, formulaName) => {
|
|
90
|
-
args.forEach((a) => {
|
|
91
|
-
if (checkFormula(a.formula, formulaName)) {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
return false;
|
|
96
|
-
};
|
|
97
|
-
const checkFormula = (formula, formulaName) => {
|
|
98
|
-
if (formula.type === 'function' && formula.name === formulaName) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
if (formula.type === 'object' ||
|
|
102
|
-
formula.type === 'array' ||
|
|
103
|
-
formula.type === 'or' ||
|
|
104
|
-
formula.type === 'and' ||
|
|
105
|
-
formula.type === 'apply') {
|
|
106
|
-
checkArguments(formula.arguments ?? [], formulaName);
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
};
|
|
110
27
|
//# sourceMappingURL=noReferenceProjectFormulaRule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noReferenceProjectFormulaRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/formulas/noReferenceProjectFormulaRule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"noReferenceProjectFormulaRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/formulas/noReferenceProjectFormulaRule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAA;AAE9E,MAAM,CAAC,MAAM,6BAA6B,GAAe;IACvD,IAAI,EAAE,8BAA8B;IACpC,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QACzD,IAAI,QAAQ,KAAK,iBAAiB,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC9D,OAAM;QACR,CAAC;QAED,IAAI,0BAA0B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACxD,OAAM;QACR,CAAC;QAED,MAAM,CAAC;YACL,IAAI;YACJ,IAAI,EAAE;gBACJ,KAAK,EAAE,uBAAuB;gBAC9B,WAAW,EAAE,oEAAoE;aAClF;YACD,KAAK,EAAE,CAAC,wBAAwB,CAAC;SAClC,CAAC,CAAA;IAAA,CACH;IACD,KAAK,EAAE;QACL,wBAAwB,EAAE,iBAAiB;KAC5C;CACF,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProjectFiles } from '@nordcraft/ssr/dist/ssr.types';
|
|
2
|
+
import type { MemoFn } from '../../../types';
|
|
3
|
+
export declare const projectFormulaIsReferenced: (files: Omit<ProjectFiles, "config"> & Partial<Pick<ProjectFiles, "config">>, memo: MemoFn) => (formulaName: string, packageName?: string | undefined) => boolean;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ToddleComponent } from '@nordcraft/core/dist/component/ToddleComponent';
|
|
2
|
+
import { isToddleFormula, } from '@nordcraft/core/dist/formula/formula';
|
|
3
|
+
import { isDefined } from '@nordcraft/core/dist/utils/util';
|
|
4
|
+
import { ToddleApiService } from '@nordcraft/ssr/dist/ToddleApiService';
|
|
5
|
+
import { ToddleRoute } from '@nordcraft/ssr/dist/ToddleRoute';
|
|
6
|
+
export const projectFormulaIsReferenced = (files, memo) => {
|
|
7
|
+
const allUsedFormulaKeys = memo('all-used-formulas', () => {
|
|
8
|
+
const usedFormulas = new Set();
|
|
9
|
+
// Check in all API services first, since that should be quick
|
|
10
|
+
for (const apiService of Object.values(files.services ?? {})) {
|
|
11
|
+
const service = new ToddleApiService({
|
|
12
|
+
service: apiService,
|
|
13
|
+
globalFormulas: { formulas: files.formulas, packages: files.packages },
|
|
14
|
+
});
|
|
15
|
+
const formulas = service.formulasInService();
|
|
16
|
+
for (const { path: _formulaPath, formula } of formulas) {
|
|
17
|
+
// Check if the formula is used in the formula
|
|
18
|
+
checkFormula(usedFormulas, formula);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// Check routes before components, since they should be quicker
|
|
22
|
+
for (const projectRoute of Object.values(files.routes ?? {})) {
|
|
23
|
+
const route = new ToddleRoute({
|
|
24
|
+
route: projectRoute,
|
|
25
|
+
globalFormulas: { formulas: files.formulas, packages: files.packages },
|
|
26
|
+
});
|
|
27
|
+
const formulas = route.formulasInRoute();
|
|
28
|
+
for (const { path: _formulaPath, formula } of formulas) {
|
|
29
|
+
// Check if the formula is used in the formula
|
|
30
|
+
checkFormula(usedFormulas, formula);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const component of Object.values(files.components)) {
|
|
34
|
+
const c = new ToddleComponent({
|
|
35
|
+
// Enforce that the component is not undefined since we're iterating
|
|
36
|
+
component: component,
|
|
37
|
+
getComponent: (name) => files.components[name],
|
|
38
|
+
packageName: undefined,
|
|
39
|
+
globalFormulas: {
|
|
40
|
+
formulas: files.formulas,
|
|
41
|
+
packages: files.packages,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
for (const { formula } of c.formulasInComponent()) {
|
|
45
|
+
if (formula.type === 'function') {
|
|
46
|
+
usedFormulas.add([formula.package, formula.name].filter(isDefined).join('/'));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const f of Object.values(files.formulas ?? {})) {
|
|
51
|
+
// Check if the formula is used in the formula
|
|
52
|
+
if (isToddleFormula(f)) {
|
|
53
|
+
const usedFormulasMinusSelf = new Set();
|
|
54
|
+
checkFormula(usedFormulasMinusSelf, f.formula);
|
|
55
|
+
// Add all minus self (a formula is unused, if it's only used by itself)
|
|
56
|
+
usedFormulasMinusSelf.delete(f.name);
|
|
57
|
+
usedFormulasMinusSelf.forEach((f) => usedFormulas.add(f));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return usedFormulas;
|
|
61
|
+
});
|
|
62
|
+
return (formulaName, packageName) => {
|
|
63
|
+
return allUsedFormulaKeys.has([packageName, formulaName].filter(isDefined).join('/'));
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const checkArguments = (usedFormulas, args) => {
|
|
67
|
+
args.forEach((a) => {
|
|
68
|
+
checkFormula(usedFormulas, a.formula);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const checkFormula = (usedFormulas, formula) => {
|
|
72
|
+
if (formula.type === 'function') {
|
|
73
|
+
usedFormulas.add([formula.package, formula.name].filter(isDefined).join('/'));
|
|
74
|
+
checkArguments(usedFormulas, formula.arguments ?? []);
|
|
75
|
+
}
|
|
76
|
+
else if (formula.type === 'object' ||
|
|
77
|
+
formula.type === 'array' ||
|
|
78
|
+
formula.type === 'or' ||
|
|
79
|
+
formula.type === 'and' ||
|
|
80
|
+
formula.type === 'apply') {
|
|
81
|
+
checkArguments(usedFormulas, formula.arguments ?? []);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=projectFormulaIsReferenced.memo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectFormulaIsReferenced.memo.js","sourceRoot":"","sources":["../../../../src/rules/issues/formulas/projectFormulaIsReferenced.memo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AAChF,OAAO,EACL,eAAe,GAEhB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAG7D,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,KAA2E,EAC3E,IAAY,EACZ,EAAE,CAAC;IACH,MAAM,kBAAkB,GAAG,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC;QACzD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAA;QAEtC,8DAA8D;QAC9D,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC;gBACnC,OAAO,EAAE,UAAU;gBACnB,cAAc,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE;aACvE,CAAC,CAAA;YACF,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAA;YAC5C,KAAK,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,QAAQ,EAAE,CAAC;gBACvD,8CAA8C;gBAC9C,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;YACrC,CAAC;QACH,CAAC;QAED,+DAA+D;QAC/D,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,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C5D,CAAA;QACD,cAAc,CAAC,YAAY,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;IACvD,CAAC;SAAM,IACL,OAAO,CAAC,IAAI,KAAK,QAAQ;QACzB,OAAO,CAAC,IAAI,KAAK,OAAO;QACxB,OAAO,CAAC,IAAI,KAAK,IAAI;QACrB,OAAO,CAAC,IAAI,KAAK,KAAK;QACtB,OAAO,CAAC,IAAI,KAAK,OAAO,EACxB,CAAC;QACD,cAAc,CAAC,YAAY,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;IACvD,CAAC;AAAA,CACF,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createStaticSizeConstraintRule } from './createStaticSizeConstraintRule';
|
|
2
2
|
import { noReferenceNodeRule } from './noReferenceNodeRule';
|
|
3
|
+
import { noReferenceProjectPackageRule } from './noReferencePackageRule';
|
|
3
4
|
import { requireExtensionRule } from './requireExtensionRule';
|
|
4
5
|
import { unknownCookieRule } from './unknownCookieRule';
|
|
5
6
|
export default [
|
|
@@ -10,5 +11,6 @@ export default [
|
|
|
10
11
|
createStaticSizeConstraintRule('svg', 100 * 1024),
|
|
11
12
|
// 50 KB is a large img element (with potential base64 encoded image)
|
|
12
13
|
createStaticSizeConstraintRule('img', 50 * 1024),
|
|
14
|
+
noReferenceProjectPackageRule,
|
|
13
15
|
];
|
|
14
16
|
//# sourceMappingURL=miscRules.index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"miscRules.index.js","sourceRoot":"","sources":["../../../../src/rules/issues/miscellaneous/miscRules.index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,eAAe;IACb,mBAAmB;IACnB,oBAAoB;IACpB,iBAAiB;IACjB,wBAAwB;IACxB,8BAA8B,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IACjD,qEAAqE;IACrE,8BAA8B,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"miscRules.index.js","sourceRoot":"","sources":["../../../../src/rules/issues/miscellaneous/miscRules.index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAA;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,eAAe;IACb,mBAAmB;IACnB,oBAAoB;IACpB,iBAAiB;IACjB,wBAAwB;IACxB,8BAA8B,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IACjD,qEAAqE;IACrE,8BAA8B,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC;IAChD,6BAA6B;CAC9B,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { removeFromPathFix } from '../../../util/removeUnused.fix';
|
|
2
|
+
import { projectActionIsReferenced } from '../actions/projectActionIsReferenced.memo';
|
|
3
|
+
import { componentIsReferenced } from '../components/componentIsReferenced.memo';
|
|
4
|
+
import { projectFormulaIsReferenced } from '../formulas/projectFormulaIsReferenced.memo';
|
|
5
|
+
export const noReferenceProjectPackageRule = {
|
|
6
|
+
code: 'no-reference project package',
|
|
7
|
+
level: 'info',
|
|
8
|
+
category: 'No References',
|
|
9
|
+
visit: (report, info) => {
|
|
10
|
+
if (info.nodeType !== 'project-package') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { files, memo, path, value, packageName } = info;
|
|
14
|
+
const exportedFormulas = Object.entries(value.formulas ?? {}).filter(([, formula]) => formula.exported);
|
|
15
|
+
if (exportedFormulas.length > 0) {
|
|
16
|
+
const projectFormulaIsReferencedFn = projectFormulaIsReferenced(files, memo);
|
|
17
|
+
for (const [, formula] of exportedFormulas) {
|
|
18
|
+
if (projectFormulaIsReferencedFn(formula.name, packageName)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const exportedActions = Object.entries(value.actions ?? {}).filter(([, action]) => action.exported);
|
|
24
|
+
if (exportedActions.length > 0) {
|
|
25
|
+
const projectActionIsReferencedFn = projectActionIsReferenced(files, memo);
|
|
26
|
+
for (const [, action] of exportedActions) {
|
|
27
|
+
if (projectActionIsReferencedFn(action.name, packageName)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const exportedComponents = Object.entries(value.components ?? {}).filter(([, component]) => component?.exported);
|
|
33
|
+
if (exportedComponents.length > 0) {
|
|
34
|
+
const componentIsReferencedFn = componentIsReferenced(files, memo);
|
|
35
|
+
for (const [, component] of exportedComponents) {
|
|
36
|
+
if (component && componentIsReferencedFn(component.name, packageName)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
report({
|
|
42
|
+
path,
|
|
43
|
+
info: {
|
|
44
|
+
title: `Unused package`,
|
|
45
|
+
description: `Package is installed, but none of its formulas, actions, or components are used by any other part of the project. The package can safely be uninstalled.`,
|
|
46
|
+
},
|
|
47
|
+
fixes: ['uninstall-package'],
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
fixes: {
|
|
51
|
+
'uninstall-package': removeFromPathFix,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=noReferencePackageRule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noReferencePackageRule.js","sourceRoot":"","sources":["../../../../src/rules/issues/miscellaneous/noReferencePackageRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AACrF,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAA;AAExF,MAAM,CAAC,MAAM,6BAA6B,GAA2B;IACnE,IAAI,EAAE,8BAA8B;IACpC,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,QAAQ,KAAK,iBAAiB,EAAE,CAAC;YACxC,OAAM;QACR,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;QAEtD,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAClE,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAClC,CAAA;QACD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,4BAA4B,GAAG,0BAA0B,CAC7D,KAAK,EACL,IAAI,CACL,CAAA;YACD,KAAK,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,gBAAgB,EAAE,CAAC;gBAC3C,IAAI,4BAA4B,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC;oBAC5D,OAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,IAAI,EAA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files, rules, pathsToVisit = [], useExactPaths
|
|
|
153
153
|
state,
|
|
154
154
|
fixOptions: fixOptions,
|
|
155
155
|
});
|
|
156
|
+
if (files.packages) {
|
|
157
|
+
for (const key in files.packages) {
|
|
158
|
+
const pkg = files.packages[key];
|
|
159
|
+
if (pkg) {
|
|
160
|
+
yield* visitNode({
|
|
161
|
+
args: {
|
|
162
|
+
nodeType: 'project-package',
|
|
163
|
+
value: pkg,
|
|
164
|
+
packageName: key,
|
|
165
|
+
path: ['packages', key],
|
|
166
|
+
rules,
|
|
167
|
+
files,
|
|
168
|
+
pathsToVisit,
|
|
169
|
+
useExactPaths,
|
|
170
|
+
memo,
|
|
171
|
+
},
|
|
172
|
+
state,
|
|
173
|
+
fixOptions: fixOptions,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
156
178
|
}
|
|
157
179
|
function* visitNode({ args, state, fixOptions, }) {
|
|
158
180
|
const { rules, pathsToVisit, useExactPaths, ...data } = args;
|
|
@@ -241,6 +263,7 @@ function* visitNode({ args, state, fixOptions, }) {
|
|
|
241
263
|
case 'project-config':
|
|
242
264
|
case 'project-theme':
|
|
243
265
|
case 'project-theme-property':
|
|
266
|
+
case 'project-package':
|
|
244
267
|
case 'style-declaration':
|
|
245
268
|
case 'style-variable':
|
|
246
269
|
case 'style-variant':
|