@memberjunction/react-test-harness 2.100.2 → 2.100.3
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/lib/component-linter.d.ts.map +1 -1
- package/dist/lib/component-linter.js +112 -1
- package/dist/lib/component-linter.js.map +1 -1
- package/dist/lib/component-runner.d.ts.map +1 -1
- package/dist/lib/component-runner.js +13 -0
- package/dist/lib/component-runner.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-linter.d.ts","sourceRoot":"","sources":["../../src/lib/component-linter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAiC,MAAM,6CAA6C,CAAC;AAG3G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAG/D,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,cAAc,CAAC;IACn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AAO,CAAC,MAAM,CAAC,yBAAyB;CAkGzC"}
|
|
@@ -8210,7 +8210,7 @@ const [state, setState] = useState(initialValue);`
|
|
|
8210
8210
|
test: (ast, componentName, componentSpec) => {
|
|
8211
8211
|
const violations = [];
|
|
8212
8212
|
// Define the allowed methods on ComponentCallbacks interface
|
|
8213
|
-
const allowedCallbackMethods = new Set(['OpenEntityRecord', 'RegisterMethod']);
|
|
8213
|
+
const allowedCallbackMethods = new Set(['OpenEntityRecord', 'RegisterMethod', 'CreateSimpleNotification']);
|
|
8214
8214
|
// Build list of component's event names from spec
|
|
8215
8215
|
const componentEvents = new Set();
|
|
8216
8216
|
if (componentSpec?.events) {
|
|
@@ -8264,6 +8264,7 @@ function MyComponent({ ..., ${methodName} }) {
|
|
|
8264
8264
|
example: `// Allowed callbacks methods:
|
|
8265
8265
|
callbacks?.OpenEntityRecord?.(entityName, key);
|
|
8266
8266
|
callbacks?.RegisterMethod?.(methodName, handler);
|
|
8267
|
+
callbacks?.CreateSimpleNotification?.(message, style, hideAfter);
|
|
8267
8268
|
|
|
8268
8269
|
// For custom events, define them in the spec and use as props:
|
|
8269
8270
|
function MyComponent({ onCustomEvent }) {
|
|
@@ -8652,6 +8653,116 @@ const extendedCallbacks = { ...callbacks, onCustomEvent: handler };
|
|
|
8652
8653
|
});
|
|
8653
8654
|
return violations;
|
|
8654
8655
|
}
|
|
8656
|
+
},
|
|
8657
|
+
{
|
|
8658
|
+
name: 'callback-parameter-validation',
|
|
8659
|
+
appliesTo: 'all',
|
|
8660
|
+
test: (ast, _componentName, _componentSpec) => {
|
|
8661
|
+
const violations = [];
|
|
8662
|
+
(0, traverse_1.default)(ast, {
|
|
8663
|
+
CallExpression(path) {
|
|
8664
|
+
// Check for callbacks?.method() calls
|
|
8665
|
+
if (t.isOptionalMemberExpression(path.node.callee) || t.isMemberExpression(path.node.callee)) {
|
|
8666
|
+
const callee = path.node.callee;
|
|
8667
|
+
// Check if it's callbacks.something or callbacks?.something
|
|
8668
|
+
if ((t.isIdentifier(callee.object) && callee.object.name === 'callbacks') ||
|
|
8669
|
+
(t.isOptionalMemberExpression(callee) && t.isIdentifier(callee.object) && callee.object.name === 'callbacks')) {
|
|
8670
|
+
if (t.isIdentifier(callee.property)) {
|
|
8671
|
+
const methodName = callee.property.name;
|
|
8672
|
+
const args = path.node.arguments;
|
|
8673
|
+
// Validate parameters based on the method
|
|
8674
|
+
if (methodName === 'OpenEntityRecord') {
|
|
8675
|
+
// OpenEntityRecord(entityName: string, key: any)
|
|
8676
|
+
if (args.length < 2) {
|
|
8677
|
+
violations.push({
|
|
8678
|
+
rule: 'callback-parameter-validation',
|
|
8679
|
+
severity: 'high',
|
|
8680
|
+
line: path.node.loc?.start.line || 0,
|
|
8681
|
+
column: path.node.loc?.start.column || 0,
|
|
8682
|
+
message: `OpenEntityRecord requires 2 parameters (entityName, key), but ${args.length} provided`,
|
|
8683
|
+
suggestion: {
|
|
8684
|
+
text: `OpenEntityRecord expects an entity name and a key parameter.`,
|
|
8685
|
+
example: `callbacks?.OpenEntityRecord?.(entityName, recordKey);`
|
|
8686
|
+
}
|
|
8687
|
+
});
|
|
8688
|
+
}
|
|
8689
|
+
}
|
|
8690
|
+
else if (methodName === 'RegisterMethod') {
|
|
8691
|
+
// RegisterMethod(methodName: string, handler: Function)
|
|
8692
|
+
if (args.length < 2) {
|
|
8693
|
+
violations.push({
|
|
8694
|
+
rule: 'callback-parameter-validation',
|
|
8695
|
+
severity: 'high',
|
|
8696
|
+
line: path.node.loc?.start.line || 0,
|
|
8697
|
+
column: path.node.loc?.start.column || 0,
|
|
8698
|
+
message: `RegisterMethod requires 2 parameters (methodName, handler), but ${args.length} provided`,
|
|
8699
|
+
suggestion: {
|
|
8700
|
+
text: `RegisterMethod expects a method name and a handler function.`,
|
|
8701
|
+
example: `callbacks?.RegisterMethod?.('myMethod', myHandler);`
|
|
8702
|
+
}
|
|
8703
|
+
});
|
|
8704
|
+
}
|
|
8705
|
+
}
|
|
8706
|
+
else if (methodName === 'CreateSimpleNotification') {
|
|
8707
|
+
// CreateSimpleNotification(message: string, style?: NotificationStyle, hideAfter?: number)
|
|
8708
|
+
if (args.length < 1) {
|
|
8709
|
+
violations.push({
|
|
8710
|
+
rule: 'callback-parameter-validation',
|
|
8711
|
+
severity: 'high',
|
|
8712
|
+
line: path.node.loc?.start.line || 0,
|
|
8713
|
+
column: path.node.loc?.start.column || 0,
|
|
8714
|
+
message: `CreateSimpleNotification requires at least 1 parameter (message), but ${args.length} provided`,
|
|
8715
|
+
suggestion: {
|
|
8716
|
+
text: `CreateSimpleNotification expects a message and optional style and hideAfter parameters.`,
|
|
8717
|
+
example: `callbacks?.CreateSimpleNotification?.('Success!', 'success', 3000);`
|
|
8718
|
+
}
|
|
8719
|
+
});
|
|
8720
|
+
}
|
|
8721
|
+
else if (args.length >= 2) {
|
|
8722
|
+
// Validate style parameter (second argument)
|
|
8723
|
+
const styleArg = args[1];
|
|
8724
|
+
if (t.isStringLiteral(styleArg)) {
|
|
8725
|
+
const validStyles = ['none', 'success', 'error', 'warning', 'info'];
|
|
8726
|
+
if (!validStyles.includes(styleArg.value)) {
|
|
8727
|
+
violations.push({
|
|
8728
|
+
rule: 'callback-parameter-validation',
|
|
8729
|
+
severity: 'medium',
|
|
8730
|
+
line: styleArg.loc?.start.line || 0,
|
|
8731
|
+
column: styleArg.loc?.start.column || 0,
|
|
8732
|
+
message: `Invalid notification style "${styleArg.value}". Must be one of: ${validStyles.join(', ')}`,
|
|
8733
|
+
suggestion: {
|
|
8734
|
+
text: `Use one of the valid notification styles.`,
|
|
8735
|
+
example: `callbacks?.CreateSimpleNotification?.('Message', 'success', 3000);`
|
|
8736
|
+
}
|
|
8737
|
+
});
|
|
8738
|
+
}
|
|
8739
|
+
}
|
|
8740
|
+
}
|
|
8741
|
+
// Validate hideAfter parameter (third argument) if provided
|
|
8742
|
+
if (args.length >= 3) {
|
|
8743
|
+
const hideAfterArg = args[2];
|
|
8744
|
+
if (t.isNumericLiteral(hideAfterArg) && hideAfterArg.value < 0) {
|
|
8745
|
+
violations.push({
|
|
8746
|
+
rule: 'callback-parameter-validation',
|
|
8747
|
+
severity: 'low',
|
|
8748
|
+
line: hideAfterArg.loc?.start.line || 0,
|
|
8749
|
+
column: hideAfterArg.loc?.start.column || 0,
|
|
8750
|
+
message: `hideAfter parameter should be a positive number (milliseconds)`,
|
|
8751
|
+
suggestion: {
|
|
8752
|
+
text: `Use a positive number for auto-hide duration in milliseconds.`,
|
|
8753
|
+
example: `callbacks?.CreateSimpleNotification?.('Message', 'success', 3000); // Hide after 3 seconds`
|
|
8754
|
+
}
|
|
8755
|
+
});
|
|
8756
|
+
}
|
|
8757
|
+
}
|
|
8758
|
+
}
|
|
8759
|
+
}
|
|
8760
|
+
}
|
|
8761
|
+
}
|
|
8762
|
+
}
|
|
8763
|
+
});
|
|
8764
|
+
return violations;
|
|
8765
|
+
}
|
|
8655
8766
|
}
|
|
8656
8767
|
];
|
|
8657
8768
|
//# sourceMappingURL=component-linter.js.map
|