@platformos/platformos-check-common 0.0.7 → 0.0.9
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/CHANGELOG.md +16 -0
- package/README.md +4 -4
- package/dist/AugmentedPlatformOSDocset.d.ts +11 -0
- package/dist/AugmentedPlatformOSDocset.js +81 -0
- package/dist/AugmentedPlatformOSDocset.js.map +1 -0
- package/dist/JSONValidator.js +1 -1
- package/dist/JSONValidator.js.map +1 -1
- package/dist/checks/deprecated-filter/index.js +4 -41
- package/dist/checks/deprecated-filter/index.js.map +1 -1
- package/dist/checks/deprecated-tag/index.js +21 -22
- package/dist/checks/deprecated-tag/index.js.map +1 -1
- package/dist/checks/duplicate-function-arguments/index.js +1 -1
- package/dist/checks/duplicate-function-arguments/index.js.map +1 -1
- package/dist/checks/duplicate-render-partial-arguments/index.js +1 -1
- package/dist/checks/duplicate-render-partial-arguments/index.js.map +1 -1
- package/dist/checks/graphql/index.js +1 -1
- package/dist/checks/graphql/index.js.map +1 -1
- package/dist/checks/graphql-variables/index.js +4 -0
- package/dist/checks/graphql-variables/index.js.map +1 -1
- package/dist/checks/img-width-and-height/index.js +1 -1
- package/dist/checks/img-width-and-height/index.js.map +1 -1
- package/dist/checks/index.d.ts +3 -3
- package/dist/checks/index.js +4 -79
- package/dist/checks/index.js.map +1 -1
- package/dist/checks/json-syntax-error/index.js +1 -1
- package/dist/checks/json-syntax-error/index.js.map +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.js +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.js.map +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.d.ts +19 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js +79 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.d.ts +3 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.js +32 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/index.js +23 -5
- package/dist/checks/liquid-html-syntax-error/index.js.map +1 -1
- package/dist/checks/matching-translations/index.d.ts +2 -2
- package/dist/checks/matching-translations/index.js +114 -90
- package/dist/checks/matching-translations/index.js.map +1 -1
- package/dist/checks/metadata-params/index.js +6 -3
- package/dist/checks/metadata-params/index.js.map +1 -1
- package/dist/checks/missing-asset/index.js +1 -1
- package/dist/checks/missing-asset/index.js.map +1 -1
- package/dist/checks/missing-partial/index.d.ts +6 -0
- package/dist/checks/missing-partial/index.js +70 -0
- package/dist/checks/missing-partial/index.js.map +1 -0
- package/dist/checks/orphaned-partial/index.js +4 -4
- package/dist/checks/orphaned-partial/index.js.map +1 -1
- package/dist/checks/parser-blocking-script/index.js +10 -36
- package/dist/checks/parser-blocking-script/index.js.map +1 -1
- package/dist/checks/parser-blocking-script/suggestions.d.ts +1 -2
- package/dist/checks/parser-blocking-script/suggestions.js +1 -11
- package/dist/checks/parser-blocking-script/suggestions.js.map +1 -1
- package/dist/checks/reserved-doc-param-names/index.js +6 -5
- package/dist/checks/reserved-doc-param-names/index.js.map +1 -1
- package/dist/checks/translation-key-exists/index.js +1 -1
- package/dist/checks/translation-key-exists/index.js.map +1 -1
- package/dist/checks/unclosed-html-element/index.js +5 -1
- package/dist/checks/unclosed-html-element/index.js.map +1 -1
- package/dist/checks/undefined-object/index.js +13 -31
- package/dist/checks/undefined-object/index.js.map +1 -1
- package/dist/checks/unique-doc-param-names/index.js +1 -1
- package/dist/checks/unique-doc-param-names/index.js.map +1 -1
- package/dist/checks/unknown-filter/index.js +3 -3
- package/dist/checks/unknown-filter/index.js.map +1 -1
- package/dist/checks/unknown-property/index.js +1 -1
- package/dist/checks/unknown-property/index.js.map +1 -1
- package/dist/checks/unrecognized-render-partial-arguments/index.js +2 -2
- package/dist/checks/unrecognized-render-partial-arguments/index.js.map +1 -1
- package/dist/checks/unused-assign/index.js +1 -1
- package/dist/checks/unused-assign/index.js.map +1 -1
- package/dist/checks/unused-doc-param/index.js +1 -1
- package/dist/checks/unused-doc-param/index.js.map +1 -1
- package/dist/checks/utils.js +1 -1
- package/dist/checks/utils.js.map +1 -1
- package/dist/checks/valid-content-for-arguments/index.js +1 -1
- package/dist/checks/valid-content-for-arguments/index.js.map +1 -1
- package/dist/checks/valid-doc-param-types/index.js +4 -4
- package/dist/checks/valid-doc-param-types/index.js.map +1 -1
- package/dist/checks/valid-html-translation/index.d.ts +2 -2
- package/dist/checks/valid-html-translation/index.js +4 -4
- package/dist/checks/valid-html-translation/index.js.map +1 -1
- package/dist/checks/valid-json/index.js +1 -1
- package/dist/checks/valid-json/index.js.map +1 -1
- package/dist/checks/valid-render-partial-argument-types/index.js +2 -2
- package/dist/checks/valid-render-partial-argument-types/index.js.map +1 -1
- package/dist/checks/variable-name/index.js +1 -1
- package/dist/checks/variable-name/index.js.map +1 -1
- package/dist/context-utils.d.ts +18 -7
- package/dist/context-utils.js +68 -109
- package/dist/context-utils.js.map +1 -1
- package/dist/disabled-checks/index.js +4 -2
- package/dist/disabled-checks/index.js.map +1 -1
- package/dist/doc-generator/DocBlockGenerator.d.ts +16 -0
- package/dist/doc-generator/DocBlockGenerator.js +464 -0
- package/dist/doc-generator/DocBlockGenerator.js.map +1 -0
- package/dist/doc-generator/index.d.ts +1 -0
- package/dist/doc-generator/index.js +6 -0
- package/dist/doc-generator/index.js.map +1 -0
- package/dist/find-root.d.ts +7 -10
- package/dist/find-root.js +10 -17
- package/dist/find-root.js.map +1 -1
- package/dist/fixes/autofix.d.ts +4 -4
- package/dist/fixes/autofix.js +2 -2
- package/dist/fixes/autofix.js.map +1 -1
- package/dist/fixes/correctors/index.js +4 -0
- package/dist/fixes/correctors/index.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +50 -17
- package/dist/index.js.map +1 -1
- package/dist/jsonc/parse.d.ts +1 -1
- package/dist/jsonc/parse.js +1 -1
- package/dist/liquid-doc/arguments.d.ts +7 -8
- package/dist/liquid-doc/arguments.js +28 -29
- package/dist/liquid-doc/arguments.js.map +1 -1
- package/dist/liquid-doc/liquidDoc.d.ts +1 -1
- package/dist/liquid-doc/liquidDoc.js.map +1 -1
- package/dist/liquid-doc/utils.d.ts +3 -3
- package/dist/liquid-doc/utils.js +14 -3
- package/dist/liquid-doc/utils.js.map +1 -1
- package/dist/path.d.ts +1 -0
- package/dist/path.js +16 -1
- package/dist/path.js.map +1 -1
- package/{src/test/MockTheme.ts → dist/test/MockApp.d.ts} +2 -3
- package/dist/test/MockApp.js +16 -0
- package/dist/test/MockApp.js.map +1 -0
- package/dist/test/MockFileSystem.d.ts +3 -3
- package/dist/test/MockFileSystem.js +6 -6
- package/dist/test/MockFileSystem.js.map +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +1 -1
- package/dist/test/index.js.map +1 -1
- package/dist/test/test-helper.d.ts +10 -9
- package/dist/test/test-helper.js +15 -106
- package/dist/test/test-helper.js.map +1 -1
- package/dist/to-schema.d.ts +1 -1
- package/dist/to-source-code.d.ts +3 -2
- package/dist/to-source-code.js +20 -0
- package/dist/to-source-code.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/platformos-liquid-docs.d.ts +128 -0
- package/dist/types/platformos-liquid-docs.js +3 -0
- package/dist/types/platformos-liquid-docs.js.map +1 -0
- package/dist/types/schemas/index.d.ts +0 -2
- package/dist/types/schemas/index.js.map +1 -1
- package/dist/types.d.ts +26 -67
- package/dist/types.js +3 -5
- package/dist/types.js.map +1 -1
- package/dist/utils/block.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/yaml/parse.d.ts +5 -0
- package/dist/yaml/parse.js +94 -0
- package/dist/yaml/parse.js.map +1 -0
- package/package.json +4 -3
- package/src/{AugmentedThemeDocset.spec.ts → AugmentedPlatformOSDocset.spec.ts} +47 -34
- package/src/AugmentedPlatformOSDocset.ts +89 -0
- package/src/JSONValidator.ts +1 -1
- package/src/checks/deprecated-filter/index.spec.ts +76 -248
- package/src/checks/deprecated-filter/index.ts +5 -53
- package/src/checks/deprecated-tag/index.spec.ts +85 -34
- package/src/checks/deprecated-tag/index.ts +27 -22
- package/src/checks/duplicate-function-arguments/index.ts +1 -1
- package/src/checks/duplicate-render-partial-arguments/index.spec.ts +12 -12
- package/src/checks/duplicate-render-partial-arguments/index.ts +1 -1
- package/src/checks/graphql/index.ts +1 -1
- package/src/checks/graphql-variables/index.spec.ts +95 -0
- package/src/checks/graphql-variables/index.ts +4 -0
- package/src/checks/img-width-and-height/index.ts +2 -2
- package/src/checks/index.ts +11 -80
- package/src/checks/invalid-hash-assign-target/index.spec.ts +27 -27
- package/src/checks/json-syntax-error/index.ts +2 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidBooleanExpression.spec.ts +0 -11
- package/src/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.spec.ts +1 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.ts +2 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.spec.ts +259 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.ts +89 -0
- package/src/checks/liquid-html-syntax-error/checks/UnknownTag.spec.ts +293 -0
- package/src/checks/liquid-html-syntax-error/checks/UnknownTag.ts +43 -0
- package/src/checks/liquid-html-syntax-error/index.spec.ts +1 -6
- package/src/checks/liquid-html-syntax-error/index.ts +26 -5
- package/src/checks/matching-translations/index.spec.ts +187 -354
- package/src/checks/matching-translations/index.ts +117 -107
- package/src/checks/metadata-params/index.ts +6 -8
- package/src/checks/missing-asset/index.ts +1 -1
- package/src/checks/{missing-template → missing-partial}/index.spec.ts +6 -6
- package/src/checks/{missing-template → missing-partial}/index.ts +12 -26
- package/src/checks/orphaned-partial/index.ts +3 -3
- package/src/checks/parser-blocking-script/index.spec.ts +0 -118
- package/src/checks/parser-blocking-script/index.ts +3 -33
- package/src/checks/parser-blocking-script/suggestions.ts +1 -28
- package/src/checks/translation-key-exists/index.ts +1 -1
- package/src/checks/unclosed-html-element/index.ts +5 -1
- package/src/checks/undefined-object/index.spec.ts +32 -111
- package/src/checks/undefined-object/index.ts +15 -34
- package/src/checks/unique-doc-param-names/index.ts +1 -1
- package/src/checks/unknown-filter/index.spec.ts +2 -2
- package/src/checks/unknown-filter/index.ts +3 -3
- package/src/checks/unknown-property/index.ts +1 -1
- package/src/checks/unrecognized-render-partial-arguments/index.spec.ts +5 -5
- package/src/checks/unrecognized-render-partial-arguments/index.ts +2 -5
- package/src/checks/unused-assign/index.spec.ts +0 -30
- package/src/checks/unused-assign/index.ts +2 -2
- package/src/checks/unused-doc-param/index.ts +1 -1
- package/src/checks/utils.ts +1 -1
- package/src/checks/valid-doc-param-types/index.ts +4 -4
- package/src/checks/valid-html-translation/index.spec.ts +42 -32
- package/src/checks/valid-html-translation/index.ts +7 -7
- package/src/checks/valid-json/index.ts +2 -2
- package/src/checks/valid-render-partial-argument-types/index.spec.ts +13 -13
- package/src/checks/valid-render-partial-argument-types/index.ts +2 -5
- package/src/checks/variable-name/index.ts +1 -1
- package/src/context-utils.spec.ts +49 -77
- package/src/context-utils.ts +81 -129
- package/src/disabled-checks/index.spec.ts +26 -26
- package/src/disabled-checks/index.ts +2 -2
- package/src/disabled-checks/test-checks.ts +4 -4
- package/src/find-root.ts +12 -22
- package/src/fixes/autofix.spec.ts +2 -2
- package/src/fixes/autofix.ts +4 -4
- package/src/fixes/correctors/index.ts +4 -0
- package/src/ignore.spec.ts +4 -5
- package/src/index.ts +51 -21
- package/src/jsonc/parse.ts +1 -1
- package/src/liquid-doc/arguments.spec.ts +19 -45
- package/src/liquid-doc/arguments.ts +35 -42
- package/src/liquid-doc/liquidDoc.spec.ts +1 -1
- package/src/liquid-doc/liquidDoc.ts +1 -2
- package/src/liquid-doc/utils.ts +17 -8
- package/src/path.ts +16 -0
- package/src/test/MockApp.ts +17 -0
- package/src/test/MockFileSystem.spec.ts +10 -11
- package/src/test/MockFileSystem.ts +6 -6
- package/src/test/contain-offense.spec.ts +11 -3
- package/src/test/index.ts +1 -1
- package/src/test/test-helper.ts +43 -145
- package/src/to-source-code.ts +20 -1
- package/src/types/{theme-liquid-docs.ts → platformos-liquid-docs.ts} +8 -13
- package/src/types.ts +29 -92
- package/src/utils/index.ts +0 -1
- package/src/visitor.spec.ts +2 -2
- package/src/yaml/parse.ts +111 -0
- package/src/AugmentedThemeDocset.ts +0 -137
- package/src/checks/app-block-missing-schema/index.spec.ts +0 -121
- package/src/checks/app-block-missing-schema/index.ts +0 -46
- package/src/checks/app-block-valid-tags/index.spec.ts +0 -96
- package/src/checks/app-block-valid-tags/index.ts +0 -54
- package/src/checks/asset-preload/index.spec.ts +0 -78
- package/src/checks/asset-preload/index.ts +0 -65
- package/src/checks/asset-size-app-block-css/index.spec.ts +0 -88
- package/src/checks/asset-size-app-block-css/index.ts +0 -78
- package/src/checks/asset-size-app-block-javascript/index.spec.ts +0 -66
- package/src/checks/asset-size-app-block-javascript/index.ts +0 -78
- package/src/checks/asset-size-css/index.spec.ts +0 -166
- package/src/checks/asset-size-css/index.ts +0 -160
- package/src/checks/asset-size-javascript/index.spec.ts +0 -184
- package/src/checks/asset-size-javascript/index.ts +0 -144
- package/src/checks/block-id-usage/index.spec.ts +0 -76
- package/src/checks/block-id-usage/index.ts +0 -72
- package/src/checks/cdn-preconnect/index.spec.ts +0 -40
- package/src/checks/cdn-preconnect/index.ts +0 -43
- package/src/checks/content-for-header-modification/index.spec.ts +0 -65
- package/src/checks/content-for-header-modification/index.ts +0 -72
- package/src/checks/deprecate-bgsizes/index.spec.ts +0 -41
- package/src/checks/deprecate-bgsizes/index.ts +0 -49
- package/src/checks/deprecate-lazysizes/index.spec.ts +0 -26
- package/src/checks/deprecate-lazysizes/index.ts +0 -58
- package/src/checks/deprecated-filter/fixes.ts +0 -264
- package/src/checks/deprecated-fonts-on-sections-and-blocks/deprecated-fonts-data.ts +0 -1343
- package/src/checks/deprecated-fonts-on-sections-and-blocks/index.spec.ts +0 -613
- package/src/checks/deprecated-fonts-on-sections-and-blocks/index.ts +0 -284
- package/src/checks/deprecated-fonts-on-settings-schema/index.spec.ts +0 -102
- package/src/checks/deprecated-fonts-on-settings-schema/index.ts +0 -66
- package/src/checks/duplicate-content-for-arguments/index.spec.ts +0 -98
- package/src/checks/duplicate-content-for-arguments/index.ts +0 -43
- package/src/checks/empty-block-content/index.spec.ts +0 -117
- package/src/checks/empty-block-content/index.ts +0 -60
- package/src/checks/hardcoded-routes/index.spec.ts +0 -58
- package/src/checks/hardcoded-routes/index.ts +0 -100
- package/src/checks/json-missing-block/index.spec.ts +0 -435
- package/src/checks/json-missing-block/index.ts +0 -56
- package/src/checks/json-missing-block/missing-block-utils.ts +0 -147
- package/src/checks/liquid-free-settings/index.spec.ts +0 -180
- package/src/checks/liquid-free-settings/index.ts +0 -79
- package/src/checks/missing-content-for-arguments/index.spec.ts +0 -144
- package/src/checks/missing-content-for-arguments/index.ts +0 -46
- package/src/checks/pagination-size/index.spec.ts +0 -158
- package/src/checks/pagination-size/index.ts +0 -104
- package/src/checks/remote-asset/index.spec.ts +0 -280
- package/src/checks/remote-asset/index.ts +0 -238
- package/src/checks/reserved-doc-param-names/index.spec.ts +0 -62
- package/src/checks/reserved-doc-param-names/index.ts +0 -57
- package/src/checks/schema-presets-block-order/index.spec.ts +0 -344
- package/src/checks/schema-presets-block-order/index.ts +0 -154
- package/src/checks/schema-presets-static-blocks/index.spec.ts +0 -145
- package/src/checks/schema-presets-static-blocks/index.ts +0 -126
- package/src/checks/static-stylesheet-and-javascript-tags/index.spec.ts +0 -257
- package/src/checks/static-stylesheet-and-javascript-tags/index.ts +0 -48
- package/src/checks/unique-settings-id/index.spec.ts +0 -24
- package/src/checks/unique-settings-id/index.ts +0 -84
- package/src/checks/unique-settings-id/test-data.ts +0 -1191
- package/src/checks/unique-static-block-id/index.spec.ts +0 -55
- package/src/checks/unique-static-block-id/index.ts +0 -60
- package/src/checks/unrecognized-content-for-arguments/index.spec.ts +0 -145
- package/src/checks/unrecognized-content-for-arguments/index.ts +0 -55
- package/src/checks/valid-block-target/index.spec.ts +0 -1396
- package/src/checks/valid-block-target/index.ts +0 -142
- package/src/checks/valid-content-for-argument-types/index.spec.ts +0 -382
- package/src/checks/valid-content-for-argument-types/index.ts +0 -42
- package/src/checks/valid-content-for-arguments/index.spec.ts +0 -107
- package/src/checks/valid-content-for-arguments/index.ts +0 -98
- package/src/checks/valid-local-blocks/index.spec.ts +0 -286
- package/src/checks/valid-local-blocks/index.ts +0 -100
- package/src/checks/valid-local-blocks/valid-block-utils.ts +0 -97
- package/src/checks/valid-schema/index.spec.ts +0 -174
- package/src/checks/valid-schema/index.ts +0 -41
- package/src/checks/valid-schema-name/index.spec.ts +0 -112
- package/src/checks/valid-schema-name/index.ts +0 -75
- package/src/checks/valid-settings-key/index.spec.ts +0 -321
- package/src/checks/valid-settings-key/index.ts +0 -144
- package/src/checks/valid-static-block-type/index.spec.ts +0 -38
- package/src/checks/valid-static-block-type/index.ts +0 -58
- package/src/checks/valid-visible-if/index.spec.ts +0 -619
- package/src/checks/valid-visible-if/index.ts +0 -184
- package/src/checks/valid-visible-if/visible-if-utils.ts +0 -158
- package/src/tags/content-for.ts +0 -25
- package/src/to-schema.ts +0 -231
- package/src/types/schemas/index.ts +0 -5
- package/src/types/schemas/preset.ts +0 -52
- package/src/types/schemas/section.ts +0 -86
- package/src/types/schemas/setting.ts +0 -320
- package/src/types/schemas/template.ts +0 -34
- package/src/types/schemas/theme-block.ts +0 -34
- package/src/types/theme-schemas.ts +0 -80
- package/src/utils/block.ts +0 -300
- package/src/utils/markup.ts +0 -10
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from 'vitest';
|
|
2
|
-
import { LiquidFreeSettings } from './index';
|
|
3
|
-
import { check, MockTheme } from '../../test';
|
|
4
|
-
|
|
5
|
-
describe('LiquidFreeSettings validation', () => {
|
|
6
|
-
const paths = ['sections', 'blocks'];
|
|
7
|
-
paths.forEach((path) => {
|
|
8
|
-
it(`should not report errors for valid settings without liquid logic in ${path} bucket`, async () => {
|
|
9
|
-
const theme: MockTheme = {
|
|
10
|
-
[`${path}/test-section.liquid`]: `
|
|
11
|
-
{% schema %}
|
|
12
|
-
{
|
|
13
|
-
"name": "Section name",
|
|
14
|
-
"settings": [
|
|
15
|
-
{
|
|
16
|
-
"id": "text_value",
|
|
17
|
-
"type": "text",
|
|
18
|
-
"label": "Text Value",
|
|
19
|
-
"default": "Some text without liquid logic."
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
{% endschema %}
|
|
24
|
-
`,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const offenses = await check(theme, [LiquidFreeSettings]);
|
|
28
|
-
expect(offenses).to.have.length(0);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it(`should not report errors for valid settings with dynamic source liquid logic in ${path} bucket`, async () => {
|
|
32
|
-
const theme: MockTheme = {
|
|
33
|
-
[`${path}/test-section.liquid`]: `
|
|
34
|
-
{% schema %}
|
|
35
|
-
{
|
|
36
|
-
"name": "Section name",
|
|
37
|
-
"settings": [
|
|
38
|
-
{
|
|
39
|
-
"id": "text_value",
|
|
40
|
-
"type": "text",
|
|
41
|
-
"label": "Text Value",
|
|
42
|
-
"default": "Title {{ product.title }}"
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
{% endschema %}
|
|
47
|
-
`,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const offenses = await check(theme, [LiquidFreeSettings]);
|
|
51
|
-
expect(offenses).to.have.length(0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it(`should report an error when settings value contains Liquid logic in ${path} bucket`, async () => {
|
|
55
|
-
const theme: MockTheme = {
|
|
56
|
-
[`${path}/test-section.liquid`]: `
|
|
57
|
-
{% schema %}
|
|
58
|
-
{
|
|
59
|
-
"name": "Section name",
|
|
60
|
-
"settings": [
|
|
61
|
-
{
|
|
62
|
-
"id": "input_with_logic",
|
|
63
|
-
"type": "text",
|
|
64
|
-
"label": "Input with Logic",
|
|
65
|
-
"default": "Hello {% if user %} User {% endif %}!"
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
{% endschema %}
|
|
70
|
-
`,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const offenses = await check(theme, [LiquidFreeSettings]);
|
|
74
|
-
expect(offenses).to.have.length(1);
|
|
75
|
-
expect(offenses[0].message).to.equal('Settings values cannot contain liquid logic.');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it(`should report an error with correct indices when settings value contains Liquid logic in ${path} bucket`, async () => {
|
|
79
|
-
const theme: MockTheme = {
|
|
80
|
-
[`${path}/test-section.liquid`]: `
|
|
81
|
-
{% schema %}
|
|
82
|
-
{
|
|
83
|
-
"name": "Section name",
|
|
84
|
-
"settings": [
|
|
85
|
-
{
|
|
86
|
-
"id": "input_with_logic",
|
|
87
|
-
"type": "text",
|
|
88
|
-
"label": "Input with Logic",
|
|
89
|
-
"default": "Hello {% if user %} User {% endif %}!"
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
{% endschema %}
|
|
94
|
-
`,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const offenses = await check(theme, [LiquidFreeSettings]);
|
|
98
|
-
expect(offenses).to.have.length(1);
|
|
99
|
-
const content = theme[`${path}/test-section.liquid`];
|
|
100
|
-
const errorContent = content.slice(offenses[0].start.index, offenses[0].end.index);
|
|
101
|
-
expect(errorContent).to.equal('"Hello {% if user %} User {% endif %}!"');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it(`should report an error when settings value contains Liquid logic in object format in ${path} bucket`, async () => {
|
|
105
|
-
const theme: MockTheme = {
|
|
106
|
-
[`${path}/test-section.liquid`]: `
|
|
107
|
-
{% schema %}
|
|
108
|
-
{
|
|
109
|
-
"name": "test",
|
|
110
|
-
"settings": {
|
|
111
|
-
"text_block": {
|
|
112
|
-
"type": "text",
|
|
113
|
-
"id": "text_block",
|
|
114
|
-
"label": "Text Block",
|
|
115
|
-
"default": "Hello {% if user %} User {% endif %}!"
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
{% endschema %}
|
|
120
|
-
`,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const offenses = await check(theme, [LiquidFreeSettings]);
|
|
124
|
-
expect(offenses).to.have.length(1);
|
|
125
|
-
expect(offenses[0].message).to.equal('Settings values cannot contain liquid logic.');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it(`should report errors when preset block values contain Liquid logic in ${path} bucket`, async () => {
|
|
129
|
-
const theme: MockTheme = {
|
|
130
|
-
[`${path}/test-section.liquid`]: `
|
|
131
|
-
{% schema %}
|
|
132
|
-
{
|
|
133
|
-
"name": "Section name",
|
|
134
|
-
"presets": [
|
|
135
|
-
{
|
|
136
|
-
"name": "Default",
|
|
137
|
-
"block": [
|
|
138
|
-
{
|
|
139
|
-
"type": "text",
|
|
140
|
-
"settings": {
|
|
141
|
-
"text": "Hello World!{% random liquid logic %}"
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
]
|
|
145
|
-
}
|
|
146
|
-
]
|
|
147
|
-
}
|
|
148
|
-
{% endschema %}
|
|
149
|
-
`,
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const offenses = await check(theme, [LiquidFreeSettings]);
|
|
153
|
-
expect(offenses).to.have.length(1);
|
|
154
|
-
expect(offenses[0].message).to.equal('Settings values cannot contain liquid logic.');
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it(`should not report errors when settings value is available_if and it contains liquid logic`, async () => {
|
|
158
|
-
const theme: MockTheme = {
|
|
159
|
-
[`${path}/test-section.liquid`]: `
|
|
160
|
-
{% schema %}
|
|
161
|
-
{
|
|
162
|
-
"name": "test",
|
|
163
|
-
"settings": {
|
|
164
|
-
"text_block": {
|
|
165
|
-
"type": "text",
|
|
166
|
-
"id": "text_block",
|
|
167
|
-
"label": "Text Block",
|
|
168
|
-
"default": "Hello World!",
|
|
169
|
-
"visible_if": "{% if user %} true {% endif %}"
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
{% endschema %}
|
|
174
|
-
`,
|
|
175
|
-
};
|
|
176
|
-
const offenses = await check(theme, [LiquidFreeSettings]);
|
|
177
|
-
expect(offenses).toEqual([]);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { toJSONAST } from '../../to-source-code';
|
|
2
|
-
import {
|
|
3
|
-
JSONNode,
|
|
4
|
-
LiquidCheckDefinition,
|
|
5
|
-
LiteralNode,
|
|
6
|
-
Severity,
|
|
7
|
-
SourceCodeType,
|
|
8
|
-
} from '../../types';
|
|
9
|
-
import { visit } from '../../visitor';
|
|
10
|
-
|
|
11
|
-
export const LiquidFreeSettings: LiquidCheckDefinition = {
|
|
12
|
-
meta: {
|
|
13
|
-
code: 'LiquidFreeSettings',
|
|
14
|
-
name: 'Check for liquid free settings values',
|
|
15
|
-
docs: {
|
|
16
|
-
description: 'Ensures settings values are liquid free.',
|
|
17
|
-
recommended: true,
|
|
18
|
-
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/liquid-free-settings',
|
|
19
|
-
},
|
|
20
|
-
type: SourceCodeType.LiquidHtml,
|
|
21
|
-
severity: Severity.WARNING,
|
|
22
|
-
schema: {},
|
|
23
|
-
targets: [],
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
create(context) {
|
|
27
|
-
return {
|
|
28
|
-
async LiquidRawTag(node) {
|
|
29
|
-
if (node.name !== 'schema' || node.body.kind !== 'json') {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const jsonString = node.source.slice(
|
|
34
|
-
node.blockStartPosition.end,
|
|
35
|
-
node.blockEndPosition.start,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const jsonFile = toJSONAST(jsonString);
|
|
39
|
-
if (jsonFile instanceof Error) return;
|
|
40
|
-
|
|
41
|
-
await visit<SourceCodeType.JSON, void>(jsonFile, {
|
|
42
|
-
async Property(schemaNode, ancestors) {
|
|
43
|
-
if (isInArrayWithParentKey(ancestors, 'settings') && isLiteralNode(schemaNode.value)) {
|
|
44
|
-
const { value, loc } = schemaNode.value;
|
|
45
|
-
const propertyValue = schemaNode.key.value;
|
|
46
|
-
if (
|
|
47
|
-
typeof value === 'string' &&
|
|
48
|
-
propertyValue !== 'visible_if' &&
|
|
49
|
-
value.includes('{%') &&
|
|
50
|
-
value.includes('%}')
|
|
51
|
-
) {
|
|
52
|
-
context.report({
|
|
53
|
-
message: 'Settings values cannot contain liquid logic.',
|
|
54
|
-
startIndex: node.blockStartPosition.end + loc!.start.offset,
|
|
55
|
-
endIndex: node.blockStartPosition.end + loc!.end.offset,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
function isLiteralNode(node: JSONNode): node is LiteralNode {
|
|
67
|
-
return node.type === 'Literal';
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function isInArrayWithParentKey(ancestors: JSONNode[], parentKey: string): boolean {
|
|
71
|
-
return ancestors.some((ancestor, index) => {
|
|
72
|
-
const parent = ancestors[index - 1];
|
|
73
|
-
return (
|
|
74
|
-
(ancestor.type === 'Array' || ancestor.type === 'Object') &&
|
|
75
|
-
parent?.type === 'Property' &&
|
|
76
|
-
parent.key?.value === parentKey
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { applySuggestions, runLiquidCheck } from '../../test';
|
|
3
|
-
import { MissingContentForArguments } from '.';
|
|
4
|
-
|
|
5
|
-
function check(existingCode: string, source: string) {
|
|
6
|
-
return runLiquidCheck(
|
|
7
|
-
MissingContentForArguments,
|
|
8
|
-
source,
|
|
9
|
-
undefined,
|
|
10
|
-
{},
|
|
11
|
-
{
|
|
12
|
-
'blocks/card.liquid': existingCode,
|
|
13
|
-
},
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const blockSourceCode = `
|
|
18
|
-
{% doc %}
|
|
19
|
-
@param {string} required_string - A required string
|
|
20
|
-
@param {number} required_number - A required number
|
|
21
|
-
@param {boolean} required_boolean - A required boolean
|
|
22
|
-
@param {object} required_object - A required object
|
|
23
|
-
@param {string} [optional_string] - An optional string
|
|
24
|
-
@param {number} [optional_number] - An optional number
|
|
25
|
-
@param {object} [optional_object] - An optional object
|
|
26
|
-
@param {boolean} [optional_boolean] - An optional boolean
|
|
27
|
-
{% enddoc %}
|
|
28
|
-
`;
|
|
29
|
-
|
|
30
|
-
describe('Module: MissingContentForArguments', () => {
|
|
31
|
-
describe('missing required arguments', () => {
|
|
32
|
-
it('should report missing required arguments', async () => {
|
|
33
|
-
const offenses = await check(blockSourceCode, `{% content_for 'block', type: 'card' %}`);
|
|
34
|
-
|
|
35
|
-
expect(offenses).toHaveLength(4);
|
|
36
|
-
expect(offenses[0].message).toBe(
|
|
37
|
-
"Missing required argument 'required_string' in content_for tag for static block 'card'.",
|
|
38
|
-
);
|
|
39
|
-
expect(offenses[1].message).toBe(
|
|
40
|
-
"Missing required argument 'required_number' in content_for tag for static block 'card'.",
|
|
41
|
-
);
|
|
42
|
-
expect(offenses[2].message).toBe(
|
|
43
|
-
"Missing required argument 'required_boolean' in content_for tag for static block 'card'.",
|
|
44
|
-
);
|
|
45
|
-
expect(offenses[3].message).toBe(
|
|
46
|
-
"Missing required argument 'required_object' in content_for tag for static block 'card'.",
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('suggestions', () => {
|
|
52
|
-
it('should suggest adding missing required arguments when none already exist', async () => {
|
|
53
|
-
const sourceCode = `{% content_for 'block', type: 'card' %}`;
|
|
54
|
-
const offenses = await check(blockSourceCode, sourceCode);
|
|
55
|
-
|
|
56
|
-
expect(offenses).toHaveLength(4);
|
|
57
|
-
const x = applySuggestions(sourceCode, offenses[0]);
|
|
58
|
-
expect(x).toEqual([`{% content_for 'block', type: 'card', required_string: '' %}`]);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('edge cases', () => {
|
|
63
|
-
it('should handle mixed case type annotations', async () => {
|
|
64
|
-
const sourceCode = `{% content_for 'block', type: 'card', text: "hello", count: 5, flag: true, data: product %}`;
|
|
65
|
-
const offenses = await runLiquidCheck(
|
|
66
|
-
MissingContentForArguments,
|
|
67
|
-
sourceCode,
|
|
68
|
-
undefined,
|
|
69
|
-
{},
|
|
70
|
-
{
|
|
71
|
-
'blocks/card.liquid': `
|
|
72
|
-
{% doc %}
|
|
73
|
-
@param {String} text - The text
|
|
74
|
-
@param {NUMBER} count - The count
|
|
75
|
-
@param {BOOLEAN} flag - The flag
|
|
76
|
-
@param {Object} data - The data
|
|
77
|
-
{% enddoc %}
|
|
78
|
-
<div>{{ text }}{{ count }}{{ flag }}{{ data }}</div>
|
|
79
|
-
`,
|
|
80
|
-
},
|
|
81
|
-
);
|
|
82
|
-
expect(offenses).toHaveLength(0);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should not report when block has no doc comment', async () => {
|
|
86
|
-
const sourceCode = `{% content_for 'block', type: 'card', title: 'My Card' %}`;
|
|
87
|
-
const offenses = await runLiquidCheck(
|
|
88
|
-
MissingContentForArguments,
|
|
89
|
-
sourceCode,
|
|
90
|
-
undefined,
|
|
91
|
-
{},
|
|
92
|
-
{
|
|
93
|
-
'blocks/card.liquid': `<h1>This partial has no doc comment</h1>`,
|
|
94
|
-
},
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
expect(offenses).toHaveLength(0);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should not report when LiquidDoc definition has no defined params', async () => {
|
|
101
|
-
const sourceCode = `{% content_for 'block', type: 'card', title: 'My Card' %}`;
|
|
102
|
-
const offenses = await runLiquidCheck(
|
|
103
|
-
MissingContentForArguments,
|
|
104
|
-
sourceCode,
|
|
105
|
-
undefined,
|
|
106
|
-
{},
|
|
107
|
-
{
|
|
108
|
-
'blocks/card.liquid': `
|
|
109
|
-
{% doc %}
|
|
110
|
-
@description this is a description
|
|
111
|
-
@example this is an example
|
|
112
|
-
{% enddoc %}
|
|
113
|
-
<div>{{ title }}</div>
|
|
114
|
-
<div>{{ description }}</div>
|
|
115
|
-
`,
|
|
116
|
-
},
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
expect(offenses).toHaveLength(0);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should not report when block name is a VariableLookup', async () => {
|
|
123
|
-
const sourceCode = `{% assign block_name = 'card' %}{% content_for 'block', type: block_name, title: 'My Card' %}`;
|
|
124
|
-
const offenses = await runLiquidCheck(
|
|
125
|
-
MissingContentForArguments,
|
|
126
|
-
sourceCode,
|
|
127
|
-
undefined,
|
|
128
|
-
{},
|
|
129
|
-
{
|
|
130
|
-
'blocks/card.liquid': `
|
|
131
|
-
{% doc %}
|
|
132
|
-
@param {string} title - The title of the card
|
|
133
|
-
@param {string} description - The description of the card
|
|
134
|
-
{% enddoc %}
|
|
135
|
-
<div>{{ title }}</div>
|
|
136
|
-
<div>{{ description }}</div>
|
|
137
|
-
`,
|
|
138
|
-
},
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
expect(offenses).toHaveLength(0);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';
|
|
2
|
-
import { ContentForMarkup } from '@platformos/liquid-html-parser';
|
|
3
|
-
import {
|
|
4
|
-
getBlockName,
|
|
5
|
-
getLiquidDocParams,
|
|
6
|
-
reportMissingArguments,
|
|
7
|
-
} from '../../liquid-doc/arguments';
|
|
8
|
-
|
|
9
|
-
export const MissingContentForArguments: LiquidCheckDefinition = {
|
|
10
|
-
meta: {
|
|
11
|
-
code: 'MissingContentForArguments',
|
|
12
|
-
name: 'Missing ContentFor Arguments',
|
|
13
|
-
docs: {
|
|
14
|
-
description:
|
|
15
|
-
'This check ensures that all required arguments are provided when rendering a static block.',
|
|
16
|
-
recommended: true,
|
|
17
|
-
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/missing-content-for-arguments',
|
|
18
|
-
},
|
|
19
|
-
type: SourceCodeType.LiquidHtml,
|
|
20
|
-
severity: Severity.WARNING,
|
|
21
|
-
schema: {},
|
|
22
|
-
targets: [],
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
create(context) {
|
|
26
|
-
return {
|
|
27
|
-
async ContentForMarkup(node: ContentForMarkup) {
|
|
28
|
-
const blockName = getBlockName(node);
|
|
29
|
-
|
|
30
|
-
if (!blockName) return;
|
|
31
|
-
|
|
32
|
-
const liquidDocParameters = await getLiquidDocParams(context, `blocks/${blockName}.liquid`);
|
|
33
|
-
|
|
34
|
-
if (!liquidDocParameters) return;
|
|
35
|
-
|
|
36
|
-
const providedParams = new Map(node.args.map((arg) => [arg.name, arg]));
|
|
37
|
-
|
|
38
|
-
const missingRequiredParams = Array.from(liquidDocParameters.values()).filter(
|
|
39
|
-
(p) => p.required && !providedParams.has(p.name),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
reportMissingArguments(context, node, missingRequiredParams, blockName);
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from 'vitest';
|
|
2
|
-
import { highlightedOffenses, runLiquidCheck } from '../../test';
|
|
3
|
-
import { PaginationSize } from './index';
|
|
4
|
-
|
|
5
|
-
describe('Module: PaginationSize', () => {
|
|
6
|
-
it('should report an offense when paginate size is less than minSize', async () => {
|
|
7
|
-
const sourceCode = `
|
|
8
|
-
{% paginate collection.products by 0 %}
|
|
9
|
-
{% endpaginate %}
|
|
10
|
-
`;
|
|
11
|
-
const offenses = await runLiquidCheck(PaginationSize, sourceCode);
|
|
12
|
-
|
|
13
|
-
expect(offenses).to.have.length(1);
|
|
14
|
-
expect(offenses[0].message).to.equal(
|
|
15
|
-
'Pagination size must be a positive integer between 1 and 250.',
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
const highlights = highlightedOffenses({ 'file.liquid': sourceCode }, offenses);
|
|
19
|
-
expect(highlights).to.eql(['0']);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should report an offense when paginate size is greater than maxSize', async () => {
|
|
23
|
-
const sourceCode = `
|
|
24
|
-
{% paginate collection.products by 251 %}
|
|
25
|
-
{% endpaginate %}
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
const offenses = await runLiquidCheck(PaginationSize, sourceCode);
|
|
29
|
-
|
|
30
|
-
expect(offenses).to.have.length(1);
|
|
31
|
-
expect(offenses[0].message).to.equal(
|
|
32
|
-
'Pagination size must be a positive integer between 1 and 250.',
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const highlights = highlightedOffenses({ 'file.liquid': sourceCode }, offenses);
|
|
36
|
-
expect(highlights).to.eql(['251']);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should not report an offense when paginate size is within the minSize and maxSize range', async () => {
|
|
40
|
-
const sourceCode = `
|
|
41
|
-
{% paginate collection.products by 25 %}
|
|
42
|
-
{% endpaginate %}
|
|
43
|
-
`;
|
|
44
|
-
|
|
45
|
-
const offenses = await runLiquidCheck(PaginationSize, sourceCode);
|
|
46
|
-
expect(offenses).to.have.length(0);
|
|
47
|
-
|
|
48
|
-
const highlights = highlightedOffenses({ 'file.liquid': sourceCode }, offenses);
|
|
49
|
-
expect(highlights).to.be.empty;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should not report an offense when paginate size is a section setting with a valid default value', async () => {
|
|
53
|
-
const sourceCode = `
|
|
54
|
-
{% paginate collection.products by section.settings.products_per_page %}
|
|
55
|
-
{% endpaginate %}
|
|
56
|
-
{% schema %}
|
|
57
|
-
{
|
|
58
|
-
"name": "test",
|
|
59
|
-
"settings": [
|
|
60
|
-
{
|
|
61
|
-
"type": "number",
|
|
62
|
-
"id": "products_per_page",
|
|
63
|
-
"label": "Products per Page",
|
|
64
|
-
"default": 12
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
{% endschema %}
|
|
69
|
-
`;
|
|
70
|
-
|
|
71
|
-
const offenses = await runLiquidCheck(PaginationSize, sourceCode);
|
|
72
|
-
expect(offenses).to.have.length(0);
|
|
73
|
-
const highlights = highlightedOffenses({ 'file.liquid': sourceCode }, offenses);
|
|
74
|
-
expect(highlights).to.be.empty;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should report an offense when paginate size is a section setting with an invalid default value', async () => {
|
|
78
|
-
const sourceCode = `
|
|
79
|
-
{% paginate collection.products by section.settings.products_per_page %}
|
|
80
|
-
{% endpaginate %}
|
|
81
|
-
{% schema %}
|
|
82
|
-
{
|
|
83
|
-
"name": "test",
|
|
84
|
-
"settings": [
|
|
85
|
-
{
|
|
86
|
-
"type": "number",
|
|
87
|
-
"id": "products_per_page",
|
|
88
|
-
"label": "Products per Page",
|
|
89
|
-
"default": 251
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
{% endschema %}
|
|
94
|
-
`;
|
|
95
|
-
|
|
96
|
-
const offenses = await runLiquidCheck(PaginationSize, sourceCode);
|
|
97
|
-
expect(offenses).to.have.length(1);
|
|
98
|
-
expect(offenses[0].message).to.equal(
|
|
99
|
-
`This setting's default value should be between 1 and 250 but is currently 251.`,
|
|
100
|
-
);
|
|
101
|
-
const highlights = highlightedOffenses({ 'file.liquid': sourceCode }, offenses);
|
|
102
|
-
expect(highlights).to.eql(['section.settings.products_per_page']);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should report an offense when paginate size is a section setting with a missing default value', async () => {
|
|
106
|
-
const sourceCode = `
|
|
107
|
-
{% paginate collection.products by section.settings.products_per_page %}
|
|
108
|
-
{% endpaginate %}
|
|
109
|
-
{% schema %}
|
|
110
|
-
{
|
|
111
|
-
"name": "test",
|
|
112
|
-
"settings": [
|
|
113
|
-
{
|
|
114
|
-
"type": "number",
|
|
115
|
-
"id": "products_per_page",
|
|
116
|
-
"label": "Products per Page"
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
{% endschema %}
|
|
121
|
-
`;
|
|
122
|
-
|
|
123
|
-
const offenses = await runLiquidCheck(PaginationSize, sourceCode);
|
|
124
|
-
expect(offenses).to.have.length(1);
|
|
125
|
-
expect(offenses[0].message).to.equal(
|
|
126
|
-
'Default pagination size should be defined in the section settings.',
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
const highlights = highlightedOffenses({ 'file.liquid': sourceCode }, offenses);
|
|
130
|
-
expect(highlights).to.eql(['section.settings.products_per_page']);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should not report an offense when settings is not an array', async () => {
|
|
134
|
-
const sourceCode = `
|
|
135
|
-
{% paginate collection.products by section.settings.products_per_page %}
|
|
136
|
-
{% endpaginate %}
|
|
137
|
-
{% schema %}
|
|
138
|
-
{
|
|
139
|
-
"name": "test",
|
|
140
|
-
"settings": {
|
|
141
|
-
"products_per_page": {
|
|
142
|
-
"type": "number",
|
|
143
|
-
"id": "products_per_page",
|
|
144
|
-
"label": "Products per Page",
|
|
145
|
-
"default": 51
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
{% endschema %}
|
|
150
|
-
`;
|
|
151
|
-
|
|
152
|
-
const offenses = await runLiquidCheck(PaginationSize, sourceCode);
|
|
153
|
-
expect(offenses).to.have.length(0);
|
|
154
|
-
|
|
155
|
-
const highlights = highlightedOffenses({ 'file.liquid': sourceCode }, offenses);
|
|
156
|
-
expect(highlights).to.be.empty;
|
|
157
|
-
});
|
|
158
|
-
});
|