Skip to content

Commit f63933b

Browse files
committed
Make Boolean types more permissive and remove default value for Object
1 parent a2686d6 commit f63933b

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

packages/theme-check-common/src/checks/valid-render-snippet-param-types/index.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ describe('Module: ValidRenderSnippetParamTypes', () => {
2525
},
2626
{
2727
type: 'boolean',
28-
validValues: ['true', 'false', 'nil', 'empty', 'product'],
29-
invalidValues: [
30-
{ value: "'hello'", actualType: SupportedParamTypes.String },
31-
{ value: '123', actualType: SupportedParamTypes.Number },
32-
],
28+
validValues: ['true', 'false', 'nil', 'empty', 'product', '123', "'hello'"],
29+
invalidValues: [],
3330
},
3431
{
3532
type: 'object',

packages/theme-check-common/src/checks/valid-render-snippet-param-types/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
inferArgumentType,
88
getDefaultValueForType,
99
SupportedParamTypes,
10+
isTypeCompatible,
1011
} from '../../liquid-doc/utils';
1112

1213
export const ValidRenderSnippetParamTypes: LiquidCheckDefinition = {
@@ -46,7 +47,7 @@ export const ValidRenderSnippetParamTypes: LiquidCheckDefinition = {
4647
continue;
4748
}
4849

49-
if (inferArgumentType(arg) !== paramType) {
50+
if (!isTypeCompatible(paramType, inferArgumentType(arg))) {
5051
typeMismatchParams.push(arg);
5152
}
5253
}

packages/theme-check-common/src/liquid-doc/utils.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export function getDefaultValueForType(type: string | null) {
2525
return '0';
2626
case SupportedParamTypes.Boolean:
2727
return 'false';
28-
case SupportedParamTypes.Object:
29-
return 'empty';
28+
case SupportedParamTypes.Object: // Objects don't have a sensible default value (maybe `theme`?)
3029
default:
3130
return '';
3231
}
@@ -51,3 +50,18 @@ export function inferArgumentType(arg: LiquidNamedArgument): SupportedParamTypes
5150
return assertNever(arg.value);
5251
}
5352
}
53+
54+
/**
55+
* Checks if the provided argument type is compatible with the expected type.
56+
* Makes certain types more permissive:
57+
* - Boolean accepts any value, since everything is truthy / falsy in Liquid
58+
*/
59+
export function isTypeCompatible(expectedType: string, actualType: SupportedParamTypes): boolean {
60+
const normalizedExpectedType = expectedType.toLowerCase();
61+
62+
if (normalizedExpectedType === SupportedParamTypes.Boolean) {
63+
return true;
64+
}
65+
66+
return normalizedExpectedType === actualType;
67+
}

0 commit comments

Comments
 (0)