@platformos/platformos-check-common 0.0.6 → 0.0.8
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/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/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/index.js +2 -2
- 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 +20 -31
- 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 +7 -30
- 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 +2 -7
- package/dist/context-utils.js +39 -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/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 +4 -5
- package/dist/index.js +34 -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 +20 -28
- 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 +1 -1
- package/dist/liquid-doc/utils.js +4 -3
- package/dist/liquid-doc/utils.js.map +1 -1
- package/dist/path.d.ts +1 -0
- package/dist/path.js +5 -1
- package/dist/path.js.map +1 -1
- package/dist/test/MockApp.d.ts +16 -0
- 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-source-code.d.ts +4 -3
- 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 +18 -67
- package/dist/types.js +3 -5
- package/dist/types.js.map +1 -1
- package/dist/utils/file-utils.js +1 -2
- package/dist/utils/file-utils.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 +9 -9
- 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.ts +1 -1
- package/src/checks/graphql/index.ts +1 -1
- package/src/checks/img-width-and-height/index.ts +1 -1
- package/src/checks/index.ts +11 -80
- package/src/checks/invalid-hash-assign-target/index.spec.ts +14 -14
- package/src/checks/json-syntax-error/index.ts +1 -1
- 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/index.spec.ts +1 -6
- package/src/checks/liquid-html-syntax-error/index.ts +2 -2
- package/src/checks/matching-translations/index.spec.ts +89 -346
- package/src/checks/matching-translations/index.ts +24 -35
- package/src/checks/metadata-params/index.ts +5 -7
- 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 +6 -20
- 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 +3 -109
- package/src/checks/undefined-object/index.ts +8 -33
- 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 +1 -1
- 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 +1 -1
- 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 +39 -128
- package/src/disabled-checks/index.spec.ts +35 -0
- package/src/disabled-checks/index.ts +4 -2
- 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 +0 -1
- package/src/index.ts +33 -21
- package/src/jsonc/parse.ts +1 -1
- package/src/liquid-doc/arguments.spec.ts +19 -45
- package/src/liquid-doc/arguments.ts +26 -39
- package/src/liquid-doc/liquidDoc.ts +1 -2
- package/src/liquid-doc/utils.ts +4 -3
- package/src/path.ts +1 -0
- package/src/test/{MockTheme.ts → MockApp.ts} +1 -1
- package/src/test/MockFileSystem.ts +9 -6
- package/src/test/index.ts +1 -1
- package/src/test/test-helper.ts +29 -127
- package/src/to-source-code.ts +20 -1
- package/src/types/{theme-liquid-docs.ts → platformos-liquid-docs.ts} +8 -13
- package/src/types/schemas/index.ts +0 -2
- package/src/types.ts +21 -92
- package/src/utils/file-utils.ts +0 -1
- package/src/utils/index.ts +0 -1
- 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/section.ts +0 -86
- 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
|
@@ -205,20 +205,6 @@ describe('Module: UndefinedObject', () => {
|
|
|
205
205
|
expect(offenses.map((e) => e.message)).toEqual(["Unknown object 'c' used."]);
|
|
206
206
|
});
|
|
207
207
|
|
|
208
|
-
it('should contextually report on the undefined nature of the paginate object (defined in paginate tag, undefined outside)', async () => {
|
|
209
|
-
const sourceCode = `
|
|
210
|
-
{% assign col = 'string' | split: '' %}
|
|
211
|
-
{% paginate col by 5 %}
|
|
212
|
-
{{ paginate }}
|
|
213
|
-
{% endpaginate %}{{ paginate }}
|
|
214
|
-
`;
|
|
215
|
-
|
|
216
|
-
const offenses = await runLiquidCheck(UndefinedObject, sourceCode);
|
|
217
|
-
|
|
218
|
-
expect(offenses).toHaveLength(1);
|
|
219
|
-
expect(offenses.map((e) => e.message)).toEqual(["Unknown object 'paginate' used."]);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
208
|
it('should contextually report on the undefined nature of the form object (defined in form tag, undefined outside)', async () => {
|
|
223
209
|
const sourceCode = `
|
|
224
210
|
{% form "cart" %}
|
|
@@ -313,42 +299,9 @@ describe('Module: UndefinedObject', () => {
|
|
|
313
299
|
}
|
|
314
300
|
});
|
|
315
301
|
|
|
316
|
-
it('should support contextual exceptions', async () => {
|
|
317
|
-
let offenses: Offense[];
|
|
318
|
-
const contexts: [string, string][] = [
|
|
319
|
-
['section', 'sections/section.liquid'],
|
|
320
|
-
['predictive_search', 'sections/predictive-search.liquid'],
|
|
321
|
-
['recommendations', 'sections/recommendations.liquid'],
|
|
322
|
-
['comment', 'sections/main-article.liquid'],
|
|
323
|
-
['block', 'blocks/theme-app-extension.liquid'],
|
|
324
|
-
['app', 'blocks/theme-app-extension.liquid'],
|
|
325
|
-
['app', 'app/views/partials/theme-app-extension.liquid'],
|
|
326
|
-
];
|
|
327
|
-
for (const [object, goodPath] of contexts) {
|
|
328
|
-
offenses = await runLiquidCheck(UndefinedObject, `{{ ${object} }}`, goodPath);
|
|
329
|
-
expect(offenses).toHaveLength(0);
|
|
330
|
-
offenses = await runLiquidCheck(UndefinedObject, `{{ ${object} }}`, 'file.liquid');
|
|
331
|
-
expect(offenses).toHaveLength(1);
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it('should support contextual exceptions for checkout.liquid', async () => {
|
|
302
|
+
it('should support contextual exceptions for partials', async () => {
|
|
336
303
|
let offenses: Offense[];
|
|
337
|
-
const contexts: [string, string][] = [
|
|
338
|
-
['locale', 'layout/checkout.liquid'],
|
|
339
|
-
['direction', 'layout/checkout.liquid'],
|
|
340
|
-
['skip_to_content_link', 'layout/checkout.liquid'],
|
|
341
|
-
['checkout_html_classes', 'layout/checkout.liquid'],
|
|
342
|
-
['checkout_stylesheets', 'layout/checkout.liquid'],
|
|
343
|
-
['checkout_scripts', 'layout/checkout.liquid'],
|
|
344
|
-
['content_for_logo', 'layout/checkout.liquid'],
|
|
345
|
-
['breadcrumb', 'layout/checkout.liquid'],
|
|
346
|
-
['order_summary_toggle', 'layout/checkout.liquid'],
|
|
347
|
-
['content_for_order_summary', 'layout/checkout.liquid'],
|
|
348
|
-
['alternative_payment_methods', 'layout/checkout.liquid'],
|
|
349
|
-
['content_for_footer', 'layout/checkout.liquid'],
|
|
350
|
-
['tracking_code', 'layout/checkout.liquid'],
|
|
351
|
-
];
|
|
304
|
+
const contexts: [string, string][] = [['app', 'app/views/partials/theme-app-extension.liquid']];
|
|
352
305
|
for (const [object, goodPath] of contexts) {
|
|
353
306
|
offenses = await runLiquidCheck(UndefinedObject, `{{ ${object} }}`, goodPath);
|
|
354
307
|
expect(offenses).toHaveLength(0);
|
|
@@ -374,44 +327,12 @@ describe('Module: UndefinedObject', () => {
|
|
|
374
327
|
`;
|
|
375
328
|
|
|
376
329
|
const offenses = await runLiquidCheck(UndefinedObject, sourceCode, 'file.liquid', {
|
|
377
|
-
|
|
330
|
+
platformosDocset: undefined,
|
|
378
331
|
});
|
|
379
332
|
|
|
380
333
|
expect(offenses).toHaveLength(0);
|
|
381
334
|
});
|
|
382
335
|
|
|
383
|
-
it('should not report an offense when object is defined with @param in a block file', async () => {
|
|
384
|
-
const sourceCode = `
|
|
385
|
-
{% doc %}
|
|
386
|
-
@param {string} text
|
|
387
|
-
{% enddoc %}
|
|
388
|
-
|
|
389
|
-
{{ text }}
|
|
390
|
-
`;
|
|
391
|
-
|
|
392
|
-
const filePath = 'blocks/my-custom-block.liquid';
|
|
393
|
-
const offenses = await runLiquidCheck(UndefinedObject, sourceCode, filePath);
|
|
394
|
-
|
|
395
|
-
expect(offenses).toHaveLength(0);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it('should report an offense when an undefined object is used alongside @param in a block file', async () => {
|
|
399
|
-
const sourceCode = `
|
|
400
|
-
{% doc %}
|
|
401
|
-
@param {string} text
|
|
402
|
-
{% enddoc %}
|
|
403
|
-
|
|
404
|
-
{{ text }}
|
|
405
|
-
{{ undefined_variable }}
|
|
406
|
-
`;
|
|
407
|
-
|
|
408
|
-
const filePath = 'blocks/my-custom-block.liquid';
|
|
409
|
-
const offenses = await runLiquidCheck(UndefinedObject, sourceCode, filePath);
|
|
410
|
-
|
|
411
|
-
expect(offenses).toHaveLength(1);
|
|
412
|
-
expect(offenses[0].message).toBe("Unknown object 'undefined_variable' used.");
|
|
413
|
-
});
|
|
414
|
-
|
|
415
336
|
it('should not report an offense when a self defined variable is defined with a @param tag', async () => {
|
|
416
337
|
const sourceCode = `
|
|
417
338
|
{% doc %}
|
|
@@ -438,33 +359,6 @@ describe('Module: UndefinedObject', () => {
|
|
|
438
359
|
expect(offenses[0].message).toBe("Unknown object 'my_var' used.");
|
|
439
360
|
});
|
|
440
361
|
|
|
441
|
-
it('should not report an offense when using variables inside visible_if statements in a schema tag', async () => {
|
|
442
|
-
const sourceCode = `
|
|
443
|
-
{% schema %}
|
|
444
|
-
{
|
|
445
|
-
"settings": [
|
|
446
|
-
{
|
|
447
|
-
"type": "text",
|
|
448
|
-
"label": "foo",
|
|
449
|
-
"id": "foo",
|
|
450
|
-
}
|
|
451
|
-
{
|
|
452
|
-
"type": "text",
|
|
453
|
-
"label": "bar",
|
|
454
|
-
"id": "bar",
|
|
455
|
-
"visible_if": "{{ block.settings.foo }}",
|
|
456
|
-
}
|
|
457
|
-
]
|
|
458
|
-
}
|
|
459
|
-
{% endschema %}
|
|
460
|
-
`;
|
|
461
|
-
|
|
462
|
-
const offenses = await runLiquidCheck(UndefinedObject, sourceCode);
|
|
463
|
-
|
|
464
|
-
assert(offenses.length == 0);
|
|
465
|
-
expect(offenses).to.be.empty;
|
|
466
|
-
});
|
|
467
|
-
|
|
468
362
|
it('should report an offense when job_id is used inside background block', async () => {
|
|
469
363
|
const sourceCode = `
|
|
470
364
|
{% background job_id %}
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
LiquidTagBackground,
|
|
20
20
|
BackgroundInlineMarkup,
|
|
21
21
|
} from '@platformos/liquid-html-parser';
|
|
22
|
-
import { LiquidCheckDefinition, Severity, SourceCodeType,
|
|
22
|
+
import { LiquidCheckDefinition, Severity, SourceCodeType, PlatformOSDocset } from '../../types';
|
|
23
23
|
import { isError, last } from '../../utils';
|
|
24
24
|
import { isWithinRawTagThatDoesNotParseItsContents } from '../utils';
|
|
25
25
|
|
|
@@ -32,7 +32,7 @@ export const UndefinedObject: LiquidCheckDefinition = {
|
|
|
32
32
|
docs: {
|
|
33
33
|
description: 'This check exists to identify references to undefined Liquid objects.',
|
|
34
34
|
recommended: true,
|
|
35
|
-
url: 'https://
|
|
35
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/undefined-object',
|
|
36
36
|
},
|
|
37
37
|
type: SourceCodeType.LiquidHtml,
|
|
38
38
|
severity: Severity.WARNING,
|
|
@@ -49,11 +49,11 @@ export const UndefinedObject: LiquidCheckDefinition = {
|
|
|
49
49
|
/**
|
|
50
50
|
* Skip this check when definitions for global objects are unavailable.
|
|
51
51
|
*/
|
|
52
|
-
if (!context.
|
|
52
|
+
if (!context.platformosDocset) {
|
|
53
53
|
return {};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const
|
|
56
|
+
const platformosDocset = context.platformosDocset;
|
|
57
57
|
const scopedVariables: Map<string, Scope[]> = new Map();
|
|
58
58
|
const fileScopedVariables: Set<string> = new Set();
|
|
59
59
|
const variables: LiquidVariableLookup[] = [];
|
|
@@ -99,7 +99,7 @@ export const UndefinedObject: LiquidCheckDefinition = {
|
|
|
99
99
|
* {{ form }}
|
|
100
100
|
* {% endform %}
|
|
101
101
|
*/
|
|
102
|
-
if (
|
|
102
|
+
if (node.name === 'form') {
|
|
103
103
|
indexVariableScope(node.name, {
|
|
104
104
|
start: node.blockStartPosition.end,
|
|
105
105
|
end: node.blockEndPosition?.start,
|
|
@@ -166,7 +166,7 @@ export const UndefinedObject: LiquidCheckDefinition = {
|
|
|
166
166
|
},
|
|
167
167
|
|
|
168
168
|
async onCodePathEnd() {
|
|
169
|
-
const objects = await globalObjects(
|
|
169
|
+
const objects = await globalObjects(platformosDocset, relativePath);
|
|
170
170
|
|
|
171
171
|
objects.forEach((obj) => fileScopedVariables.add(obj.name));
|
|
172
172
|
|
|
@@ -192,8 +192,8 @@ export const UndefinedObject: LiquidCheckDefinition = {
|
|
|
192
192
|
},
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
-
async function globalObjects(
|
|
196
|
-
const objects = await
|
|
195
|
+
async function globalObjects(platformosDocset: PlatformOSDocset, relativePath: string) {
|
|
196
|
+
const objects = await platformosDocset.objects();
|
|
197
197
|
const contextualObjects = getContextualObjects(relativePath);
|
|
198
198
|
|
|
199
199
|
const globalObjects = objects.filter(({ access, name }) => {
|
|
@@ -209,31 +209,6 @@ async function globalObjects(themeDocset: ThemeDocset, relativePath: string) {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
function getContextualObjects(relativePath: string): string[] {
|
|
212
|
-
if (relativePath.startsWith('layout/checkout.liquid')) {
|
|
213
|
-
return [
|
|
214
|
-
'locale',
|
|
215
|
-
'direction',
|
|
216
|
-
'skip_to_content_link',
|
|
217
|
-
'checkout_html_classes',
|
|
218
|
-
'checkout_stylesheets',
|
|
219
|
-
'checkout_scripts',
|
|
220
|
-
'content_for_logo',
|
|
221
|
-
'breadcrumb',
|
|
222
|
-
'order_summary_toggle',
|
|
223
|
-
'content_for_order_summary',
|
|
224
|
-
'alternative_payment_methods',
|
|
225
|
-
'content_for_footer',
|
|
226
|
-
'tracking_code',
|
|
227
|
-
];
|
|
228
|
-
}
|
|
229
|
-
if (relativePath.startsWith('sections/')) {
|
|
230
|
-
return ['section', 'predictive_search', 'recommendations', 'comment'];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (relativePath.startsWith('blocks/')) {
|
|
234
|
-
return ['app', 'section', 'recommendations', 'block'];
|
|
235
|
-
}
|
|
236
|
-
|
|
237
212
|
if (relativePath.includes('views/partials/') || relativePath.includes('/lib/')) {
|
|
238
213
|
return ['app'];
|
|
239
214
|
}
|
|
@@ -8,7 +8,7 @@ export const UniqueDocParamNames: LiquidCheckDefinition = {
|
|
|
8
8
|
description:
|
|
9
9
|
'This check exists to ensure any parameter names defined in the `doc` tag are unique.',
|
|
10
10
|
recommended: true,
|
|
11
|
-
url: 'https://
|
|
11
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/unique-doc-param-names',
|
|
12
12
|
},
|
|
13
13
|
type: SourceCodeType.LiquidHtml,
|
|
14
14
|
severity: Severity.ERROR,
|
|
@@ -46,13 +46,13 @@ describe('Module: UnknownFilter', () => {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it('should not report an offense when a known filter is used (1)', async () => {
|
|
49
|
-
const sourceCode = `{{ 'hello' |
|
|
49
|
+
const sourceCode = `{{ 'hello' | parameterize }}`;
|
|
50
50
|
const offenses = await runLiquidCheck(UnknownFilter, sourceCode);
|
|
51
51
|
expect(offenses).toHaveLength(0);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
it('should not report an offense when a known filter is used (2)', async () => {
|
|
55
|
-
const sourceCode = `{{ 'hello' |
|
|
55
|
+
const sourceCode = `{{ 'hello' | slugify }}`;
|
|
56
56
|
const offenses = await runLiquidCheck(UnknownFilter, sourceCode);
|
|
57
57
|
expect(offenses).toHaveLength(0);
|
|
58
58
|
});
|
|
@@ -7,7 +7,7 @@ export const UnknownFilter: LiquidCheckDefinition = {
|
|
|
7
7
|
name: 'Prevent use of unknown filters',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'This check is aimed at preventing the use of unknown filters.',
|
|
10
|
-
url: 'https://
|
|
10
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/unknown-filter',
|
|
11
11
|
recommended: true,
|
|
12
12
|
},
|
|
13
13
|
type: SourceCodeType.LiquidHtml,
|
|
@@ -17,13 +17,13 @@ export const UnknownFilter: LiquidCheckDefinition = {
|
|
|
17
17
|
},
|
|
18
18
|
|
|
19
19
|
create(context) {
|
|
20
|
-
if (!context.
|
|
20
|
+
if (!context.platformosDocset) {
|
|
21
21
|
return {};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
async LiquidFilter(node) {
|
|
26
|
-
const knownFilters = await context.
|
|
26
|
+
const knownFilters = await context.platformosDocset!.filters();
|
|
27
27
|
|
|
28
28
|
if (!knownFilters.some((filter) => filter.name === node.name)) {
|
|
29
29
|
context.report({
|
|
@@ -56,7 +56,7 @@ export const UnknownProperty: LiquidCheckDefinition = {
|
|
|
56
56
|
let graphqlSchema: string | undefined;
|
|
57
57
|
const getGraphQLSchema = async (): Promise<string | undefined> => {
|
|
58
58
|
if (graphqlSchema === undefined) {
|
|
59
|
-
graphqlSchema = (await context.
|
|
59
|
+
graphqlSchema = (await context.platformosDocset?.graphQL()) ?? undefined;
|
|
60
60
|
}
|
|
61
61
|
return graphqlSchema;
|
|
62
62
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { applySuggestions,
|
|
2
|
+
import { applySuggestions, MockApp, runLiquidCheck } from '../../test';
|
|
3
3
|
import { UnrecognizedRenderPartialArguments } from '.';
|
|
4
4
|
|
|
5
5
|
function check(partial: string, source: string) {
|
|
@@ -113,14 +113,14 @@ describe('Module: UnrecognizedRenderPartialParams', () => {
|
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
it('should report when "with/for" alias syntax is used', async () => {
|
|
116
|
-
const
|
|
116
|
+
const mockApp = {
|
|
117
117
|
'app/views/partials/card.liquid': `
|
|
118
118
|
{% doc %}
|
|
119
119
|
@param {string} title - The title of the card
|
|
120
120
|
{% enddoc %}
|
|
121
121
|
<div>{{ title }}</div>
|
|
122
122
|
`,
|
|
123
|
-
} as
|
|
123
|
+
} as MockApp;
|
|
124
124
|
|
|
125
125
|
let sourceCode = `{% render 'card' with 'my-card' as unknown_param %}`;
|
|
126
126
|
let offenses = await runLiquidCheck(
|
|
@@ -128,7 +128,7 @@ describe('Module: UnrecognizedRenderPartialParams', () => {
|
|
|
128
128
|
sourceCode,
|
|
129
129
|
undefined,
|
|
130
130
|
{},
|
|
131
|
-
|
|
131
|
+
mockApp,
|
|
132
132
|
);
|
|
133
133
|
|
|
134
134
|
expect(offenses).toHaveLength(1);
|
|
@@ -146,7 +146,7 @@ describe('Module: UnrecognizedRenderPartialParams', () => {
|
|
|
146
146
|
sourceCode,
|
|
147
147
|
undefined,
|
|
148
148
|
{},
|
|
149
|
-
|
|
149
|
+
mockApp,
|
|
150
150
|
);
|
|
151
151
|
|
|
152
152
|
expect(offenses).toHaveLength(1);
|
|
@@ -16,7 +16,7 @@ export const UnrecognizedRenderPartialArguments: LiquidCheckDefinition = {
|
|
|
16
16
|
description:
|
|
17
17
|
'This check ensures that no unknown arguments are used when rendering a partial.',
|
|
18
18
|
recommended: true,
|
|
19
|
-
url: 'https://
|
|
19
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/unrecognized-render-partial-arguments',
|
|
20
20
|
},
|
|
21
21
|
type: SourceCodeType.LiquidHtml,
|
|
22
22
|
severity: Severity.WARNING,
|
|
@@ -60,10 +60,7 @@ export const UnrecognizedRenderPartialArguments: LiquidCheckDefinition = {
|
|
|
60
60
|
|
|
61
61
|
if (!partialName) return;
|
|
62
62
|
|
|
63
|
-
const liquidDocParameters = await getLiquidDocParams(
|
|
64
|
-
context,
|
|
65
|
-
`app/views/partials/${partialName}.liquid`,
|
|
66
|
-
);
|
|
63
|
+
const liquidDocParameters = await getLiquidDocParams(context, partialName);
|
|
67
64
|
|
|
68
65
|
if (!liquidDocParameters) return;
|
|
69
66
|
|
|
@@ -84,36 +84,6 @@ describe('Module: UnusedAssign', () => {
|
|
|
84
84
|
expect(offenses).not.to.be.empty;
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
it('should not report unused assigns for things used in a raw-like tag', async () => {
|
|
88
|
-
const tags = ['style'];
|
|
89
|
-
for (const tag of tags) {
|
|
90
|
-
const sourceCode = `
|
|
91
|
-
{% assign usedVar = 1 %}
|
|
92
|
-
{% ${tag} %}
|
|
93
|
-
{{ usedVar }}
|
|
94
|
-
{% end${tag} %}
|
|
95
|
-
`;
|
|
96
|
-
|
|
97
|
-
const offenses = await runLiquidCheck(UnusedAssign, sourceCode);
|
|
98
|
-
expect(offenses).to.be.empty;
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should report unused assigns for things used in raw code that gets stripped away (schema, etc)', async () => {
|
|
103
|
-
const tags = ['schema', 'javascript', 'stylesheet'];
|
|
104
|
-
for (const tag of tags) {
|
|
105
|
-
const sourceCode = `
|
|
106
|
-
{% assign usedVar = 1 %}
|
|
107
|
-
{% ${tag} %}
|
|
108
|
-
{{ usedVar }}
|
|
109
|
-
{% end${tag} %}
|
|
110
|
-
`;
|
|
111
|
-
|
|
112
|
-
const offenses = await runLiquidCheck(UnusedAssign, sourceCode);
|
|
113
|
-
expect(offenses).to.not.be.empty;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
87
|
it('should not report unused assigns for things used in a HTML raw-like tag', async () => {
|
|
118
88
|
const tags = ['style', 'script'];
|
|
119
89
|
for (const tag of tags) {
|
|
@@ -16,7 +16,7 @@ export const UnusedAssign: LiquidCheckDefinition = {
|
|
|
16
16
|
description:
|
|
17
17
|
'This check exists to prevent bloat in themes by surfacing variable definitions that are not used.',
|
|
18
18
|
recommended: true,
|
|
19
|
-
url: 'https://
|
|
19
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/unused-assign',
|
|
20
20
|
},
|
|
21
21
|
type: SourceCodeType.LiquidHtml,
|
|
22
22
|
severity: Severity.WARNING,
|
|
@@ -10,7 +10,7 @@ export const UnusedDocParam: LiquidCheckDefinition = {
|
|
|
10
10
|
description:
|
|
11
11
|
'This check exists to ensure any parameters defined in the `doc` tag are used within the partial.',
|
|
12
12
|
recommended: true,
|
|
13
|
-
url: 'https://
|
|
13
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/unused-doc-param',
|
|
14
14
|
},
|
|
15
15
|
type: SourceCodeType.LiquidHtml,
|
|
16
16
|
severity: Severity.WARNING,
|
package/src/checks/utils.ts
CHANGED
|
@@ -104,7 +104,7 @@ export function isLoopLiquidTag(tag: LiquidTag): tag is LiquidTagFor | LiquidTag
|
|
|
104
104
|
return LoopNamedTags.includes(tag.name as any);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const RawTagsThatDoNotParseTheirContents = ['raw'
|
|
107
|
+
const RawTagsThatDoNotParseTheirContents = ['raw'];
|
|
108
108
|
|
|
109
109
|
function isRawTagThatDoesNotParseItsContent(node: LiquidHtmlNode) {
|
|
110
110
|
return (
|
|
@@ -9,7 +9,7 @@ export const ValidDocParamTypes: LiquidCheckDefinition = {
|
|
|
9
9
|
description:
|
|
10
10
|
'This check exists to ensure any parameter types defined in the `doc` tag are valid.',
|
|
11
11
|
recommended: true,
|
|
12
|
-
url: 'https://
|
|
12
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/valid-doc-param-types',
|
|
13
13
|
},
|
|
14
14
|
type: SourceCodeType.LiquidHtml,
|
|
15
15
|
severity: Severity.ERROR,
|
|
@@ -18,14 +18,14 @@ export const ValidDocParamTypes: LiquidCheckDefinition = {
|
|
|
18
18
|
},
|
|
19
19
|
|
|
20
20
|
create(context) {
|
|
21
|
-
if (!context.
|
|
21
|
+
if (!context.platformosDocset) {
|
|
22
22
|
return {};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// To avoid recalculating valid param types during
|
|
25
|
+
// To avoid recalculating valid param types during platformos-check, constructing
|
|
26
26
|
// the promise beforehand.
|
|
27
27
|
const validParamTypesPromise = context
|
|
28
|
-
.
|
|
28
|
+
.platformosDocset!.liquidDrops()
|
|
29
29
|
.then((entries) => new Set(getValidParamTypes(entries).keys()));
|
|
30
30
|
|
|
31
31
|
return {
|
|
@@ -1,73 +1,83 @@
|
|
|
1
1
|
import { ValidHTMLTranslation } from './index';
|
|
2
|
-
import { highlightedOffenses,
|
|
2
|
+
import { highlightedOffenses, runYAMLCheck } from '../../test';
|
|
3
3
|
import { expect, describe, it } from 'vitest';
|
|
4
4
|
|
|
5
5
|
describe('Module: ValidHTMLTranslation', () => {
|
|
6
6
|
it('should not report valid HTML in translations', async () => {
|
|
7
|
-
const sourceCode =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const sourceCode = [
|
|
8
|
+
'en:',
|
|
9
|
+
' hello_html: "<h1>Hello, world</h1>"',
|
|
10
|
+
' image_html: "<img src=\'spongebob.png\'>"',
|
|
11
|
+
' line_break_html: "<br>"',
|
|
12
|
+
' self_closing_svg_html: "<svg />"',
|
|
13
|
+
' foo: bar',
|
|
14
|
+
].join('\n');
|
|
14
15
|
|
|
15
|
-
const offenses = await
|
|
16
|
+
const offenses = await runYAMLCheck(
|
|
17
|
+
ValidHTMLTranslation,
|
|
18
|
+
sourceCode,
|
|
19
|
+
'app/translations/en.yml',
|
|
20
|
+
);
|
|
16
21
|
expect(offenses).toHaveLength(0);
|
|
17
22
|
});
|
|
18
23
|
|
|
19
24
|
it('should report invalid HTML in translations', async () => {
|
|
20
|
-
const sourceCode =
|
|
21
|
-
hello_html: '<h1>Hello, world',
|
|
22
|
-
});
|
|
25
|
+
const sourceCode = 'en:\n hello_html: "<h1>Hello, world"';
|
|
23
26
|
|
|
24
|
-
const offenses = await
|
|
27
|
+
const offenses = await runYAMLCheck(
|
|
28
|
+
ValidHTMLTranslation,
|
|
29
|
+
sourceCode,
|
|
30
|
+
'app/translations/en.yml',
|
|
31
|
+
);
|
|
25
32
|
expect(offenses).toHaveLength(1);
|
|
26
33
|
expect(offenses[0].message).to.equal(
|
|
27
34
|
"LiquidHTMLParsingError: Attempting to end parsing before HtmlElement 'h1' was closed.",
|
|
28
35
|
);
|
|
29
36
|
|
|
30
|
-
const highlights = highlightedOffenses({ '
|
|
37
|
+
const highlights = highlightedOffenses({ 'app/translations/en.yml': sourceCode }, offenses);
|
|
31
38
|
expect(highlights).toHaveLength(1);
|
|
32
39
|
expect(highlights[0]).to.equal(`"<h1>Hello, world"`);
|
|
33
40
|
});
|
|
34
41
|
|
|
35
42
|
it('should report nested invalid HTML in translations', async () => {
|
|
36
|
-
const sourceCode =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
});
|
|
43
|
+
const sourceCode = [
|
|
44
|
+
'en:',
|
|
45
|
+
' hello:',
|
|
46
|
+
' world:',
|
|
47
|
+
' today:',
|
|
48
|
+
' good:',
|
|
49
|
+
' day_html: "<h1>Hello, world"',
|
|
50
|
+
].join('\n');
|
|
47
51
|
|
|
48
|
-
const offenses = await
|
|
52
|
+
const offenses = await runYAMLCheck(
|
|
53
|
+
ValidHTMLTranslation,
|
|
54
|
+
sourceCode,
|
|
55
|
+
'app/translations/en.yml',
|
|
56
|
+
);
|
|
49
57
|
expect(offenses).toHaveLength(1);
|
|
50
58
|
expect(offenses[0].message).to.equal(
|
|
51
59
|
"LiquidHTMLParsingError: Attempting to end parsing before HtmlElement 'h1' was closed.",
|
|
52
60
|
);
|
|
53
61
|
|
|
54
|
-
const highlights = highlightedOffenses({ '
|
|
62
|
+
const highlights = highlightedOffenses({ 'app/translations/en.yml': sourceCode }, offenses);
|
|
55
63
|
expect(highlights).toHaveLength(1);
|
|
56
64
|
expect(highlights[0]).to.equal(`"<h1>Hello, world"`);
|
|
57
65
|
});
|
|
58
66
|
|
|
59
67
|
it('should report pluralized key with invalid HTML', async () => {
|
|
60
|
-
const sourceCode =
|
|
61
|
-
hello_html: { one: '<h1>Hello, world' },
|
|
62
|
-
});
|
|
68
|
+
const sourceCode = 'en:\n hello_html:\n one: "<h1>Hello, world"';
|
|
63
69
|
|
|
64
|
-
const offenses = await
|
|
70
|
+
const offenses = await runYAMLCheck(
|
|
71
|
+
ValidHTMLTranslation,
|
|
72
|
+
sourceCode,
|
|
73
|
+
'app/translations/en.yml',
|
|
74
|
+
);
|
|
65
75
|
expect(offenses).toHaveLength(1);
|
|
66
76
|
expect(offenses[0].message).to.equal(
|
|
67
77
|
"LiquidHTMLParsingError: Attempting to end parsing before HtmlElement 'h1' was closed.",
|
|
68
78
|
);
|
|
69
79
|
|
|
70
|
-
const highlights = highlightedOffenses({ '
|
|
80
|
+
const highlights = highlightedOffenses({ 'app/translations/en.yml': sourceCode }, offenses);
|
|
71
81
|
expect(highlights).toHaveLength(1);
|
|
72
82
|
expect(highlights[0]).to.equal(`"<h1>Hello, world"`);
|
|
73
83
|
});
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { SourceCodeType,
|
|
1
|
+
import { SourceCodeType, YAMLCheckDefinition, Severity, Problem, LiteralNode } from '../../types';
|
|
2
2
|
import { toLiquidHtmlAST } from '@platformos/liquid-html-parser';
|
|
3
3
|
|
|
4
|
-
export const ValidHTMLTranslation:
|
|
4
|
+
export const ValidHTMLTranslation: YAMLCheckDefinition = {
|
|
5
5
|
meta: {
|
|
6
6
|
code: 'ValidHTMLTranslation',
|
|
7
7
|
name: 'Valid HTML Translation',
|
|
8
8
|
docs: {
|
|
9
9
|
description: 'This check exists to prevent invalid HTML inside translations.',
|
|
10
|
-
url: 'https://
|
|
10
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/valid-html-translation',
|
|
11
11
|
recommended: true,
|
|
12
12
|
},
|
|
13
|
-
type: SourceCodeType.
|
|
13
|
+
type: SourceCodeType.YAML,
|
|
14
14
|
severity: Severity.WARNING,
|
|
15
15
|
schema: {},
|
|
16
16
|
targets: [],
|
|
17
17
|
},
|
|
18
18
|
|
|
19
19
|
create(context) {
|
|
20
|
-
// We ignore
|
|
20
|
+
// We ignore yaml files that aren't translation files.
|
|
21
21
|
const relativePath = context.toRelativePath(context.file.uri);
|
|
22
|
-
if (!relativePath.
|
|
22
|
+
if (!relativePath.includes('/translations/')) return {};
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
async Literal(node: LiteralNode) {
|
|
@@ -32,7 +32,7 @@ export const ValidHTMLTranslation: JSONCheckDefinition = {
|
|
|
32
32
|
} catch (error) {
|
|
33
33
|
const loc = node.loc;
|
|
34
34
|
|
|
35
|
-
const problem: Problem<SourceCodeType.
|
|
35
|
+
const problem: Problem<SourceCodeType.YAML> = {
|
|
36
36
|
message: `${error}.`,
|
|
37
37
|
startIndex: loc.start.offset,
|
|
38
38
|
endIndex: loc.end.offset,
|
|
@@ -9,7 +9,7 @@ export const ValidJSON: JSONCheckDefinition = {
|
|
|
9
9
|
description:
|
|
10
10
|
'This check exists to prevent invalid JSON files in themes. Will check against schema if available.',
|
|
11
11
|
recommended: true,
|
|
12
|
-
url: 'https://
|
|
12
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/json-syntax-error',
|
|
13
13
|
},
|
|
14
14
|
type: SourceCodeType.JSON,
|
|
15
15
|
severity: Severity.ERROR,
|
|
@@ -19,7 +19,7 @@ export const ValidRenderPartialArgumentTypes: LiquidCheckDefinition = {
|
|
|
19
19
|
description:
|
|
20
20
|
'This check ensures that arguments passed to partial match the expected types defined in the liquidDoc header if present.',
|
|
21
21
|
recommended: true,
|
|
22
|
-
url: 'https://
|
|
22
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/valid-render-partial-argument-types',
|
|
23
23
|
},
|
|
24
24
|
type: SourceCodeType.LiquidHtml,
|
|
25
25
|
severity: Severity.WARNING,
|
|
@@ -72,10 +72,7 @@ export const ValidRenderPartialArgumentTypes: LiquidCheckDefinition = {
|
|
|
72
72
|
|
|
73
73
|
if (!partialName) return;
|
|
74
74
|
|
|
75
|
-
const liquidDocParameters = await getLiquidDocParams(
|
|
76
|
-
context,
|
|
77
|
-
`app/views/partials/${partialName}.liquid`,
|
|
78
|
-
);
|
|
75
|
+
const liquidDocParameters = await getLiquidDocParams(context, partialName);
|
|
79
76
|
|
|
80
77
|
if (!liquidDocParameters) return;
|
|
81
78
|
|
|
@@ -48,7 +48,7 @@ export const VariableName: LiquidCheckDefinition<typeof schema> = {
|
|
|
48
48
|
name: 'Invalid variable naming format',
|
|
49
49
|
docs: {
|
|
50
50
|
description: 'This check is aimed at using certain variable naming conventions',
|
|
51
|
-
url: 'https://
|
|
51
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/variable-name',
|
|
52
52
|
recommended: true,
|
|
53
53
|
},
|
|
54
54
|
type: SourceCodeType.LiquidHtml,
|