@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,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
YAMLCheckDefinition,
|
|
3
3
|
JSONNode,
|
|
4
|
-
|
|
4
|
+
YAMLSourceCode,
|
|
5
5
|
Severity,
|
|
6
6
|
SourceCodeType,
|
|
7
7
|
PropertyNode,
|
|
@@ -9,16 +9,16 @@ import {
|
|
|
9
9
|
|
|
10
10
|
const PLURALIZATION_KEYS = new Set(['zero', 'one', 'two', 'few', 'many', 'other']);
|
|
11
11
|
|
|
12
|
-
export const MatchingTranslations:
|
|
12
|
+
export const MatchingTranslations: YAMLCheckDefinition = {
|
|
13
13
|
meta: {
|
|
14
14
|
code: 'MatchingTranslations',
|
|
15
15
|
name: 'Translation files should have the same keys',
|
|
16
16
|
docs: {
|
|
17
17
|
description: 'TODO',
|
|
18
18
|
recommended: true,
|
|
19
|
-
url: 'https://
|
|
19
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/matching-translations',
|
|
20
20
|
},
|
|
21
|
-
type: SourceCodeType.
|
|
21
|
+
type: SourceCodeType.YAML,
|
|
22
22
|
severity: Severity.ERROR,
|
|
23
23
|
schema: {},
|
|
24
24
|
targets: [],
|
|
@@ -29,18 +29,17 @@ export const MatchingTranslations: JSONCheckDefinition = {
|
|
|
29
29
|
const defaultTranslations = new Set<string>();
|
|
30
30
|
const missingTranslations = new Set<string>();
|
|
31
31
|
const nodesByPath = new Map<string, PropertyNode>();
|
|
32
|
-
const file = context.file;
|
|
32
|
+
const file = context.file as YAMLSourceCode;
|
|
33
33
|
const fileUri = file.uri;
|
|
34
34
|
const relativePath = context.toRelativePath(fileUri);
|
|
35
35
|
const ast = file.ast;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
if (!
|
|
42
|
-
// No need to lint a file that isn't a translation file
|
|
43
|
-
// empty object as the check for those.
|
|
36
|
+
const isTranslationFile = relativePath.includes('/translations/');
|
|
37
|
+
// In platformOS, en.yml is the reference locale; skip running the check on it
|
|
38
|
+
const basename = fileUri.split('/').pop() ?? '';
|
|
39
|
+
const isDefaultTranslationsFile = basename.replace(/\.ya?ml$/, '') === 'en';
|
|
40
|
+
|
|
41
|
+
if (!isTranslationFile || isDefaultTranslationsFile || ast instanceof Error) {
|
|
42
|
+
// No need to lint a file that isn't a non-default translation file
|
|
44
43
|
return {};
|
|
45
44
|
}
|
|
46
45
|
|
|
@@ -48,7 +47,6 @@ export const MatchingTranslations: JSONCheckDefinition = {
|
|
|
48
47
|
const hasDefaultTranslations = () => defaultTranslations.size > 0;
|
|
49
48
|
const isTerminalNode = ({ type }: JSONNode) => type === 'Literal';
|
|
50
49
|
const isPluralizationNode = (node: PropertyNode) => PLURALIZATION_KEYS.has(node.key.value);
|
|
51
|
-
const isShopifyPath = (path: string) => path.startsWith('shopify.');
|
|
52
50
|
|
|
53
51
|
const hasDefaultTranslation = (translationPath: string) =>
|
|
54
52
|
defaultTranslations.has(translationPath) ?? false;
|
|
@@ -71,10 +69,15 @@ export const MatchingTranslations: JSONCheckDefinition = {
|
|
|
71
69
|
}, []);
|
|
72
70
|
};
|
|
73
71
|
|
|
72
|
+
// Strip the locale prefix (first Property in the ancestors chain).
|
|
73
|
+
// YAML files wrap content under a locale key: { en: { hello: 'Hello' } }
|
|
74
|
+
// We want paths like 'hello', not 'en.hello'.
|
|
74
75
|
const objectPath = (nodes: JSONNode[]) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const props = nodes.filter((n): n is PropertyNode => n.type === 'Property');
|
|
77
|
+
if (props.length <= 1) return ''; // locale key itself, or empty
|
|
78
|
+
return props
|
|
79
|
+
.slice(1)
|
|
80
|
+
.map((p) => p.key.value)
|
|
78
81
|
.join('.');
|
|
79
82
|
};
|
|
80
83
|
|
|
@@ -110,10 +113,7 @@ export const MatchingTranslations: JSONCheckDefinition = {
|
|
|
110
113
|
|
|
111
114
|
return {
|
|
112
115
|
async onCodePathStart() {
|
|
113
|
-
const
|
|
114
|
-
? context.getDefaultSchemaTranslations
|
|
115
|
-
: context.getDefaultTranslations;
|
|
116
|
-
const defaultTranslationPaths = await getDefaultTranslations().then(jsonPaths);
|
|
116
|
+
const defaultTranslationPaths = await context.getDefaultTranslations().then(jsonPaths);
|
|
117
117
|
defaultTranslationPaths.forEach(Set.prototype.add, defaultTranslations);
|
|
118
118
|
|
|
119
119
|
// At the `onCodePathStart`, we assume that all translations are missing,
|
|
@@ -124,12 +124,13 @@ export const MatchingTranslations: JSONCheckDefinition = {
|
|
|
124
124
|
async Property(node, ancestors) {
|
|
125
125
|
const path = objectPath(ancestors.concat(node));
|
|
126
126
|
|
|
127
|
+
if (!path) return; // skip the root locale key (e.g. 'pt-BR')
|
|
128
|
+
|
|
127
129
|
nodesByPath.set(path, node);
|
|
128
130
|
|
|
129
131
|
if (!hasDefaultTranslations()) return;
|
|
130
132
|
if (isPluralizationNode(node)) return;
|
|
131
133
|
if (!isTerminalNode(node.value)) return;
|
|
132
|
-
if (isShopifyPath(path)) return;
|
|
133
134
|
|
|
134
135
|
if (hasDefaultTranslation(path)) {
|
|
135
136
|
// As `path` is present, we remove it from the
|
|
@@ -142,14 +143,6 @@ export const MatchingTranslations: JSONCheckDefinition = {
|
|
|
142
143
|
message: `A default translation for '${path}' does not exist`,
|
|
143
144
|
startIndex: node.loc!.start.offset,
|
|
144
145
|
endIndex: node.loc!.end.offset,
|
|
145
|
-
suggest: [
|
|
146
|
-
{
|
|
147
|
-
message: 'Delete unneeded translation key',
|
|
148
|
-
fix(corrector) {
|
|
149
|
-
corrector.remove(path);
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
146
|
});
|
|
154
147
|
},
|
|
155
148
|
|
|
@@ -158,15 +151,11 @@ export const MatchingTranslations: JSONCheckDefinition = {
|
|
|
158
151
|
const closest = closestTranslationKey(path);
|
|
159
152
|
|
|
160
153
|
if (isPluralizationPath(path)) return;
|
|
161
|
-
if (isShopifyPath(path)) return;
|
|
162
154
|
|
|
163
155
|
context.report({
|
|
164
156
|
message: `The translation for '${path}' is missing`,
|
|
165
157
|
startIndex: closest.loc!.start.offset,
|
|
166
158
|
endIndex: closest.loc!.end.offset,
|
|
167
|
-
fix(corrector) {
|
|
168
|
-
corrector.add(path, 'TODO');
|
|
169
|
-
},
|
|
170
159
|
});
|
|
171
160
|
});
|
|
172
161
|
},
|
|
@@ -3,7 +3,6 @@ import yaml from 'js-yaml';
|
|
|
3
3
|
import { DocumentsLocator, DocumentType } from '@platformos/platformos-common';
|
|
4
4
|
import { URI } from 'vscode-uri';
|
|
5
5
|
import { LiquidNamedArgument, Position } from '@platformos/liquid-html-parser';
|
|
6
|
-
import { getLiquidDocParams } from '../../liquid-doc/arguments';
|
|
7
6
|
import { relative } from '../../path';
|
|
8
7
|
|
|
9
8
|
type Metadata = {
|
|
@@ -64,12 +63,11 @@ export const MetadataParamsCheck: LiquidCheckDefinition = {
|
|
|
64
63
|
}
|
|
65
64
|
let params = extractMetadataParams(await context.fs.readFile(locatedFile));
|
|
66
65
|
if (!params) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
if (!liquidDocParameters) return;
|
|
66
|
+
if (!context.getDocDefinition) return;
|
|
67
|
+
const relativePath = relative(locatedFile, context.config.rootUri);
|
|
68
|
+
const docDef = await context.getDocDefinition(relativePath);
|
|
69
|
+
if (!docDef?.liquidDoc?.parameters) return;
|
|
70
|
+
const liquidDocParameters = new Map(docDef.liquidDoc.parameters.map((p) => [p.name, p]));
|
|
73
71
|
|
|
74
72
|
params = Array.from(liquidDocParameters.values())
|
|
75
73
|
.filter((p) => p.required)
|
|
@@ -11,7 +11,7 @@ export const MissingAsset: LiquidCheckDefinition = {
|
|
|
11
11
|
docs: {
|
|
12
12
|
description: 'Reports missing asset files',
|
|
13
13
|
recommended: true,
|
|
14
|
-
url: 'https://
|
|
14
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/missing-asset',
|
|
15
15
|
},
|
|
16
16
|
type: SourceCodeType.LiquidHtml,
|
|
17
17
|
severity: Severity.ERROR,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { expect, describe, it } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { MissingPartial } from '.';
|
|
3
3
|
import { check } from '../../test';
|
|
4
4
|
|
|
5
|
-
describe('Module:
|
|
6
|
-
it('should report missing
|
|
5
|
+
describe('Module: MissingPartial', () => {
|
|
6
|
+
it('should report missing partial errors', async () => {
|
|
7
7
|
const testCases = [
|
|
8
8
|
{
|
|
9
9
|
testCase: 'should report the missing partial to be rendered with "render"',
|
|
@@ -12,7 +12,7 @@ describe('Module: MissingTemplate', () => {
|
|
|
12
12
|
{% render myvariable %}
|
|
13
13
|
`,
|
|
14
14
|
expected: {
|
|
15
|
-
check: '
|
|
15
|
+
check: 'MissingPartial',
|
|
16
16
|
end: {
|
|
17
17
|
character: 27,
|
|
18
18
|
index: 28,
|
|
@@ -49,11 +49,11 @@ describe('Module: MissingTemplate', () => {
|
|
|
49
49
|
},
|
|
50
50
|
];
|
|
51
51
|
for (const { testCase, file, expected, filesWith } of testCases) {
|
|
52
|
-
const offenses = await check(filesWith(file), [
|
|
52
|
+
const offenses = await check(filesWith(file), [MissingPartial]);
|
|
53
53
|
|
|
54
54
|
expect(offenses).to.have.length(1);
|
|
55
55
|
expect(offenses, testCase).to.containOffense({
|
|
56
|
-
check:
|
|
56
|
+
check: MissingPartial.meta.code,
|
|
57
57
|
...expected,
|
|
58
58
|
});
|
|
59
59
|
}
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
LiquidTagNamed,
|
|
4
|
-
NamedTags,
|
|
5
|
-
NodeTypes,
|
|
6
|
-
Position,
|
|
7
|
-
} from '@platformos/liquid-html-parser';
|
|
8
|
-
import { minimatch } from 'minimatch';
|
|
9
|
-
import {
|
|
10
|
-
LiquidCheckDefinition,
|
|
11
|
-
RelativePath,
|
|
12
|
-
SchemaProp,
|
|
13
|
-
Severity,
|
|
14
|
-
SourceCodeType,
|
|
15
|
-
} from '../../types';
|
|
16
|
-
import { doesFileExist } from '../../utils/file-utils';
|
|
1
|
+
import { NodeTypes } from '@platformos/liquid-html-parser';
|
|
2
|
+
import { LiquidCheckDefinition, SchemaProp, Severity, SourceCodeType } from '../../types';
|
|
17
3
|
import { DocumentsLocator } from '@platformos/platformos-common';
|
|
18
4
|
import { URI } from 'vscode-uri';
|
|
19
5
|
|
|
@@ -21,14 +7,14 @@ const schema = {
|
|
|
21
7
|
ignoreMissing: SchemaProp.array(SchemaProp.string(), []),
|
|
22
8
|
};
|
|
23
9
|
|
|
24
|
-
export const
|
|
10
|
+
export const MissingPartial: LiquidCheckDefinition<typeof schema> = {
|
|
25
11
|
meta: {
|
|
26
|
-
code: '
|
|
27
|
-
name: 'Avoid rendering missing
|
|
12
|
+
code: 'MissingPartial',
|
|
13
|
+
name: 'Avoid rendering missing partials',
|
|
28
14
|
docs: {
|
|
29
15
|
description: 'Reports missing partial liquid file',
|
|
30
16
|
recommended: true,
|
|
31
|
-
url: 'https://
|
|
17
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/missing-partial',
|
|
32
18
|
},
|
|
33
19
|
type: SourceCodeType.LiquidHtml,
|
|
34
20
|
severity: Severity.ERROR,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPartial } from '../../
|
|
1
|
+
import { isPartial } from '../../path';
|
|
2
2
|
import { LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';
|
|
3
3
|
|
|
4
4
|
export const OrphanedPartial: LiquidCheckDefinition = {
|
|
@@ -6,9 +6,9 @@ export const OrphanedPartial: LiquidCheckDefinition = {
|
|
|
6
6
|
code: 'OrphanedPartial',
|
|
7
7
|
name: 'Prevent orphaned partials',
|
|
8
8
|
docs: {
|
|
9
|
-
description: 'This check exists to prevent orphaned partials in
|
|
9
|
+
description: 'This check exists to prevent orphaned partials in platformOS apps.',
|
|
10
10
|
recommended: true,
|
|
11
|
-
url: 'https://
|
|
11
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/orphaned-partial',
|
|
12
12
|
},
|
|
13
13
|
type: SourceCodeType.LiquidHtml,
|
|
14
14
|
severity: Severity.WARNING,
|
|
@@ -3,26 +3,6 @@ import { ParserBlockingScript } from '.';
|
|
|
3
3
|
import { applySuggestions, check as reportOffenses } from '../../test';
|
|
4
4
|
|
|
5
5
|
describe('Module: ParserBlockingScript', () => {
|
|
6
|
-
it('should report the correct offense for the Liquid filter', async () => {
|
|
7
|
-
const file = "{{ 'asset' | script_tag }}";
|
|
8
|
-
const startIndex = file.indexOf('script_tag');
|
|
9
|
-
const endIndex = startIndex + 'script_tag'.length;
|
|
10
|
-
|
|
11
|
-
const offenses = await reportOffenses(
|
|
12
|
-
{
|
|
13
|
-
'code.liquid': file,
|
|
14
|
-
},
|
|
15
|
-
[ParserBlockingScript],
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
expect(offenses).to.have.length(1);
|
|
19
|
-
const { check, message, start, end } = offenses[0];
|
|
20
|
-
expect(check).to.equal(ParserBlockingScript.meta.code);
|
|
21
|
-
expect(message).to.contain('Use a <script> tag with async');
|
|
22
|
-
expect(start.index).to.equal(startIndex);
|
|
23
|
-
expect(end.index).to.equal(endIndex);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
6
|
it('should report the correct offense when using the script tag', async () => {
|
|
27
7
|
const file = `
|
|
28
8
|
<script src="https://foo.bar/baz.js"></script>
|
|
@@ -45,104 +25,6 @@ describe('Module: ParserBlockingScript', () => {
|
|
|
45
25
|
expect(end.index).to.equal(endIndex);
|
|
46
26
|
});
|
|
47
27
|
|
|
48
|
-
describe('Case: LiquidFilter corrections', () => {
|
|
49
|
-
it('should suggest to replace a LiquidVariableOutput with a script tag that has the expression as URL', async () => {
|
|
50
|
-
const file = "{{ 'asset' | script_tag }}";
|
|
51
|
-
const offenses = await reportOffenses(
|
|
52
|
-
{
|
|
53
|
-
'code.liquid': file,
|
|
54
|
-
},
|
|
55
|
-
[ParserBlockingScript],
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
expect(offenses).to.have.length(1);
|
|
59
|
-
const offense = offenses[0]!;
|
|
60
|
-
expect(offense).to.suggest(file, `Use an HTML script tag with the defer attribute instead`, {
|
|
61
|
-
startIndex: 0,
|
|
62
|
-
endIndex: file.length,
|
|
63
|
-
insert: `<script src="{{ 'asset' }}" defer></script>`,
|
|
64
|
-
});
|
|
65
|
-
expect(offense).to.suggest(file, `Use an HTML script tag with the async attribute instead`, {
|
|
66
|
-
startIndex: 0,
|
|
67
|
-
endIndex: file.length,
|
|
68
|
-
insert: `<script src="{{ 'asset' }}" async></script>`,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const suggestions = applySuggestions(file, offense);
|
|
72
|
-
expect(suggestions).to.include(`<script src="{{ 'asset' }}" defer></script>`);
|
|
73
|
-
expect(suggestions).to.include(`<script src="{{ 'asset' }}" async></script>`);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should suggest to replace a LiquidVariableOutput with a script tag that has the expression and previous filters as URL', async () => {
|
|
77
|
-
const file = "{{ 'asset' | asset_url | script_tag }}";
|
|
78
|
-
const offenses = await reportOffenses(
|
|
79
|
-
{
|
|
80
|
-
'code.liquid': file,
|
|
81
|
-
},
|
|
82
|
-
[ParserBlockingScript],
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
expect(offenses).to.have.length(1);
|
|
86
|
-
const offense = offenses[0];
|
|
87
|
-
expect(offense).to.suggest(file, `Use an HTML script tag with the defer attribute instead`, {
|
|
88
|
-
startIndex: 0,
|
|
89
|
-
endIndex: file.length,
|
|
90
|
-
insert: `<script src="{{ 'asset' | asset_url }}" defer></script>`,
|
|
91
|
-
});
|
|
92
|
-
expect(offense).to.suggest(file, `Use an HTML script tag with the async attribute instead`, {
|
|
93
|
-
startIndex: 0,
|
|
94
|
-
endIndex: file.length,
|
|
95
|
-
insert: `<script src="{{ 'asset' | asset_url }}" async></script>`,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const suggestions = applySuggestions(file, offense);
|
|
99
|
-
expect(suggestions).to.include(`<script src="{{ 'asset' | asset_url }}" defer></script>`);
|
|
100
|
-
expect(suggestions).to.include(`<script src="{{ 'asset' | asset_url }}" async></script>`);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should not suggest anything if the script_tag appears in an echo tag', async () => {
|
|
104
|
-
const file = "{% echo 'asset' | asset_url | script_tag %}";
|
|
105
|
-
const offenses = await reportOffenses(
|
|
106
|
-
{
|
|
107
|
-
'code.liquid': file,
|
|
108
|
-
},
|
|
109
|
-
[ParserBlockingScript],
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
expect(offenses).to.have.length(1);
|
|
113
|
-
const { suggest } = offenses[0];
|
|
114
|
-
expect(suggest).not.to.exist;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should not suggest anything if the script_tag appears in an assign tag', async () => {
|
|
118
|
-
const file = "{% assign script = 'asset' | asset_url | script_tag %}";
|
|
119
|
-
const offenses = await reportOffenses(
|
|
120
|
-
{
|
|
121
|
-
'code.liquid': file,
|
|
122
|
-
},
|
|
123
|
-
[ParserBlockingScript],
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
expect(offenses).to.have.length(1);
|
|
127
|
-
const { suggest } = offenses[0];
|
|
128
|
-
expect(suggest).not.to.exist;
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should not suggest anything if the script_tag appears in a liquid tag', async () => {
|
|
132
|
-
const file = "{% liquid\necho 'asset' | asset_url | script_tag %}";
|
|
133
|
-
const offenses = await reportOffenses(
|
|
134
|
-
{
|
|
135
|
-
'code.liquid': file,
|
|
136
|
-
},
|
|
137
|
-
[ParserBlockingScript],
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
expect(offenses).to.have.length(1);
|
|
141
|
-
const { suggest } = offenses[0];
|
|
142
|
-
expect(suggest).not.to.exist;
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
28
|
describe('Case: script tag suggestion', () => {
|
|
147
29
|
it('should suggest adding both attributes at the end', async () => {
|
|
148
30
|
const file = `<script src="a.js"></script>`;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { NodeTypes } from '@platformos/liquid-html-parser';
|
|
2
1
|
import { LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';
|
|
3
|
-
import { last } from '../../utils';
|
|
4
2
|
import { hasAttributeValueOf, isAttr, isHtmlAttribute, isValuedHtmlAttribute } from '../utils';
|
|
5
|
-
import {
|
|
3
|
+
import { scriptTagSuggestion } from './suggestions';
|
|
6
4
|
|
|
7
5
|
export const ParserBlockingScript: LiquidCheckDefinition = {
|
|
8
6
|
meta: {
|
|
@@ -10,9 +8,9 @@ export const ParserBlockingScript: LiquidCheckDefinition = {
|
|
|
10
8
|
aliases: ['ParserBlockingScriptTag'],
|
|
11
9
|
name: 'Avoid parser blocking scripts',
|
|
12
10
|
docs: {
|
|
13
|
-
description: '
|
|
11
|
+
description: 'Parser-blocking scripts delay page rendering by blocking the HTML parser.',
|
|
14
12
|
recommended: true,
|
|
15
|
-
url: 'https://
|
|
13
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/parser-blocking-script',
|
|
16
14
|
},
|
|
17
15
|
type: SourceCodeType.LiquidHtml,
|
|
18
16
|
severity: Severity.ERROR,
|
|
@@ -22,34 +20,6 @@ export const ParserBlockingScript: LiquidCheckDefinition = {
|
|
|
22
20
|
|
|
23
21
|
create(context) {
|
|
24
22
|
return {
|
|
25
|
-
// {{ 'asset' | asset_url | script_tag }}
|
|
26
|
-
LiquidFilter: async (node, ancestors) => {
|
|
27
|
-
if (node.name !== 'script_tag') return;
|
|
28
|
-
|
|
29
|
-
const filterString = node.source.slice(node.position.start, node.position.end);
|
|
30
|
-
const offset = filterString.indexOf('script_tag');
|
|
31
|
-
const parentNode = last(ancestors);
|
|
32
|
-
const grandParentNode = last(ancestors, -1);
|
|
33
|
-
|
|
34
|
-
context.report({
|
|
35
|
-
message:
|
|
36
|
-
'The script_tag filter is parser-blocking. Use a <script> tag with async or defer for better performance',
|
|
37
|
-
startIndex: node.position.start + offset,
|
|
38
|
-
endIndex: node.position.end,
|
|
39
|
-
suggest:
|
|
40
|
-
grandParentNode &&
|
|
41
|
-
grandParentNode.type === NodeTypes.LiquidVariableOutput &&
|
|
42
|
-
parentNode &&
|
|
43
|
-
parentNode.type === NodeTypes.LiquidVariable &&
|
|
44
|
-
last(parentNode.filters) === node
|
|
45
|
-
? [
|
|
46
|
-
liquidFilterSuggestion('defer', node, parentNode, grandParentNode),
|
|
47
|
-
liquidFilterSuggestion('async', node, parentNode, grandParentNode),
|
|
48
|
-
]
|
|
49
|
-
: undefined,
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
|
|
53
23
|
// <script src="...">
|
|
54
24
|
HtmlRawNode: async (node) => {
|
|
55
25
|
if (node.name !== 'script') {
|
|
@@ -1,36 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HtmlRawNode,
|
|
3
|
-
LiquidFilter,
|
|
4
|
-
LiquidVariable,
|
|
5
|
-
LiquidVariableOutput,
|
|
6
|
-
} from '@platformos/liquid-html-parser';
|
|
1
|
+
import { HtmlRawNode } from '@platformos/liquid-html-parser';
|
|
7
2
|
import { LiquidHtmlSuggestion } from '../../types';
|
|
8
|
-
import { last } from '../../utils';
|
|
9
3
|
|
|
10
4
|
const suggestionMessage = (attr: 'defer' | 'async') =>
|
|
11
5
|
`Use an HTML script tag with the ${attr} attribute instead`;
|
|
12
6
|
|
|
13
|
-
export const liquidFilterSuggestion = (
|
|
14
|
-
attr: 'defer' | 'async',
|
|
15
|
-
node: LiquidFilter,
|
|
16
|
-
parentNode: LiquidVariable,
|
|
17
|
-
grandParentNode: LiquidVariableOutput,
|
|
18
|
-
): LiquidHtmlSuggestion => ({
|
|
19
|
-
message: suggestionMessage(attr),
|
|
20
|
-
fix(corrector) {
|
|
21
|
-
const expression = node.source.slice(
|
|
22
|
-
parentNode.expression.position.start,
|
|
23
|
-
last(parentNode.filters, -1)?.position.end ?? node.position.start,
|
|
24
|
-
);
|
|
25
|
-
const url = `{{ ${expression} }}`;
|
|
26
|
-
corrector.replace(
|
|
27
|
-
grandParentNode.position.start,
|
|
28
|
-
grandParentNode.position.end,
|
|
29
|
-
`<script src="${url}" ${attr}></script>`,
|
|
30
|
-
);
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
7
|
export const scriptTagSuggestion = (
|
|
35
8
|
attr: 'defer' | 'async',
|
|
36
9
|
node: HtmlRawNode,
|
|
@@ -25,7 +25,7 @@ export const TranslationKeyExists: LiquidCheckDefinition = {
|
|
|
25
25
|
docs: {
|
|
26
26
|
description: 'Reports missing translation keys',
|
|
27
27
|
recommended: true,
|
|
28
|
-
url: 'https://
|
|
28
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/translation-key-exists',
|
|
29
29
|
},
|
|
30
30
|
type: SourceCodeType.LiquidHtml,
|
|
31
31
|
severity: Severity.ERROR,
|
|
@@ -41,7 +41,7 @@ export const UnclosedHTMLElement: LiquidCheckDefinition = {
|
|
|
41
41
|
docs: {
|
|
42
42
|
description: 'Warns you of unbalanced HTML tags in branching code',
|
|
43
43
|
recommended: true,
|
|
44
|
-
url: 'https://
|
|
44
|
+
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/unclosed-html-element',
|
|
45
45
|
},
|
|
46
46
|
type: SourceCodeType.LiquidHtml,
|
|
47
47
|
severity: Severity.WARNING,
|
|
@@ -272,6 +272,10 @@ function getConditionIdentifierForMarkup(condition: string | LiquidConditionalEx
|
|
|
272
272
|
condition.relation,
|
|
273
273
|
getConditionIdentifierForMarkup(condition.right),
|
|
274
274
|
].join(' ');
|
|
275
|
+
case NodeTypes.JsonHashLiteral:
|
|
276
|
+
return '{}';
|
|
277
|
+
case NodeTypes.JsonArrayLiteral:
|
|
278
|
+
return '[]';
|
|
275
279
|
default: {
|
|
276
280
|
return assertNever(condition);
|
|
277
281
|
}
|