@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
|
@@ -1,103 +1,75 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
makeGetDefaultLocale,
|
|
4
|
-
makeGetDefaultTranslations,
|
|
5
|
-
makeGetMetafieldDefinitions,
|
|
6
|
-
} from './context-utils';
|
|
2
|
+
import { makeGetDefaultLocale, makeGetDefaultTranslations } from './context-utils';
|
|
7
3
|
import { MockFileSystem } from './test';
|
|
8
4
|
import { AbstractFileSystem } from '@platformos/platformos-common';
|
|
9
5
|
|
|
10
6
|
describe('Unit: getDefaultLocale', () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
fs = new MockFileSystem(
|
|
7
|
+
it('should always return en (en.yml is the reference locale file)', async () => {
|
|
8
|
+
const fs: AbstractFileSystem = new MockFileSystem(
|
|
14
9
|
{
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'gitRootTheme/snippet/foo.liquid': JSON.stringify({ beverage: 'coffee' }),
|
|
18
|
-
'frenchDefault/locales/fr.default.json': JSON.stringify({ beverage: 'café' }),
|
|
19
|
-
'frenchDefault/snippet/foo.liquid': JSON.stringify({ beverage: 'coffee' }),
|
|
20
|
-
'.shopify/metafields.json': JSON.stringify({
|
|
21
|
-
product: [
|
|
22
|
-
{
|
|
23
|
-
key: 'color',
|
|
24
|
-
name: 'color',
|
|
25
|
-
namespace: 'custom',
|
|
26
|
-
description: 'the color of the product',
|
|
27
|
-
type: {
|
|
28
|
-
category: 'COLOR',
|
|
29
|
-
name: 'color',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
}),
|
|
10
|
+
'app/translations/en.yml': 'en:\n beverage: coffee\n',
|
|
11
|
+
'app/translations/fr.yml': 'fr:\n beverage: café\n',
|
|
34
12
|
},
|
|
35
|
-
'
|
|
13
|
+
'platformos-vfs:/',
|
|
36
14
|
);
|
|
37
|
-
});
|
|
38
15
|
|
|
39
|
-
|
|
40
|
-
let getDefaultLocale = makeGetDefaultLocale(fs, 'shopify-vfs:/gitRootTheme');
|
|
16
|
+
const getDefaultLocale = makeGetDefaultLocale(fs, 'platformos-vfs:/');
|
|
41
17
|
expect(await getDefaultLocale()).to.eql('en');
|
|
42
|
-
|
|
43
|
-
getDefaultLocale = makeGetDefaultLocale(fs, 'shopify-vfs:/frenchDefault');
|
|
44
|
-
expect(await getDefaultLocale()).to.eql('fr');
|
|
45
18
|
});
|
|
46
19
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
20
|
+
it('should return en even when no translation files exist', async () => {
|
|
21
|
+
const fs: AbstractFileSystem = new MockFileSystem({}, 'platformos-vfs:/');
|
|
22
|
+
const getDefaultLocale = makeGetDefaultLocale(fs, 'platformos-vfs:/');
|
|
23
|
+
expect(await getDefaultLocale()).to.eql('en');
|
|
24
|
+
});
|
|
52
25
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
type: {
|
|
60
|
-
category: 'COLOR',
|
|
61
|
-
name: 'color',
|
|
26
|
+
describe('Unit: getDefaultTranslationsFactory', () => {
|
|
27
|
+
it('should return translations from en.yml stripped of the locale prefix', async () => {
|
|
28
|
+
const fs: AbstractFileSystem = new MockFileSystem(
|
|
29
|
+
{
|
|
30
|
+
'app/translations/en.yml': 'en:\n beverage: coffee\n',
|
|
31
|
+
'app/translations/fr.yml': 'fr:\n beverage: café\n',
|
|
62
32
|
},
|
|
63
|
-
|
|
33
|
+
'platformos-vfs:/',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const getDefaultTranslations = makeGetDefaultTranslations(fs, [], 'platformos-vfs:/');
|
|
37
|
+
expect(await getDefaultTranslations()).to.eql({ beverage: 'coffee' });
|
|
64
38
|
});
|
|
65
39
|
|
|
66
|
-
it(
|
|
67
|
-
fs = new MockFileSystem(
|
|
40
|
+
it('should return empty object when no en.yml exists', async () => {
|
|
41
|
+
const fs: AbstractFileSystem = new MockFileSystem(
|
|
68
42
|
{
|
|
69
|
-
'
|
|
43
|
+
'app/translations/fr.yml': 'fr:\n beverage: café\n',
|
|
70
44
|
},
|
|
71
|
-
'
|
|
45
|
+
'platformos-vfs:/',
|
|
72
46
|
);
|
|
73
|
-
const getMetafieldDefinitions = makeGetMetafieldDefinitions(fs);
|
|
74
47
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
expect(definitions).deep.equals({
|
|
78
|
-
article: [],
|
|
79
|
-
blog: [],
|
|
80
|
-
collection: [],
|
|
81
|
-
company: [],
|
|
82
|
-
company_location: [],
|
|
83
|
-
location: [],
|
|
84
|
-
market: [],
|
|
85
|
-
order: [],
|
|
86
|
-
page: [],
|
|
87
|
-
product: [],
|
|
88
|
-
variant: [],
|
|
89
|
-
shop: [],
|
|
90
|
-
});
|
|
48
|
+
const getDefaultTranslations = makeGetDefaultTranslations(fs, [], 'platformos-vfs:/');
|
|
49
|
+
expect(await getDefaultTranslations()).to.eql({});
|
|
91
50
|
});
|
|
92
|
-
});
|
|
93
51
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
52
|
+
it('should prefer translations from the in-memory app buffer over the filesystem', async () => {
|
|
53
|
+
const fs: AbstractFileSystem = new MockFileSystem(
|
|
54
|
+
{
|
|
55
|
+
'app/translations/en.yml': 'en:\n beverage: coffee\n',
|
|
56
|
+
},
|
|
57
|
+
'platformos-vfs:/',
|
|
58
|
+
);
|
|
98
59
|
|
|
99
|
-
|
|
100
|
-
|
|
60
|
+
// Simulate an open buffer with different content
|
|
61
|
+
const { toSourceCode } = await import('./to-source-code');
|
|
62
|
+
const bufferedSourceCode = toSourceCode(
|
|
63
|
+
'platformos-vfs:/app/translations/en.yml',
|
|
64
|
+
'en:\n beverage: tea\n',
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const getDefaultTranslations = makeGetDefaultTranslations(
|
|
68
|
+
fs,
|
|
69
|
+
[bufferedSourceCode],
|
|
70
|
+
'platformos-vfs:/',
|
|
71
|
+
);
|
|
72
|
+
expect(await getDefaultTranslations()).to.eql({ beverage: 'tea' });
|
|
101
73
|
});
|
|
102
74
|
});
|
|
103
75
|
});
|
package/src/context-utils.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { load } from 'js-yaml';
|
|
2
2
|
import { AbstractFileSystem, FileTuple, FileType, UriString } from '@platformos/platformos-common';
|
|
3
|
-
import { parseJSON } from './json';
|
|
4
3
|
import { join } from './path';
|
|
5
|
-
import {
|
|
6
|
-
MetafieldCategory,
|
|
7
|
-
MetafieldDefinitionMap,
|
|
8
|
-
SourceCodeType,
|
|
9
|
-
Theme,
|
|
10
|
-
Translations,
|
|
11
|
-
} from './types';
|
|
12
|
-
import { isError } from './utils';
|
|
4
|
+
import { SourceCodeType, App, Translations } from './types';
|
|
13
5
|
|
|
14
6
|
export type FileExists = (uri: string) => Promise<boolean>;
|
|
15
7
|
|
|
@@ -33,71 +25,49 @@ export const makeFileSize = (fs: AbstractFileSystem) =>
|
|
|
33
25
|
}
|
|
34
26
|
};
|
|
35
27
|
|
|
36
|
-
export const makeGetDefaultLocaleFileUri =
|
|
37
|
-
|
|
38
|
-
getDefaultLocaleFileUriFactoryFactory('.default.schema.json');
|
|
39
|
-
function getDefaultLocaleFileUriFactoryFactory(postfix = '.default.json') {
|
|
40
|
-
return function getDefaultLocaleFileUriFactory(fs: AbstractFileSystem) {
|
|
41
|
-
return (rootUri: string) => getDefaultLocaleFile(fs, rootUri, postfix);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
28
|
+
export const makeGetDefaultLocaleFileUri = (fs: AbstractFileSystem) => (rootUri: string) =>
|
|
29
|
+
getDefaultLocaleFile(fs, rootUri);
|
|
44
30
|
|
|
45
|
-
export const makeGetDefaultLocale =
|
|
46
|
-
|
|
47
|
-
function getDefaultLocaleFactoryFactory(postfix = '.default.json') {
|
|
48
|
-
return function getDefaultLocaleFactory(fs: AbstractFileSystem, rootUri: string) {
|
|
49
|
-
return cached(() => getDefaultLocale(fs, rootUri, postfix));
|
|
50
|
-
};
|
|
51
|
-
}
|
|
31
|
+
export const makeGetDefaultLocale = (fs: AbstractFileSystem, rootUri: string) =>
|
|
32
|
+
cached(() => getDefaultLocale(fs, rootUri));
|
|
52
33
|
|
|
53
|
-
export const makeGetDefaultTranslations =
|
|
54
|
-
|
|
55
|
-
getDefaultTranslationsFactoryFactory('.default.schema.json');
|
|
56
|
-
// prettier-ignore
|
|
57
|
-
function getDefaultTranslationsFactoryFactory(postfix = '.default.json') {
|
|
58
|
-
return function getDefaultTranslationsFactory(fs: AbstractFileSystem, theme: Theme, rootUri: string) {
|
|
59
|
-
return cached(() => getDefaultTranslations(fs, theme, rootUri, postfix));
|
|
60
|
-
};
|
|
61
|
-
}
|
|
34
|
+
export const makeGetDefaultTranslations = (fs: AbstractFileSystem, app: App, rootUri: string) =>
|
|
35
|
+
cached(() => getDefaultTranslations(fs, app, rootUri));
|
|
62
36
|
|
|
63
37
|
async function getDefaultLocaleFile(
|
|
64
38
|
fs: AbstractFileSystem,
|
|
65
39
|
rootUri: string,
|
|
66
|
-
|
|
67
|
-
)
|
|
68
|
-
const files = await fs.readDirectory(join(rootUri, 'locales'));
|
|
69
|
-
return files.find(([uri]) => uri.endsWith(postfix))?.[0];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function getDefaultLocale(
|
|
73
|
-
fs: AbstractFileSystem,
|
|
74
|
-
rootUri: string,
|
|
75
|
-
postfix: string,
|
|
76
|
-
): Promise<string> {
|
|
40
|
+
): Promise<string | undefined> {
|
|
41
|
+
const enYmlUri = join(rootUri, 'app/translations/en.yml');
|
|
77
42
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error(error);
|
|
84
|
-
return 'en';
|
|
43
|
+
await fs.stat(enYmlUri);
|
|
44
|
+
return enYmlUri;
|
|
45
|
+
} catch {
|
|
46
|
+
return undefined;
|
|
85
47
|
}
|
|
86
48
|
}
|
|
87
49
|
|
|
50
|
+
async function getDefaultLocale(_fs: AbstractFileSystem, _rootUri: string): Promise<string> {
|
|
51
|
+
// In platformOS, en.yml is always the reference translation file
|
|
52
|
+
return 'en';
|
|
53
|
+
}
|
|
54
|
+
|
|
88
55
|
async function getDefaultTranslations(
|
|
89
56
|
fs: AbstractFileSystem,
|
|
90
|
-
|
|
57
|
+
app: App,
|
|
91
58
|
rootUri: string,
|
|
92
|
-
postfix: string,
|
|
93
59
|
): Promise<Translations> {
|
|
94
60
|
try {
|
|
95
|
-
const bufferTranslations = getDefaultTranslationsFromBuffer(
|
|
61
|
+
const bufferTranslations = getDefaultTranslationsFromBuffer(app);
|
|
96
62
|
if (bufferTranslations) return bufferTranslations;
|
|
97
|
-
const defaultLocaleFile = await getDefaultLocaleFile(fs, rootUri
|
|
63
|
+
const defaultLocaleFile = await getDefaultLocaleFile(fs, rootUri);
|
|
98
64
|
if (!defaultLocaleFile) return {};
|
|
99
|
-
const
|
|
100
|
-
|
|
65
|
+
const yamlContent = await fs.readFile(defaultLocaleFile);
|
|
66
|
+
const data = load(yamlContent) as Record<string, any>;
|
|
67
|
+
if (!data || typeof data !== 'object') return {};
|
|
68
|
+
// YAML translation files wrap content under the locale key: { en: { hello: 'Hello' } }
|
|
69
|
+
const localeKey = Object.keys(data)[0];
|
|
70
|
+
return (localeKey && data[localeKey]) ?? {};
|
|
101
71
|
} catch (error) {
|
|
102
72
|
console.error(error);
|
|
103
73
|
return {};
|
|
@@ -105,17 +75,19 @@ async function getDefaultTranslations(
|
|
|
105
75
|
}
|
|
106
76
|
|
|
107
77
|
/** It might be that you have an open buffer, we prefer translations from there if available */
|
|
108
|
-
function getDefaultTranslationsFromBuffer(
|
|
109
|
-
const defaultTranslationsSourceCode =
|
|
110
|
-
(sourceCode) =>
|
|
111
|
-
sourceCode.type === SourceCodeType.JSON &&
|
|
112
|
-
sourceCode.uri.match(/locales/) &&
|
|
113
|
-
sourceCode.uri.endsWith(postfix),
|
|
78
|
+
function getDefaultTranslationsFromBuffer(app: App): Translations | undefined {
|
|
79
|
+
const defaultTranslationsSourceCode = app.find(
|
|
80
|
+
(sourceCode) => sourceCode.type === SourceCodeType.YAML && sourceCode.uri.endsWith('/en.yml'),
|
|
114
81
|
);
|
|
115
82
|
if (!defaultTranslationsSourceCode) return undefined;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
83
|
+
try {
|
|
84
|
+
const data = load(defaultTranslationsSourceCode.source) as Record<string, any>;
|
|
85
|
+
if (!data || typeof data !== 'object') return undefined;
|
|
86
|
+
const localeKey = Object.keys(data)[0];
|
|
87
|
+
return (localeKey && data[localeKey]) ?? undefined;
|
|
88
|
+
} catch {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
119
91
|
}
|
|
120
92
|
|
|
121
93
|
function cached<T>(fn: () => Promise<T>): () => Promise<T>;
|
|
@@ -157,64 +129,3 @@ const ignoredFolders = ['.git', 'node_modules', 'dist', 'build', 'tmp', 'vendor'
|
|
|
157
129
|
function isIgnored([uri, type]: FileTuple) {
|
|
158
130
|
return type === FileType.Directory && ignoredFolders.some((folder) => uri.endsWith(folder));
|
|
159
131
|
}
|
|
160
|
-
|
|
161
|
-
export const FETCHED_METAFIELD_CATEGORIES: MetafieldCategory[] = [
|
|
162
|
-
'article',
|
|
163
|
-
'blog',
|
|
164
|
-
'collection',
|
|
165
|
-
'company',
|
|
166
|
-
'company_location',
|
|
167
|
-
'location',
|
|
168
|
-
'market',
|
|
169
|
-
'order',
|
|
170
|
-
'page',
|
|
171
|
-
'product',
|
|
172
|
-
'variant',
|
|
173
|
-
'shop',
|
|
174
|
-
];
|
|
175
|
-
|
|
176
|
-
export const makeGetMetafieldDefinitions = (fs: AbstractFileSystem) =>
|
|
177
|
-
async function (rootUri: string): Promise<MetafieldDefinitionMap> {
|
|
178
|
-
const definitions = {
|
|
179
|
-
article: [],
|
|
180
|
-
blog: [],
|
|
181
|
-
collection: [],
|
|
182
|
-
company: [],
|
|
183
|
-
company_location: [],
|
|
184
|
-
location: [],
|
|
185
|
-
market: [],
|
|
186
|
-
order: [],
|
|
187
|
-
page: [],
|
|
188
|
-
product: [],
|
|
189
|
-
variant: [],
|
|
190
|
-
shop: [],
|
|
191
|
-
} as MetafieldDefinitionMap;
|
|
192
|
-
|
|
193
|
-
try {
|
|
194
|
-
const content = await fs.readFile(join(rootUri, '.shopify', 'metafields.json'));
|
|
195
|
-
const json = parseJSON(content);
|
|
196
|
-
|
|
197
|
-
if (isError(json)) return definitions;
|
|
198
|
-
|
|
199
|
-
return FETCHED_METAFIELD_CATEGORIES.reduce((definitions, group) => {
|
|
200
|
-
try {
|
|
201
|
-
definitions[group] = json[group].map((definition: any) => ({
|
|
202
|
-
key: definition.key,
|
|
203
|
-
name: definition.name,
|
|
204
|
-
namespace: definition.namespace,
|
|
205
|
-
description: definition.description,
|
|
206
|
-
type: {
|
|
207
|
-
category: definition.type.category,
|
|
208
|
-
name: definition.type.name,
|
|
209
|
-
},
|
|
210
|
-
}));
|
|
211
|
-
} catch (error) {
|
|
212
|
-
// If there are errors in the file, we ignore it
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return definitions;
|
|
216
|
-
}, definitions);
|
|
217
|
-
} catch (err) {
|
|
218
|
-
return definitions;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
@@ -259,4 +259,39 @@ ${buildComment('theme-check-enable')}
|
|
|
259
259
|
});
|
|
260
260
|
});
|
|
261
261
|
});
|
|
262
|
+
|
|
263
|
+
describe('platformos-check prefix', () => {
|
|
264
|
+
it('should disable checks using platformos-check-disable prefix', async () => {
|
|
265
|
+
for (const buildComment of commentTypes) {
|
|
266
|
+
const file = `${buildComment('platformos-check-disable LiquidFilter')}
|
|
267
|
+
{{ 'asset' | random_filter }}
|
|
268
|
+
{% render 'something' %}`;
|
|
269
|
+
|
|
270
|
+
const offenses = await check({ 'code.liquid': file }, checks);
|
|
271
|
+
expect(offenses).to.have.length(1);
|
|
272
|
+
expectRenderMarkupOffense(offenses, 'something.liquid');
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('should disable all checks using platformos-check-disable prefix', async () => {
|
|
277
|
+
for (const buildComment of commentTypes) {
|
|
278
|
+
const file = `${buildComment('platformos-check-disable')}
|
|
279
|
+
{{ 'asset' | random_filter }}
|
|
280
|
+
{% render 'something' %}`;
|
|
281
|
+
|
|
282
|
+
const offenses = await check({ 'code.liquid': file }, checks);
|
|
283
|
+
expect(offenses).to.have.length(0);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('should disable next line using platformos-check-disable-next-line prefix', async () => {
|
|
288
|
+
const file = `{% # platformos-check-disable-next-line %}
|
|
289
|
+
{% render 'something' %}
|
|
290
|
+
{% render 'other-thing' %}`;
|
|
291
|
+
|
|
292
|
+
const offenses = await check({ 'code.liquid': file }, checks);
|
|
293
|
+
expect(offenses).to.have.length(1);
|
|
294
|
+
expectRenderMarkupOffense(offenses, 'other-thing.liquid');
|
|
295
|
+
});
|
|
296
|
+
});
|
|
262
297
|
});
|
|
@@ -24,7 +24,9 @@ export function createDisabledChecksModule() {
|
|
|
24
24
|
node: LiquidTag | LiquidRawTag,
|
|
25
25
|
) {
|
|
26
26
|
const [_, command, checksJoined] =
|
|
27
|
-
value
|
|
27
|
+
value
|
|
28
|
+
.trim()
|
|
29
|
+
.match(/^(?:(?:platformos|theme)\-check\-(disable-next-line|disable|enable)) ?(.*)/) || [];
|
|
28
30
|
|
|
29
31
|
const checks = checksJoined ? checksJoined.split(/,[ ]*/) : [SPECIFIC_CHECK_NOT_DEFINED];
|
|
30
32
|
|
|
@@ -133,7 +135,7 @@ export function findNextLinePosition(
|
|
|
133
135
|
* E.g. The following disables check for `elsif` tag
|
|
134
136
|
*
|
|
135
137
|
* {% if condition %}
|
|
136
|
-
* {% #
|
|
138
|
+
* {% #platformos-check-disable-next-line %}
|
|
137
139
|
* {% elsif other_condition %}
|
|
138
140
|
* {{ prouduct }}
|
|
139
141
|
* {% endif %}
|
package/src/find-root.ts
CHANGED
|
@@ -5,13 +5,11 @@ type FileExists = (uri: string) => Promise<boolean>;
|
|
|
5
5
|
|
|
6
6
|
async function isRoot(dir: UriString, fileExists: FileExists) {
|
|
7
7
|
return or(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
fileExists(path.join(dir, '.git')),
|
|
14
|
-
),
|
|
8
|
+
fileExists(path.join(dir, '.pos')),
|
|
9
|
+
fileExists(path.join(dir, '.platformos-check.yml')),
|
|
10
|
+
fileExists(path.join(dir, 'app')),
|
|
11
|
+
// modules/ is a root indicator only when not inside app/ (app/modules/ is a valid subdirectory)
|
|
12
|
+
and(fileExists(path.join(dir, 'modules')), Promise.resolve(path.basename(dir) !== 'app')),
|
|
15
13
|
);
|
|
16
14
|
}
|
|
17
15
|
|
|
@@ -25,24 +23,16 @@ async function or(...promises: Promise<boolean>[]) {
|
|
|
25
23
|
return bools.reduce((a, b) => a || b, false);
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
async function not(ap: Promise<boolean>) {
|
|
29
|
-
const a = await ap;
|
|
30
|
-
return !a;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
/**
|
|
34
|
-
* Returns the
|
|
35
|
-
*
|
|
36
|
-
* `
|
|
37
|
-
*
|
|
38
|
-
* There are cases where .theme-check.yml is not defined and we have to infer the root.
|
|
39
|
-
* We'll assume that the root is the directory that contains a `snippets` directory.
|
|
27
|
+
* Returns the root of a platformOS app. The root is the directory that contains
|
|
28
|
+
* a `.pos` sentinel file, a `.platformos-check.yml` config file, an `app/` directory,
|
|
29
|
+
* or a `modules/` directory (when not inside `app/`).
|
|
40
30
|
*
|
|
41
|
-
*
|
|
42
|
-
* should be.
|
|
31
|
+
* Note: `modules/` inside `app/` (i.e. `app/modules/`) is a valid subdirectory and
|
|
32
|
+
* should not be treated as a root indicator.
|
|
43
33
|
*
|
|
44
|
-
* Note:
|
|
45
|
-
*
|
|
34
|
+
* Note: this is not the app root itself. The config file might have a `root` entry that
|
|
35
|
+
* points to somewhere else.
|
|
46
36
|
*/
|
|
47
37
|
export async function findRoot(curr: UriString, fileExists: FileExists): Promise<UriString | null> {
|
|
48
38
|
const currIsRoot = await isRoot(curr, fileExists);
|
|
@@ -4,7 +4,7 @@ import { Offense, SourceCodeType } from '../types';
|
|
|
4
4
|
|
|
5
5
|
describe('Module: autofix', () => {
|
|
6
6
|
it('should apply a list of all safe changes', async () => {
|
|
7
|
-
const
|
|
7
|
+
const mockApp = {
|
|
8
8
|
'a.liquid': 'Banana world',
|
|
9
9
|
'b.json': prettyJSON({ a: 'b' }),
|
|
10
10
|
};
|
|
@@ -69,7 +69,7 @@ describe('Module: autofix', () => {
|
|
|
69
69
|
},
|
|
70
70
|
];
|
|
71
71
|
|
|
72
|
-
const fixed = await autofix(
|
|
72
|
+
const fixed = await autofix(mockApp, offenses);
|
|
73
73
|
expect(fixed['a.liquid']).to.eql('Bananananana world');
|
|
74
74
|
expect(fixed['b.json']).to.eql(
|
|
75
75
|
prettyJSON({
|
package/src/fixes/autofix.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FixApplicator, Offense, SourceCodeType,
|
|
1
|
+
import { FixApplicator, Offense, SourceCodeType, App } from '../types';
|
|
2
2
|
import { WithRequired } from '../utils/types';
|
|
3
3
|
import { createCorrector } from './correctors';
|
|
4
4
|
import { flattenFixes } from './utils';
|
|
@@ -8,13 +8,13 @@ type FixableOffense<S extends SourceCodeType> = S extends SourceCodeType
|
|
|
8
8
|
: never;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Takes
|
|
12
|
-
* safe ones on the
|
|
11
|
+
* Takes an app, list of offenses and a fixApplicator and runs all the
|
|
12
|
+
* safe ones on the app.
|
|
13
13
|
*
|
|
14
14
|
* Note that offense.fix is assumed to be safe, unlike offense.suggest
|
|
15
15
|
* options.
|
|
16
16
|
*/
|
|
17
|
-
export async function autofix(sourceCodes:
|
|
17
|
+
export async function autofix(sourceCodes: App, offenses: Offense[], applyFixes: FixApplicator) {
|
|
18
18
|
const fixableOffenses = offenses.filter(
|
|
19
19
|
(offense): offense is FixableOffense<SourceCodeType> => 'fix' in offense && !!offense.fix,
|
|
20
20
|
);
|
|
@@ -18,6 +18,10 @@ export function createCorrector<S extends SourceCodeType>(
|
|
|
18
18
|
}
|
|
19
19
|
case SourceCodeType.GraphQL:
|
|
20
20
|
return new GraphQLCorrector(source) as Corrector<typeof sourceCodeType>;
|
|
21
|
+
case SourceCodeType.YAML: {
|
|
22
|
+
// YAML autofix is not yet supported; this case should not be reached
|
|
23
|
+
throw new Error('YAML autofix is not supported');
|
|
24
|
+
}
|
|
21
25
|
default: {
|
|
22
26
|
return assertNever(sourceCodeType);
|
|
23
27
|
}
|