@platformos/platformos-check-common 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +4 -4
- package/dist/AugmentedPlatformOSDocset.d.ts +11 -0
- package/dist/AugmentedPlatformOSDocset.js +81 -0
- package/dist/AugmentedPlatformOSDocset.js.map +1 -0
- package/dist/JSONValidator.js +1 -1
- package/dist/JSONValidator.js.map +1 -1
- package/dist/checks/deprecated-filter/index.js +4 -41
- package/dist/checks/deprecated-filter/index.js.map +1 -1
- package/dist/checks/deprecated-tag/index.js +21 -22
- package/dist/checks/deprecated-tag/index.js.map +1 -1
- package/dist/checks/duplicate-function-arguments/index.js +1 -1
- package/dist/checks/duplicate-function-arguments/index.js.map +1 -1
- package/dist/checks/duplicate-render-partial-arguments/index.js +1 -1
- package/dist/checks/duplicate-render-partial-arguments/index.js.map +1 -1
- package/dist/checks/graphql/index.js +1 -1
- package/dist/checks/graphql/index.js.map +1 -1
- package/dist/checks/graphql-variables/index.js +4 -0
- package/dist/checks/graphql-variables/index.js.map +1 -1
- package/dist/checks/img-width-and-height/index.js +1 -1
- package/dist/checks/img-width-and-height/index.js.map +1 -1
- package/dist/checks/index.d.ts +3 -3
- package/dist/checks/index.js +4 -79
- package/dist/checks/index.js.map +1 -1
- package/dist/checks/json-syntax-error/index.js +1 -1
- package/dist/checks/json-syntax-error/index.js.map +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.js +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.js.map +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.d.ts +19 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js +79 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.d.ts +3 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.js +32 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/index.js +23 -5
- package/dist/checks/liquid-html-syntax-error/index.js.map +1 -1
- package/dist/checks/matching-translations/index.d.ts +2 -2
- package/dist/checks/matching-translations/index.js +114 -90
- package/dist/checks/matching-translations/index.js.map +1 -1
- package/dist/checks/metadata-params/index.js +6 -3
- package/dist/checks/metadata-params/index.js.map +1 -1
- package/dist/checks/missing-asset/index.js +1 -1
- package/dist/checks/missing-asset/index.js.map +1 -1
- package/dist/checks/missing-partial/index.d.ts +6 -0
- package/dist/checks/missing-partial/index.js +70 -0
- package/dist/checks/missing-partial/index.js.map +1 -0
- package/dist/checks/orphaned-partial/index.js +4 -4
- package/dist/checks/orphaned-partial/index.js.map +1 -1
- package/dist/checks/parser-blocking-script/index.js +10 -36
- package/dist/checks/parser-blocking-script/index.js.map +1 -1
- package/dist/checks/parser-blocking-script/suggestions.d.ts +1 -2
- package/dist/checks/parser-blocking-script/suggestions.js +1 -11
- package/dist/checks/parser-blocking-script/suggestions.js.map +1 -1
- package/dist/checks/reserved-doc-param-names/index.js +6 -5
- package/dist/checks/reserved-doc-param-names/index.js.map +1 -1
- package/dist/checks/translation-key-exists/index.js +1 -1
- package/dist/checks/translation-key-exists/index.js.map +1 -1
- package/dist/checks/unclosed-html-element/index.js +5 -1
- package/dist/checks/unclosed-html-element/index.js.map +1 -1
- package/dist/checks/undefined-object/index.js +13 -31
- package/dist/checks/undefined-object/index.js.map +1 -1
- package/dist/checks/unique-doc-param-names/index.js +1 -1
- package/dist/checks/unique-doc-param-names/index.js.map +1 -1
- package/dist/checks/unknown-filter/index.js +3 -3
- package/dist/checks/unknown-filter/index.js.map +1 -1
- package/dist/checks/unknown-property/index.js +1 -1
- package/dist/checks/unknown-property/index.js.map +1 -1
- package/dist/checks/unrecognized-render-partial-arguments/index.js +2 -2
- package/dist/checks/unrecognized-render-partial-arguments/index.js.map +1 -1
- package/dist/checks/unused-assign/index.js +1 -1
- package/dist/checks/unused-assign/index.js.map +1 -1
- package/dist/checks/unused-doc-param/index.js +1 -1
- package/dist/checks/unused-doc-param/index.js.map +1 -1
- package/dist/checks/utils.js +1 -1
- package/dist/checks/utils.js.map +1 -1
- package/dist/checks/valid-content-for-arguments/index.js +1 -1
- package/dist/checks/valid-content-for-arguments/index.js.map +1 -1
- package/dist/checks/valid-doc-param-types/index.js +4 -4
- package/dist/checks/valid-doc-param-types/index.js.map +1 -1
- package/dist/checks/valid-html-translation/index.d.ts +2 -2
- package/dist/checks/valid-html-translation/index.js +4 -4
- package/dist/checks/valid-html-translation/index.js.map +1 -1
- package/dist/checks/valid-json/index.js +1 -1
- package/dist/checks/valid-json/index.js.map +1 -1
- package/dist/checks/valid-render-partial-argument-types/index.js +2 -2
- package/dist/checks/valid-render-partial-argument-types/index.js.map +1 -1
- package/dist/checks/variable-name/index.js +1 -1
- package/dist/checks/variable-name/index.js.map +1 -1
- package/dist/context-utils.d.ts +18 -7
- package/dist/context-utils.js +68 -109
- package/dist/context-utils.js.map +1 -1
- package/dist/disabled-checks/index.js +4 -2
- package/dist/disabled-checks/index.js.map +1 -1
- package/dist/doc-generator/DocBlockGenerator.d.ts +16 -0
- package/dist/doc-generator/DocBlockGenerator.js +464 -0
- package/dist/doc-generator/DocBlockGenerator.js.map +1 -0
- package/dist/doc-generator/index.d.ts +1 -0
- package/dist/doc-generator/index.js +6 -0
- package/dist/doc-generator/index.js.map +1 -0
- package/dist/find-root.d.ts +7 -10
- package/dist/find-root.js +10 -17
- package/dist/find-root.js.map +1 -1
- package/dist/fixes/autofix.d.ts +4 -4
- package/dist/fixes/autofix.js +2 -2
- package/dist/fixes/autofix.js.map +1 -1
- package/dist/fixes/correctors/index.js +4 -0
- package/dist/fixes/correctors/index.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +50 -17
- package/dist/index.js.map +1 -1
- package/dist/jsonc/parse.d.ts +1 -1
- package/dist/jsonc/parse.js +1 -1
- package/dist/liquid-doc/arguments.d.ts +7 -8
- package/dist/liquid-doc/arguments.js +28 -29
- package/dist/liquid-doc/arguments.js.map +1 -1
- package/dist/liquid-doc/liquidDoc.d.ts +1 -1
- package/dist/liquid-doc/liquidDoc.js.map +1 -1
- package/dist/liquid-doc/utils.d.ts +3 -3
- package/dist/liquid-doc/utils.js +14 -3
- package/dist/liquid-doc/utils.js.map +1 -1
- package/dist/path.d.ts +1 -0
- package/dist/path.js +16 -1
- package/dist/path.js.map +1 -1
- package/{src/test/MockTheme.ts → dist/test/MockApp.d.ts} +2 -3
- package/dist/test/MockApp.js +16 -0
- package/dist/test/MockApp.js.map +1 -0
- package/dist/test/MockFileSystem.d.ts +3 -3
- package/dist/test/MockFileSystem.js +6 -6
- package/dist/test/MockFileSystem.js.map +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +1 -1
- package/dist/test/index.js.map +1 -1
- package/dist/test/test-helper.d.ts +10 -9
- package/dist/test/test-helper.js +15 -106
- package/dist/test/test-helper.js.map +1 -1
- package/dist/to-schema.d.ts +1 -1
- package/dist/to-source-code.d.ts +3 -2
- package/dist/to-source-code.js +20 -0
- package/dist/to-source-code.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/platformos-liquid-docs.d.ts +128 -0
- package/dist/types/platformos-liquid-docs.js +3 -0
- package/dist/types/platformos-liquid-docs.js.map +1 -0
- package/dist/types/schemas/index.d.ts +0 -2
- package/dist/types/schemas/index.js.map +1 -1
- package/dist/types.d.ts +26 -67
- package/dist/types.js +3 -5
- package/dist/types.js.map +1 -1
- package/dist/utils/block.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/yaml/parse.d.ts +5 -0
- package/dist/yaml/parse.js +94 -0
- package/dist/yaml/parse.js.map +1 -0
- package/package.json +4 -3
- package/src/{AugmentedThemeDocset.spec.ts → AugmentedPlatformOSDocset.spec.ts} +47 -34
- package/src/AugmentedPlatformOSDocset.ts +89 -0
- package/src/JSONValidator.ts +1 -1
- package/src/checks/deprecated-filter/index.spec.ts +76 -248
- package/src/checks/deprecated-filter/index.ts +5 -53
- package/src/checks/deprecated-tag/index.spec.ts +85 -34
- package/src/checks/deprecated-tag/index.ts +27 -22
- package/src/checks/duplicate-function-arguments/index.ts +1 -1
- package/src/checks/duplicate-render-partial-arguments/index.spec.ts +12 -12
- package/src/checks/duplicate-render-partial-arguments/index.ts +1 -1
- package/src/checks/graphql/index.ts +1 -1
- package/src/checks/graphql-variables/index.spec.ts +95 -0
- package/src/checks/graphql-variables/index.ts +4 -0
- package/src/checks/img-width-and-height/index.ts +2 -2
- package/src/checks/index.ts +11 -80
- package/src/checks/invalid-hash-assign-target/index.spec.ts +27 -27
- package/src/checks/json-syntax-error/index.ts +2 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidBooleanExpression.spec.ts +0 -11
- package/src/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.spec.ts +1 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.ts +2 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.spec.ts +259 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.ts +89 -0
- package/src/checks/liquid-html-syntax-error/checks/UnknownTag.spec.ts +293 -0
- package/src/checks/liquid-html-syntax-error/checks/UnknownTag.ts +43 -0
- package/src/checks/liquid-html-syntax-error/index.spec.ts +1 -6
- package/src/checks/liquid-html-syntax-error/index.ts +26 -5
- package/src/checks/matching-translations/index.spec.ts +187 -354
- package/src/checks/matching-translations/index.ts +117 -107
- package/src/checks/metadata-params/index.ts +6 -8
- package/src/checks/missing-asset/index.ts +1 -1
- package/src/checks/{missing-template → missing-partial}/index.spec.ts +6 -6
- package/src/checks/{missing-template → missing-partial}/index.ts +12 -26
- package/src/checks/orphaned-partial/index.ts +3 -3
- package/src/checks/parser-blocking-script/index.spec.ts +0 -118
- package/src/checks/parser-blocking-script/index.ts +3 -33
- package/src/checks/parser-blocking-script/suggestions.ts +1 -28
- package/src/checks/translation-key-exists/index.ts +1 -1
- package/src/checks/unclosed-html-element/index.ts +5 -1
- package/src/checks/undefined-object/index.spec.ts +32 -111
- package/src/checks/undefined-object/index.ts +15 -34
- package/src/checks/unique-doc-param-names/index.ts +1 -1
- package/src/checks/unknown-filter/index.spec.ts +2 -2
- package/src/checks/unknown-filter/index.ts +3 -3
- package/src/checks/unknown-property/index.ts +1 -1
- package/src/checks/unrecognized-render-partial-arguments/index.spec.ts +5 -5
- package/src/checks/unrecognized-render-partial-arguments/index.ts +2 -5
- package/src/checks/unused-assign/index.spec.ts +0 -30
- package/src/checks/unused-assign/index.ts +2 -2
- package/src/checks/unused-doc-param/index.ts +1 -1
- package/src/checks/utils.ts +1 -1
- package/src/checks/valid-doc-param-types/index.ts +4 -4
- package/src/checks/valid-html-translation/index.spec.ts +42 -32
- package/src/checks/valid-html-translation/index.ts +7 -7
- package/src/checks/valid-json/index.ts +2 -2
- package/src/checks/valid-render-partial-argument-types/index.spec.ts +13 -13
- package/src/checks/valid-render-partial-argument-types/index.ts +2 -5
- package/src/checks/variable-name/index.ts +1 -1
- package/src/context-utils.spec.ts +49 -77
- package/src/context-utils.ts +81 -129
- package/src/disabled-checks/index.spec.ts +26 -26
- package/src/disabled-checks/index.ts +2 -2
- package/src/disabled-checks/test-checks.ts +4 -4
- package/src/find-root.ts +12 -22
- package/src/fixes/autofix.spec.ts +2 -2
- package/src/fixes/autofix.ts +4 -4
- package/src/fixes/correctors/index.ts +4 -0
- package/src/ignore.spec.ts +4 -5
- package/src/index.ts +51 -21
- package/src/jsonc/parse.ts +1 -1
- package/src/liquid-doc/arguments.spec.ts +19 -45
- package/src/liquid-doc/arguments.ts +35 -42
- package/src/liquid-doc/liquidDoc.spec.ts +1 -1
- package/src/liquid-doc/liquidDoc.ts +1 -2
- package/src/liquid-doc/utils.ts +17 -8
- package/src/path.ts +16 -0
- package/src/test/MockApp.ts +17 -0
- package/src/test/MockFileSystem.spec.ts +10 -11
- package/src/test/MockFileSystem.ts +6 -6
- package/src/test/contain-offense.spec.ts +11 -3
- package/src/test/index.ts +1 -1
- package/src/test/test-helper.ts +43 -145
- package/src/to-source-code.ts +20 -1
- package/src/types/{theme-liquid-docs.ts → platformos-liquid-docs.ts} +8 -13
- package/src/types.ts +29 -92
- package/src/utils/index.ts +0 -1
- package/src/visitor.spec.ts +2 -2
- package/src/yaml/parse.ts +111 -0
- package/src/AugmentedThemeDocset.ts +0 -137
- package/src/checks/app-block-missing-schema/index.spec.ts +0 -121
- package/src/checks/app-block-missing-schema/index.ts +0 -46
- package/src/checks/app-block-valid-tags/index.spec.ts +0 -96
- package/src/checks/app-block-valid-tags/index.ts +0 -54
- package/src/checks/asset-preload/index.spec.ts +0 -78
- package/src/checks/asset-preload/index.ts +0 -65
- package/src/checks/asset-size-app-block-css/index.spec.ts +0 -88
- package/src/checks/asset-size-app-block-css/index.ts +0 -78
- package/src/checks/asset-size-app-block-javascript/index.spec.ts +0 -66
- package/src/checks/asset-size-app-block-javascript/index.ts +0 -78
- package/src/checks/asset-size-css/index.spec.ts +0 -166
- package/src/checks/asset-size-css/index.ts +0 -160
- package/src/checks/asset-size-javascript/index.spec.ts +0 -184
- package/src/checks/asset-size-javascript/index.ts +0 -144
- package/src/checks/block-id-usage/index.spec.ts +0 -76
- package/src/checks/block-id-usage/index.ts +0 -72
- package/src/checks/cdn-preconnect/index.spec.ts +0 -40
- package/src/checks/cdn-preconnect/index.ts +0 -43
- package/src/checks/content-for-header-modification/index.spec.ts +0 -65
- package/src/checks/content-for-header-modification/index.ts +0 -72
- package/src/checks/deprecate-bgsizes/index.spec.ts +0 -41
- package/src/checks/deprecate-bgsizes/index.ts +0 -49
- package/src/checks/deprecate-lazysizes/index.spec.ts +0 -26
- package/src/checks/deprecate-lazysizes/index.ts +0 -58
- package/src/checks/deprecated-filter/fixes.ts +0 -264
- package/src/checks/deprecated-fonts-on-sections-and-blocks/deprecated-fonts-data.ts +0 -1343
- package/src/checks/deprecated-fonts-on-sections-and-blocks/index.spec.ts +0 -613
- package/src/checks/deprecated-fonts-on-sections-and-blocks/index.ts +0 -284
- package/src/checks/deprecated-fonts-on-settings-schema/index.spec.ts +0 -102
- package/src/checks/deprecated-fonts-on-settings-schema/index.ts +0 -66
- package/src/checks/duplicate-content-for-arguments/index.spec.ts +0 -98
- package/src/checks/duplicate-content-for-arguments/index.ts +0 -43
- package/src/checks/empty-block-content/index.spec.ts +0 -117
- package/src/checks/empty-block-content/index.ts +0 -60
- package/src/checks/hardcoded-routes/index.spec.ts +0 -58
- package/src/checks/hardcoded-routes/index.ts +0 -100
- package/src/checks/json-missing-block/index.spec.ts +0 -435
- package/src/checks/json-missing-block/index.ts +0 -56
- package/src/checks/json-missing-block/missing-block-utils.ts +0 -147
- package/src/checks/liquid-free-settings/index.spec.ts +0 -180
- package/src/checks/liquid-free-settings/index.ts +0 -79
- package/src/checks/missing-content-for-arguments/index.spec.ts +0 -144
- package/src/checks/missing-content-for-arguments/index.ts +0 -46
- package/src/checks/pagination-size/index.spec.ts +0 -158
- package/src/checks/pagination-size/index.ts +0 -104
- package/src/checks/remote-asset/index.spec.ts +0 -280
- package/src/checks/remote-asset/index.ts +0 -238
- package/src/checks/reserved-doc-param-names/index.spec.ts +0 -62
- package/src/checks/reserved-doc-param-names/index.ts +0 -57
- package/src/checks/schema-presets-block-order/index.spec.ts +0 -344
- package/src/checks/schema-presets-block-order/index.ts +0 -154
- package/src/checks/schema-presets-static-blocks/index.spec.ts +0 -145
- package/src/checks/schema-presets-static-blocks/index.ts +0 -126
- package/src/checks/static-stylesheet-and-javascript-tags/index.spec.ts +0 -257
- package/src/checks/static-stylesheet-and-javascript-tags/index.ts +0 -48
- package/src/checks/unique-settings-id/index.spec.ts +0 -24
- package/src/checks/unique-settings-id/index.ts +0 -84
- package/src/checks/unique-settings-id/test-data.ts +0 -1191
- package/src/checks/unique-static-block-id/index.spec.ts +0 -55
- package/src/checks/unique-static-block-id/index.ts +0 -60
- package/src/checks/unrecognized-content-for-arguments/index.spec.ts +0 -145
- package/src/checks/unrecognized-content-for-arguments/index.ts +0 -55
- package/src/checks/valid-block-target/index.spec.ts +0 -1396
- package/src/checks/valid-block-target/index.ts +0 -142
- package/src/checks/valid-content-for-argument-types/index.spec.ts +0 -382
- package/src/checks/valid-content-for-argument-types/index.ts +0 -42
- package/src/checks/valid-content-for-arguments/index.spec.ts +0 -107
- package/src/checks/valid-content-for-arguments/index.ts +0 -98
- package/src/checks/valid-local-blocks/index.spec.ts +0 -286
- package/src/checks/valid-local-blocks/index.ts +0 -100
- package/src/checks/valid-local-blocks/valid-block-utils.ts +0 -97
- package/src/checks/valid-schema/index.spec.ts +0 -174
- package/src/checks/valid-schema/index.ts +0 -41
- package/src/checks/valid-schema-name/index.spec.ts +0 -112
- package/src/checks/valid-schema-name/index.ts +0 -75
- package/src/checks/valid-settings-key/index.spec.ts +0 -321
- package/src/checks/valid-settings-key/index.ts +0 -144
- package/src/checks/valid-static-block-type/index.spec.ts +0 -38
- package/src/checks/valid-static-block-type/index.ts +0 -58
- package/src/checks/valid-visible-if/index.spec.ts +0 -619
- package/src/checks/valid-visible-if/index.ts +0 -184
- package/src/checks/valid-visible-if/visible-if-utils.ts +0 -158
- package/src/tags/content-for.ts +0 -25
- package/src/to-schema.ts +0 -231
- package/src/types/schemas/index.ts +0 -5
- package/src/types/schemas/preset.ts +0 -52
- package/src/types/schemas/section.ts +0 -86
- package/src/types/schemas/setting.ts +0 -320
- package/src/types/schemas/template.ts +0 -34
- package/src/types/schemas/theme-block.ts +0 -34
- package/src/types/theme-schemas.ts +0 -80
- package/src/utils/block.ts +0 -300
- package/src/utils/markup.ts +0 -10
package/src/index.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AugmentedPlatformOSDocset } from './AugmentedPlatformOSDocset';
|
|
2
2
|
import { JSONValidator } from './JSONValidator';
|
|
3
3
|
import {
|
|
4
4
|
makeFileExists,
|
|
5
5
|
makeFileSize,
|
|
6
6
|
makeGetDefaultLocale,
|
|
7
|
-
makeGetDefaultSchemaLocale,
|
|
8
|
-
makeGetDefaultSchemaTranslations,
|
|
9
7
|
makeGetDefaultTranslations,
|
|
10
|
-
|
|
8
|
+
makeGetTranslationsForBase,
|
|
11
9
|
} from './context-utils';
|
|
12
10
|
import { createDisabledChecksModule } from './disabled-checks';
|
|
13
11
|
import { isIgnored } from './ignore';
|
|
@@ -35,22 +33,40 @@ import {
|
|
|
35
33
|
Settings,
|
|
36
34
|
SourceCode,
|
|
37
35
|
SourceCodeType,
|
|
38
|
-
|
|
36
|
+
App,
|
|
39
37
|
ValidateJSON,
|
|
38
|
+
YAMLCheck,
|
|
39
|
+
YAMLSourceCode,
|
|
40
40
|
} from './types';
|
|
41
41
|
import { getPosition } from './utils';
|
|
42
42
|
import { visitJSON, visitLiquid } from './visitors';
|
|
43
43
|
|
|
44
|
-
export * from './
|
|
44
|
+
export * from './AugmentedPlatformOSDocset';
|
|
45
|
+
export * from './types/platformos-liquid-docs';
|
|
45
46
|
export * from './checks';
|
|
46
47
|
export * from './context-utils';
|
|
47
48
|
export * from './find-root';
|
|
48
49
|
export * from './fixes';
|
|
49
50
|
export * from './ignore';
|
|
51
|
+
export {
|
|
52
|
+
FILE_TYPE_DIRS,
|
|
53
|
+
getAppPaths,
|
|
54
|
+
getFileType,
|
|
55
|
+
getModulePaths,
|
|
56
|
+
isApiCall,
|
|
57
|
+
isAuthorization,
|
|
58
|
+
isEmail,
|
|
59
|
+
isKnownLiquidFile,
|
|
60
|
+
isLayout,
|
|
61
|
+
isMigration,
|
|
62
|
+
isPage,
|
|
63
|
+
isPartial,
|
|
64
|
+
isSms,
|
|
65
|
+
PlatformOSFileType,
|
|
66
|
+
} from '@platformos/platformos-common';
|
|
50
67
|
export * from './json';
|
|
51
68
|
export * from './JSONValidator';
|
|
52
69
|
export * as path from './path';
|
|
53
|
-
export * from './to-schema';
|
|
54
70
|
export * from './to-source-code';
|
|
55
71
|
export * from './types';
|
|
56
72
|
export * from './utils/error';
|
|
@@ -60,7 +76,6 @@ export * from './utils/types';
|
|
|
60
76
|
export * from './utils/object';
|
|
61
77
|
export * from './visitor';
|
|
62
78
|
export * from './liquid-doc/liquidDoc';
|
|
63
|
-
export { getBlockName } from './liquid-doc/arguments';
|
|
64
79
|
export * from './liquid-doc/utils';
|
|
65
80
|
|
|
66
81
|
const defaultErrorHandler = (_error: Error): void => {
|
|
@@ -68,7 +83,7 @@ const defaultErrorHandler = (_error: Error): void => {
|
|
|
68
83
|
};
|
|
69
84
|
|
|
70
85
|
export async function check(
|
|
71
|
-
|
|
86
|
+
app: App,
|
|
72
87
|
config: Config,
|
|
73
88
|
injectedDependencies: Dependencies,
|
|
74
89
|
): Promise<Offense[]> {
|
|
@@ -78,15 +93,11 @@ export async function check(
|
|
|
78
93
|
const { rootUri } = config;
|
|
79
94
|
const dependencies: AugmentedDependencies = {
|
|
80
95
|
...injectedDependencies,
|
|
81
|
-
mode: config.context,
|
|
82
96
|
fileExists: makeFileExists(fs),
|
|
83
97
|
fileSize: makeFileSize(fs),
|
|
84
98
|
getDefaultLocale: makeGetDefaultLocale(fs, rootUri),
|
|
85
|
-
getDefaultTranslations: makeGetDefaultTranslations(fs,
|
|
86
|
-
|
|
87
|
-
getDefaultSchemaTranslations: makeGetDefaultSchemaTranslations(fs, theme, rootUri),
|
|
88
|
-
getMetafieldDefinitions:
|
|
89
|
-
injectedDependencies.getMetafieldDefinitions ?? makeGetMetafieldDefinitions(fs),
|
|
99
|
+
getDefaultTranslations: makeGetDefaultTranslations(fs, app, rootUri),
|
|
100
|
+
getTranslationsForBase: makeGetTranslationsForBase(fs, app),
|
|
90
101
|
};
|
|
91
102
|
|
|
92
103
|
const { DisabledChecksVisitor, isDisabled } = createDisabledChecksModule();
|
|
@@ -94,14 +105,14 @@ export async function check(
|
|
|
94
105
|
const validateJSON = jsonValidator?.validate;
|
|
95
106
|
|
|
96
107
|
// We're memozing those deps here because they shouldn't change within a run.
|
|
97
|
-
if (dependencies.
|
|
98
|
-
dependencies.
|
|
108
|
+
if (dependencies.platformosDocset && !dependencies.platformosDocset.isAugmented) {
|
|
109
|
+
dependencies.platformosDocset = new AugmentedPlatformOSDocset(dependencies.platformosDocset);
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
for (const type of Object.values(SourceCodeType)) {
|
|
102
113
|
switch (type) {
|
|
103
114
|
case SourceCodeType.JSON: {
|
|
104
|
-
const files = filesOfType(type,
|
|
115
|
+
const files = filesOfType(type, app);
|
|
105
116
|
const checkDefs = checksOfType(type, config.checks);
|
|
106
117
|
for (const file of files) {
|
|
107
118
|
for (const checkDef of checkDefs) {
|
|
@@ -113,7 +124,7 @@ export async function check(
|
|
|
113
124
|
break;
|
|
114
125
|
}
|
|
115
126
|
case SourceCodeType.GraphQL: {
|
|
116
|
-
const files = filesOfType(type,
|
|
127
|
+
const files = filesOfType(type, app);
|
|
117
128
|
const checkDefs = checksOfType(type, config.checks);
|
|
118
129
|
for (const file of files) {
|
|
119
130
|
for (const checkDef of checkDefs) {
|
|
@@ -125,7 +136,7 @@ export async function check(
|
|
|
125
136
|
break;
|
|
126
137
|
}
|
|
127
138
|
case SourceCodeType.LiquidHtml: {
|
|
128
|
-
const files = filesOfType(type,
|
|
139
|
+
const files = filesOfType(type, app);
|
|
129
140
|
const checkDefs = [DisabledChecksVisitor, ...checksOfType(type, config.checks)];
|
|
130
141
|
for (const file of files) {
|
|
131
142
|
for (const checkDef of checkDefs) {
|
|
@@ -136,6 +147,18 @@ export async function check(
|
|
|
136
147
|
}
|
|
137
148
|
break;
|
|
138
149
|
}
|
|
150
|
+
case SourceCodeType.YAML: {
|
|
151
|
+
const files = filesOfType(type, app);
|
|
152
|
+
const checkDefs = checksOfType(type, config.checks);
|
|
153
|
+
for (const file of files) {
|
|
154
|
+
for (const checkDef of checkDefs) {
|
|
155
|
+
if (isIgnored(file.uri, config, checkDef)) continue;
|
|
156
|
+
const check = createCheck(checkDef, file, config, offenses, dependencies, validateJSON);
|
|
157
|
+
pipelines.push(checkYAMLFile(check, file));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
139
162
|
}
|
|
140
163
|
}
|
|
141
164
|
|
|
@@ -210,7 +233,7 @@ function createCheck<S extends SourceCodeType>(
|
|
|
210
233
|
return check.create(context as any) as Check<S>;
|
|
211
234
|
}
|
|
212
235
|
|
|
213
|
-
function filesOfType<S extends SourceCodeType>(type: S, sourceCodes:
|
|
236
|
+
function filesOfType<S extends SourceCodeType>(type: S, sourceCodes: App): SourceCode<S>[] {
|
|
214
237
|
return sourceCodes.filter((file): file is SourceCode<S> => file.type === type);
|
|
215
238
|
}
|
|
216
239
|
|
|
@@ -232,3 +255,10 @@ async function checkLiquidFile(check: LiquidCheck, file: LiquidSourceCode): Prom
|
|
|
232
255
|
if (Object.keys(check).length > 0) await visitLiquid(file.ast, check);
|
|
233
256
|
if (check.onCodePathEnd) await check.onCodePathEnd(file as typeof file & { ast: LiquidHtmlNode });
|
|
234
257
|
}
|
|
258
|
+
|
|
259
|
+
async function checkYAMLFile(check: YAMLCheck, file: YAMLSourceCode): Promise<void> {
|
|
260
|
+
if (check.onCodePathStart) await check.onCodePathStart(file);
|
|
261
|
+
if (file.ast instanceof Error) return;
|
|
262
|
+
if (Object.keys(check).length > 0) await visitJSON(file.ast, check as any);
|
|
263
|
+
if (check.onCodePathEnd) await check.onCodePathEnd(file as typeof file & { ast: JSONNode });
|
|
264
|
+
}
|
package/src/jsonc/parse.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class JSONCParseErrors extends Error {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* At some point, we started supporting JSONC.
|
|
23
|
+
* At some point, we started supporting JSONC. App Check 2 was built on top of
|
|
24
24
|
* `json-to-ast` which does not support comments.
|
|
25
25
|
*
|
|
26
26
|
* This little adapter here will take a tree we get from `jsonc-parser` and
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { applyFixToString, createCorrector } from '../fixes';
|
|
3
3
|
import { makeAddArgumentCorrector, makeRemoveArgumentCorrector } from './arguments';
|
|
4
|
-
import {
|
|
4
|
+
import { DocumentNode, LiquidTag, RenderMarkup } from '@platformos/liquid-html-parser';
|
|
5
5
|
import { SourceCodeType, toLiquidHTMLAST } from '..';
|
|
6
6
|
|
|
7
7
|
describe('Arguments', () => {
|
|
@@ -15,53 +15,45 @@ describe('Arguments', () => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
it('should suggest adding missing required arguments when none already exist', () => {
|
|
18
|
-
const node =
|
|
19
|
-
`{% content_for 'block', type: 'swatches', id: 'fake', some-arg: '' %}`,
|
|
20
|
-
);
|
|
18
|
+
const node = makeRenderMarkup(`{% render 'partial', some-arg: '' %}`);
|
|
21
19
|
|
|
22
20
|
const fixer = createCorrector(SourceCodeType.LiquidHtml, node.source);
|
|
23
21
|
|
|
24
22
|
makeAddArgumentCorrector(node, requiredParam)(fixer);
|
|
25
23
|
|
|
26
24
|
expect(applyFixToString(node.source, fixer.fix)).toBe(
|
|
27
|
-
`{%
|
|
25
|
+
`{% render 'partial', some-arg: '', required_string: '' %}`,
|
|
28
26
|
);
|
|
29
27
|
});
|
|
30
28
|
|
|
31
29
|
it('should suggest adding missing required arguments and correcting trailing comma + whitespace', () => {
|
|
32
|
-
const node =
|
|
33
|
-
`{% content_for 'block', type: 'swatches', id: 'fake', some-arg: '', %}`,
|
|
34
|
-
);
|
|
30
|
+
const node = makeRenderMarkup(`{% render 'partial', some-arg: '', %}`);
|
|
35
31
|
|
|
36
32
|
const fixer = createCorrector(SourceCodeType.LiquidHtml, node.source);
|
|
37
33
|
|
|
38
34
|
makeAddArgumentCorrector(node, requiredParam)(fixer);
|
|
39
35
|
|
|
40
36
|
expect(applyFixToString(node.source, fixer.fix)).toBe(
|
|
41
|
-
`{%
|
|
37
|
+
`{% render 'partial', some-arg: '', required_string: '' %}`,
|
|
42
38
|
);
|
|
43
39
|
});
|
|
44
40
|
|
|
45
41
|
it('should suggest adding missing required arguments and correcting trailing spaces + comma', () => {
|
|
46
|
-
const node =
|
|
47
|
-
`{% content_for 'block', type: 'swatches', id: 'fake', some-arg: '' , %}`,
|
|
48
|
-
);
|
|
42
|
+
const node = makeRenderMarkup(`{% render 'partial', some-arg: '' , %}`);
|
|
49
43
|
|
|
50
44
|
const fixer = createCorrector(SourceCodeType.LiquidHtml, node.source);
|
|
51
45
|
|
|
52
46
|
makeAddArgumentCorrector(node, requiredParam)(fixer);
|
|
53
47
|
|
|
54
48
|
expect(applyFixToString(node.source, fixer.fix)).toBe(
|
|
55
|
-
`{%
|
|
49
|
+
`{% render 'partial', some-arg: '', required_string: '' %}`,
|
|
56
50
|
);
|
|
57
51
|
});
|
|
58
52
|
});
|
|
59
53
|
|
|
60
54
|
describe('makeRemoveArgumentCorrector', () => {
|
|
61
55
|
it("should remove the last argument and it's leading comma", () => {
|
|
62
|
-
const node =
|
|
63
|
-
`{% content_for 'block', type: 'swatches', id: 'fake', some-arg: '' %}`,
|
|
64
|
-
);
|
|
56
|
+
const node = makeRenderMarkup(`{% render 'partial', id: 'fake', some-arg: '' %}`);
|
|
65
57
|
|
|
66
58
|
const argToRemove = node.args.at(-1)!;
|
|
67
59
|
|
|
@@ -69,15 +61,11 @@ describe('Arguments', () => {
|
|
|
69
61
|
|
|
70
62
|
makeRemoveArgumentCorrector(node, argToRemove)(fixer);
|
|
71
63
|
|
|
72
|
-
expect(applyFixToString(node.source, fixer.fix)).toBe(
|
|
73
|
-
`{% content_for 'block', type: 'swatches', id: 'fake' %}`,
|
|
74
|
-
);
|
|
64
|
+
expect(applyFixToString(node.source, fixer.fix)).toBe(`{% render 'partial', id: 'fake' %}`);
|
|
75
65
|
});
|
|
76
66
|
|
|
77
67
|
it('should remove an argument in the middle', () => {
|
|
78
|
-
const node =
|
|
79
|
-
`{% content_for 'block', type: 'swatches', id: 'fake', some-arg: '' %}`,
|
|
80
|
-
);
|
|
68
|
+
const node = makeRenderMarkup(`{% render 'partial', id: 'fake', some-arg: '' %}`);
|
|
81
69
|
|
|
82
70
|
const argToRemove = node.args.at(-2)!;
|
|
83
71
|
|
|
@@ -85,15 +73,11 @@ describe('Arguments', () => {
|
|
|
85
73
|
|
|
86
74
|
makeRemoveArgumentCorrector(node, argToRemove)(fixer);
|
|
87
75
|
|
|
88
|
-
expect(applyFixToString(node.source, fixer.fix)).toBe(
|
|
89
|
-
`{% content_for 'block', type: 'swatches', some-arg: '' %}`,
|
|
90
|
-
);
|
|
76
|
+
expect(applyFixToString(node.source, fixer.fix)).toBe(`{% render 'partial', some-arg: '' %}`);
|
|
91
77
|
});
|
|
92
78
|
|
|
93
79
|
it('should remove an argument with trailing comma', () => {
|
|
94
|
-
const node =
|
|
95
|
-
`{% content_for 'block', type: 'swatches', id: 'fake', some-arg: '', %}`,
|
|
96
|
-
);
|
|
80
|
+
const node = makeRenderMarkup(`{% render 'partial', id: 'fake', some-arg: '', %}`);
|
|
97
81
|
|
|
98
82
|
const argToRemove = node.args.at(-1)!;
|
|
99
83
|
|
|
@@ -101,16 +85,12 @@ describe('Arguments', () => {
|
|
|
101
85
|
|
|
102
86
|
makeRemoveArgumentCorrector(node, argToRemove)(fixer);
|
|
103
87
|
|
|
104
|
-
expect(applyFixToString(node.source, fixer.fix)).toBe(
|
|
105
|
-
`{% content_for 'block', type: 'swatches', id: 'fake' %}`,
|
|
106
|
-
);
|
|
88
|
+
expect(applyFixToString(node.source, fixer.fix)).toBe(`{% render 'partial', id: 'fake' %}`);
|
|
107
89
|
});
|
|
108
90
|
});
|
|
109
91
|
|
|
110
92
|
it('should remove an argument with trailing space', () => {
|
|
111
|
-
const node =
|
|
112
|
-
`{% content_for 'block', type: 'swatches', id: 'fake' , some-arg: '' %}`,
|
|
113
|
-
);
|
|
93
|
+
const node = makeRenderMarkup(`{% render 'partial', id: 'fake' , some-arg: '' %}`);
|
|
114
94
|
|
|
115
95
|
const argToRemove = node.args.at(-2)!;
|
|
116
96
|
|
|
@@ -118,15 +98,11 @@ describe('Arguments', () => {
|
|
|
118
98
|
|
|
119
99
|
makeRemoveArgumentCorrector(node, argToRemove)(fixer);
|
|
120
100
|
|
|
121
|
-
expect(applyFixToString(node.source, fixer.fix)).toBe(
|
|
122
|
-
`{% content_for 'block', type: 'swatches', some-arg: '' %}`,
|
|
123
|
-
);
|
|
101
|
+
expect(applyFixToString(node.source, fixer.fix)).toBe(`{% render 'partial', some-arg: '' %}`);
|
|
124
102
|
});
|
|
125
103
|
|
|
126
104
|
it('should remove an argument with leading space', () => {
|
|
127
|
-
const node =
|
|
128
|
-
`{% content_for 'block', type: 'swatches', id: 'fake', some-arg: '' %}`,
|
|
129
|
-
);
|
|
105
|
+
const node = makeRenderMarkup(`{% render 'partial', id: 'fake', some-arg: '' %}`);
|
|
130
106
|
|
|
131
107
|
const argToRemove = node.args.at(-1)!;
|
|
132
108
|
|
|
@@ -134,13 +110,11 @@ describe('Arguments', () => {
|
|
|
134
110
|
|
|
135
111
|
makeRemoveArgumentCorrector(node, argToRemove)(fixer);
|
|
136
112
|
|
|
137
|
-
expect(applyFixToString(node.source, fixer.fix)).toBe(
|
|
138
|
-
`{% content_for 'block', type: 'swatches', id: 'fake' %}`,
|
|
139
|
-
);
|
|
113
|
+
expect(applyFixToString(node.source, fixer.fix)).toBe(`{% render 'partial', id: 'fake' %}`);
|
|
140
114
|
});
|
|
141
115
|
});
|
|
142
116
|
|
|
143
|
-
function
|
|
117
|
+
function makeRenderMarkup(source: string): RenderMarkup {
|
|
144
118
|
const ast = toLiquidHTMLAST(source) as DocumentNode;
|
|
145
|
-
return (ast.children[0] as LiquidTag).markup as
|
|
119
|
+
return (ast.children[0] as LiquidTag).markup as RenderMarkup;
|
|
146
120
|
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* errors when LiquidDoc exists
|
|
4
4
|
*/
|
|
5
5
|
import {
|
|
6
|
-
ContentForMarkup,
|
|
7
6
|
RenderMarkup,
|
|
8
7
|
FunctionMarkup,
|
|
9
8
|
LiquidNamedArgument,
|
|
@@ -17,20 +16,21 @@ import {
|
|
|
17
16
|
isTypeCompatible,
|
|
18
17
|
} from './utils';
|
|
19
18
|
import { isLiquidString } from '../checks/utils';
|
|
19
|
+
import { DocumentsLocator } from '@platformos/platformos-common';
|
|
20
|
+
import { URI } from 'vscode-uri';
|
|
21
|
+
import { relative } from '../path';
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Report error when unknown arguments are provided for `content_for` tag or `render` tag
|
|
23
25
|
*/
|
|
24
26
|
export function reportUnknownArguments(
|
|
25
27
|
context: Context<SourceCodeType.LiquidHtml>,
|
|
26
|
-
node:
|
|
28
|
+
node: RenderMarkup | FunctionMarkup,
|
|
27
29
|
unknownProvidedArgs: LiquidNamedArgument[],
|
|
28
30
|
name: string,
|
|
29
31
|
) {
|
|
30
32
|
let errorOwnerMessage = '';
|
|
31
|
-
if (node.type === NodeTypes.
|
|
32
|
-
errorOwnerMessage = ` in content_for tag for static block '${name}'`;
|
|
33
|
-
} else if (node.type === NodeTypes.RenderMarkup) {
|
|
33
|
+
if (node.type === NodeTypes.RenderMarkup) {
|
|
34
34
|
errorOwnerMessage = ` in render tag for partial '${name}'`;
|
|
35
35
|
} else if (node.type === NodeTypes.FunctionMarkup) {
|
|
36
36
|
errorOwnerMessage = ` in function tag for partial '${name}'`;
|
|
@@ -56,14 +56,12 @@ export function reportUnknownArguments(
|
|
|
56
56
|
*/
|
|
57
57
|
export function reportMissingArguments(
|
|
58
58
|
context: Context<SourceCodeType.LiquidHtml>,
|
|
59
|
-
node:
|
|
59
|
+
node: RenderMarkup | FunctionMarkup,
|
|
60
60
|
missingRequiredArgs: LiquidDocParameter[],
|
|
61
61
|
name: string,
|
|
62
62
|
) {
|
|
63
63
|
let errorOwnerMessage = '';
|
|
64
|
-
if (node.type === NodeTypes.
|
|
65
|
-
errorOwnerMessage = ` in content_for tag for static block '${name}'`;
|
|
66
|
-
} else if (node.type === NodeTypes.RenderMarkup) {
|
|
64
|
+
if (node.type === NodeTypes.RenderMarkup) {
|
|
67
65
|
errorOwnerMessage = ` in render tag for partial '${name}'`;
|
|
68
66
|
} else if (node.type === NodeTypes.FunctionMarkup) {
|
|
69
67
|
errorOwnerMessage = ` in function tag for partial '${name}'`;
|
|
@@ -86,14 +84,12 @@ export function reportMissingArguments(
|
|
|
86
84
|
|
|
87
85
|
export function reportDuplicateArguments(
|
|
88
86
|
context: Context<SourceCodeType.LiquidHtml>,
|
|
89
|
-
node:
|
|
87
|
+
node: RenderMarkup | FunctionMarkup,
|
|
90
88
|
duplicateArgs: LiquidNamedArgument[],
|
|
91
89
|
name: string,
|
|
92
90
|
) {
|
|
93
91
|
let errorOwnerMessage = '';
|
|
94
|
-
if (node.type === NodeTypes.
|
|
95
|
-
errorOwnerMessage = ` in content_for tag for static block '${name}'`;
|
|
96
|
-
} else if (node.type === NodeTypes.RenderMarkup) {
|
|
92
|
+
if (node.type === NodeTypes.RenderMarkup) {
|
|
97
93
|
errorOwnerMessage = ` in render tag for partial '${name}'`;
|
|
98
94
|
} else if (node.type === NodeTypes.FunctionMarkup) {
|
|
99
95
|
errorOwnerMessage = ` in function tag for partial '${name}'`;
|
|
@@ -125,7 +121,13 @@ export function findTypeMismatchParams(
|
|
|
125
121
|
const typeMismatchParams: LiquidNamedArgument[] = [];
|
|
126
122
|
|
|
127
123
|
for (const arg of providedParams) {
|
|
128
|
-
if (
|
|
124
|
+
// Skip if the value is a variable lookup (can't determine type statically)
|
|
125
|
+
// or if it has filters (graphql args may have filters, output type is unknown)
|
|
126
|
+
if (arg.value.type === NodeTypes.LiquidVariable) {
|
|
127
|
+
if (arg.value.expression.type === NodeTypes.VariableLookup || arg.value.filters.length > 0) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
} else if (arg.value.type === NodeTypes.VariableLookup) {
|
|
129
131
|
continue;
|
|
130
132
|
}
|
|
131
133
|
|
|
@@ -208,35 +210,18 @@ export function generateTypeMismatchSuggestions(
|
|
|
208
210
|
return suggestions;
|
|
209
211
|
}
|
|
210
212
|
|
|
211
|
-
function isLastArg(
|
|
212
|
-
node: RenderMarkup | ContentForMarkup | FunctionMarkup,
|
|
213
|
-
arg: LiquidNamedArgument,
|
|
214
|
-
): boolean {
|
|
213
|
+
function isLastArg(node: RenderMarkup | FunctionMarkup, arg: LiquidNamedArgument): boolean {
|
|
215
214
|
return (
|
|
216
215
|
node.args.length == 1 || arg.position.start == node.args[node.args.length - 1].position.start
|
|
217
216
|
);
|
|
218
217
|
}
|
|
219
218
|
|
|
220
|
-
export function getBlockName(node: ContentForMarkup) {
|
|
221
|
-
if (node.contentForType.value !== 'block') {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const contentForTypeArg = node.args.find((arg) => arg.name == 'type')?.value;
|
|
226
|
-
|
|
227
|
-
if (!contentForTypeArg || !isLiquidString(contentForTypeArg)) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return contentForTypeArg.value;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
219
|
export function getPartialName(node: RenderMarkup | FunctionMarkup): string | undefined {
|
|
235
220
|
if (node.type === NodeTypes.RenderMarkup) {
|
|
236
|
-
if (!isLiquidString(node.
|
|
221
|
+
if (!isLiquidString(node.partial)) {
|
|
237
222
|
return;
|
|
238
223
|
}
|
|
239
|
-
return node.
|
|
224
|
+
return node.partial.value;
|
|
240
225
|
}
|
|
241
226
|
|
|
242
227
|
if (node.type === NodeTypes.FunctionMarkup) {
|
|
@@ -249,19 +234,27 @@ export function getPartialName(node: RenderMarkup | FunctionMarkup): string | un
|
|
|
249
234
|
|
|
250
235
|
export async function getLiquidDocParams(
|
|
251
236
|
context: Context<SourceCodeType.LiquidHtml>,
|
|
252
|
-
|
|
237
|
+
partialName: string,
|
|
253
238
|
) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
239
|
+
if (!context.getDocDefinition) return;
|
|
240
|
+
|
|
241
|
+
// Use DocumentsLocator to find the partial across all platformOS locations,
|
|
242
|
+
// including app/views/partials/, app/lib/, and module paths.
|
|
243
|
+
const locator = new DocumentsLocator(context.fs);
|
|
244
|
+
const fileUri = await locator.locate(URI.parse(context.config.rootUri), 'render', partialName);
|
|
245
|
+
if (!fileUri) return undefined;
|
|
246
|
+
|
|
247
|
+
const relativePath = relative(fileUri, context.config.rootUri);
|
|
248
|
+
const docDefinition = await context.getDocDefinition(relativePath);
|
|
249
|
+
if (docDefinition?.liquidDoc?.parameters) {
|
|
250
|
+
return new Map(docDefinition.liquidDoc.parameters.map((p) => [p.name, p]));
|
|
258
251
|
}
|
|
259
252
|
|
|
260
|
-
return
|
|
253
|
+
return undefined;
|
|
261
254
|
}
|
|
262
255
|
|
|
263
256
|
export function makeRemoveArgumentCorrector(
|
|
264
|
-
node:
|
|
257
|
+
node: RenderMarkup | FunctionMarkup,
|
|
265
258
|
arg: LiquidNamedArgument,
|
|
266
259
|
) {
|
|
267
260
|
return (fixer: StringCorrector) => {
|
|
@@ -287,7 +280,7 @@ export function makeRemoveArgumentCorrector(
|
|
|
287
280
|
}
|
|
288
281
|
|
|
289
282
|
export function makeAddArgumentCorrector(
|
|
290
|
-
node:
|
|
283
|
+
node: RenderMarkup | FunctionMarkup,
|
|
291
284
|
arg: LiquidDocParameter,
|
|
292
285
|
) {
|
|
293
286
|
return (fixer: StringCorrector) => {
|
|
@@ -238,7 +238,7 @@ describe('Unit: extractDocDefinition', () => {
|
|
|
238
238
|
});
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
-
it('should return
|
|
241
|
+
it('should return partialDefinition without liquidDoc property if doc header is not present', async () => {
|
|
242
242
|
const ast = toAST(`
|
|
243
243
|
<div>No doc header here</div>
|
|
244
244
|
`);
|
package/src/liquid-doc/utils.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { LiquidExpression, NodeTypes } from '@platformos/liquid-html-parser';
|
|
1
|
+
import { LiquidExpression, LiquidVariable, NodeTypes } from '@platformos/liquid-html-parser';
|
|
2
2
|
import { assertNever } from '../utils';
|
|
3
|
-
import {
|
|
4
|
-
import { isBlock } from '../to-schema';
|
|
3
|
+
import { isPartial } from '../path';
|
|
5
4
|
import { ObjectEntry, UriString } from '../types';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* The base set of supported param types for LiquidDoc.
|
|
9
8
|
*
|
|
10
|
-
* This is used in conjunction with objects defined in [liquid docs](https://
|
|
9
|
+
* This is used in conjunction with objects defined in [liquid docs](https://documentation.platformos.com/api-reference/liquid/objects)
|
|
11
10
|
* to determine ALL supported param types for LiquidDoc.
|
|
12
11
|
*
|
|
13
12
|
* References `getValidParamTypes`
|
|
@@ -36,7 +35,7 @@ export function getDefaultValueForType(type: string | null) {
|
|
|
36
35
|
return '0';
|
|
37
36
|
case BasicParamTypes.Boolean:
|
|
38
37
|
return 'false';
|
|
39
|
-
case BasicParamTypes.Object: // Objects don't have a sensible default value
|
|
38
|
+
case BasicParamTypes.Object: // Objects don't have a sensible default value
|
|
40
39
|
default:
|
|
41
40
|
return '';
|
|
42
41
|
}
|
|
@@ -45,7 +44,15 @@ export function getDefaultValueForType(type: string | null) {
|
|
|
45
44
|
/**
|
|
46
45
|
* Casts the value of a LiquidNamedArgument to a string representing the type of the value.
|
|
47
46
|
*/
|
|
48
|
-
export function inferArgumentType(arg: LiquidExpression): BasicParamTypes {
|
|
47
|
+
export function inferArgumentType(arg: LiquidExpression | LiquidVariable): BasicParamTypes {
|
|
48
|
+
if (arg.type === NodeTypes.LiquidVariable) {
|
|
49
|
+
// A variable with filters — delegate to the base expression if there are no filters,
|
|
50
|
+
// otherwise we can't statically determine the filtered output type.
|
|
51
|
+
if (arg.filters.length > 0) return BasicParamTypes.Object;
|
|
52
|
+
const expr = arg.expression;
|
|
53
|
+
if (expr.type === NodeTypes.BooleanExpression) return BasicParamTypes.Object;
|
|
54
|
+
return inferArgumentType(expr);
|
|
55
|
+
}
|
|
49
56
|
switch (arg.type) {
|
|
50
57
|
case NodeTypes.String:
|
|
51
58
|
return BasicParamTypes.String;
|
|
@@ -55,6 +62,8 @@ export function inferArgumentType(arg: LiquidExpression): BasicParamTypes {
|
|
|
55
62
|
return BasicParamTypes.Boolean;
|
|
56
63
|
case NodeTypes.Range:
|
|
57
64
|
case NodeTypes.VariableLookup:
|
|
65
|
+
case NodeTypes.JsonHashLiteral:
|
|
66
|
+
case NodeTypes.JsonArrayLiteral:
|
|
58
67
|
return BasicParamTypes.Object;
|
|
59
68
|
default:
|
|
60
69
|
// This ensures that we have a case for every possible type for arg.value
|
|
@@ -81,12 +90,12 @@ export function isTypeCompatible(expectedType: string, actualType: BasicParamTyp
|
|
|
81
90
|
* Checks if the provided file path supports the LiquidDoc tag.
|
|
82
91
|
*/
|
|
83
92
|
export function filePathSupportsLiquidDoc(uri: UriString) {
|
|
84
|
-
return
|
|
93
|
+
return isPartial(uri);
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
/**
|
|
88
97
|
* Dynamically generates a map of LiquidDoc param types using object entries from
|
|
89
|
-
* [liquid docs](https://
|
|
98
|
+
* [liquid docs](https://documentation.platformos.com/api-reference/liquid/objects).
|
|
90
99
|
*
|
|
91
100
|
* This is used in conjunction with the base set of supported param.
|
|
92
101
|
*
|
package/src/path.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { RelativePath, UriString } from './types';
|
|
2
2
|
import { URI, Utils } from 'vscode-uri';
|
|
3
|
+
export {
|
|
4
|
+
isPartial,
|
|
5
|
+
isLayout,
|
|
6
|
+
isPage,
|
|
7
|
+
isAuthorization,
|
|
8
|
+
isEmail,
|
|
9
|
+
isApiCall,
|
|
10
|
+
isSms,
|
|
11
|
+
isMigration,
|
|
12
|
+
isKnownLiquidFile,
|
|
13
|
+
getFileType,
|
|
14
|
+
getAppPaths,
|
|
15
|
+
getModulePaths,
|
|
16
|
+
PlatformOSFileType,
|
|
17
|
+
FILE_TYPE_DIRS,
|
|
18
|
+
} from '@platformos/platformos-common';
|
|
3
19
|
|
|
4
20
|
export { URI, Utils };
|
|
5
21
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example
|
|
3
|
+
* {
|
|
4
|
+
* 'app/views/layouts/layout.liquid': `
|
|
5
|
+
* <html>
|
|
6
|
+
* {{ content_for_page }}
|
|
7
|
+
* </html>
|
|
8
|
+
* `,
|
|
9
|
+
* 'app/views/partials/snip.liquid': `
|
|
10
|
+
* <b>'hello world'</b>
|
|
11
|
+
* `,
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export type MockApp = {
|
|
16
|
+
[relativePath in string]: string;
|
|
17
|
+
};
|