@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
package/src/index.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
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
|
-
makeGetMetafieldDefinitions,
|
|
11
8
|
} from './context-utils';
|
|
12
9
|
import { createDisabledChecksModule } from './disabled-checks';
|
|
13
10
|
import { isIgnored } from './ignore';
|
|
@@ -35,13 +32,16 @@ import {
|
|
|
35
32
|
Settings,
|
|
36
33
|
SourceCode,
|
|
37
34
|
SourceCodeType,
|
|
38
|
-
|
|
35
|
+
App,
|
|
39
36
|
ValidateJSON,
|
|
37
|
+
YAMLCheck,
|
|
38
|
+
YAMLSourceCode,
|
|
40
39
|
} from './types';
|
|
41
40
|
import { getPosition } from './utils';
|
|
42
41
|
import { visitJSON, visitLiquid } from './visitors';
|
|
43
42
|
|
|
44
|
-
export * from './
|
|
43
|
+
export * from './AugmentedPlatformOSDocset';
|
|
44
|
+
export * from './types/platformos-liquid-docs';
|
|
45
45
|
export * from './checks';
|
|
46
46
|
export * from './context-utils';
|
|
47
47
|
export * from './find-root';
|
|
@@ -50,7 +50,6 @@ export * from './ignore';
|
|
|
50
50
|
export * from './json';
|
|
51
51
|
export * from './JSONValidator';
|
|
52
52
|
export * as path from './path';
|
|
53
|
-
export * from './to-schema';
|
|
54
53
|
export * from './to-source-code';
|
|
55
54
|
export * from './types';
|
|
56
55
|
export * from './utils/error';
|
|
@@ -60,7 +59,6 @@ export * from './utils/types';
|
|
|
60
59
|
export * from './utils/object';
|
|
61
60
|
export * from './visitor';
|
|
62
61
|
export * from './liquid-doc/liquidDoc';
|
|
63
|
-
export { getBlockName } from './liquid-doc/arguments';
|
|
64
62
|
export * from './liquid-doc/utils';
|
|
65
63
|
|
|
66
64
|
const defaultErrorHandler = (_error: Error): void => {
|
|
@@ -68,7 +66,7 @@ const defaultErrorHandler = (_error: Error): void => {
|
|
|
68
66
|
};
|
|
69
67
|
|
|
70
68
|
export async function check(
|
|
71
|
-
|
|
69
|
+
app: App,
|
|
72
70
|
config: Config,
|
|
73
71
|
injectedDependencies: Dependencies,
|
|
74
72
|
): Promise<Offense[]> {
|
|
@@ -78,15 +76,10 @@ export async function check(
|
|
|
78
76
|
const { rootUri } = config;
|
|
79
77
|
const dependencies: AugmentedDependencies = {
|
|
80
78
|
...injectedDependencies,
|
|
81
|
-
mode: config.context,
|
|
82
79
|
fileExists: makeFileExists(fs),
|
|
83
80
|
fileSize: makeFileSize(fs),
|
|
84
81
|
getDefaultLocale: makeGetDefaultLocale(fs, rootUri),
|
|
85
|
-
getDefaultTranslations: makeGetDefaultTranslations(fs,
|
|
86
|
-
getDefaultSchemaLocale: makeGetDefaultSchemaLocale(fs, rootUri),
|
|
87
|
-
getDefaultSchemaTranslations: makeGetDefaultSchemaTranslations(fs, theme, rootUri),
|
|
88
|
-
getMetafieldDefinitions:
|
|
89
|
-
injectedDependencies.getMetafieldDefinitions ?? makeGetMetafieldDefinitions(fs),
|
|
82
|
+
getDefaultTranslations: makeGetDefaultTranslations(fs, app, rootUri),
|
|
90
83
|
};
|
|
91
84
|
|
|
92
85
|
const { DisabledChecksVisitor, isDisabled } = createDisabledChecksModule();
|
|
@@ -94,14 +87,14 @@ export async function check(
|
|
|
94
87
|
const validateJSON = jsonValidator?.validate;
|
|
95
88
|
|
|
96
89
|
// We're memozing those deps here because they shouldn't change within a run.
|
|
97
|
-
if (dependencies.
|
|
98
|
-
dependencies.
|
|
90
|
+
if (dependencies.platformosDocset && !dependencies.platformosDocset.isAugmented) {
|
|
91
|
+
dependencies.platformosDocset = new AugmentedPlatformOSDocset(dependencies.platformosDocset);
|
|
99
92
|
}
|
|
100
93
|
|
|
101
94
|
for (const type of Object.values(SourceCodeType)) {
|
|
102
95
|
switch (type) {
|
|
103
96
|
case SourceCodeType.JSON: {
|
|
104
|
-
const files = filesOfType(type,
|
|
97
|
+
const files = filesOfType(type, app);
|
|
105
98
|
const checkDefs = checksOfType(type, config.checks);
|
|
106
99
|
for (const file of files) {
|
|
107
100
|
for (const checkDef of checkDefs) {
|
|
@@ -113,7 +106,7 @@ export async function check(
|
|
|
113
106
|
break;
|
|
114
107
|
}
|
|
115
108
|
case SourceCodeType.GraphQL: {
|
|
116
|
-
const files = filesOfType(type,
|
|
109
|
+
const files = filesOfType(type, app);
|
|
117
110
|
const checkDefs = checksOfType(type, config.checks);
|
|
118
111
|
for (const file of files) {
|
|
119
112
|
for (const checkDef of checkDefs) {
|
|
@@ -125,7 +118,7 @@ export async function check(
|
|
|
125
118
|
break;
|
|
126
119
|
}
|
|
127
120
|
case SourceCodeType.LiquidHtml: {
|
|
128
|
-
const files = filesOfType(type,
|
|
121
|
+
const files = filesOfType(type, app);
|
|
129
122
|
const checkDefs = [DisabledChecksVisitor, ...checksOfType(type, config.checks)];
|
|
130
123
|
for (const file of files) {
|
|
131
124
|
for (const checkDef of checkDefs) {
|
|
@@ -136,6 +129,18 @@ export async function check(
|
|
|
136
129
|
}
|
|
137
130
|
break;
|
|
138
131
|
}
|
|
132
|
+
case SourceCodeType.YAML: {
|
|
133
|
+
const files = filesOfType(type, app);
|
|
134
|
+
const checkDefs = checksOfType(type, config.checks);
|
|
135
|
+
for (const file of files) {
|
|
136
|
+
for (const checkDef of checkDefs) {
|
|
137
|
+
if (isIgnored(file.uri, config, checkDef)) continue;
|
|
138
|
+
const check = createCheck(checkDef, file, config, offenses, dependencies, validateJSON);
|
|
139
|
+
pipelines.push(checkYAMLFile(check, file));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
139
144
|
}
|
|
140
145
|
}
|
|
141
146
|
|
|
@@ -210,7 +215,7 @@ function createCheck<S extends SourceCodeType>(
|
|
|
210
215
|
return check.create(context as any) as Check<S>;
|
|
211
216
|
}
|
|
212
217
|
|
|
213
|
-
function filesOfType<S extends SourceCodeType>(type: S, sourceCodes:
|
|
218
|
+
function filesOfType<S extends SourceCodeType>(type: S, sourceCodes: App): SourceCode<S>[] {
|
|
214
219
|
return sourceCodes.filter((file): file is SourceCode<S> => file.type === type);
|
|
215
220
|
}
|
|
216
221
|
|
|
@@ -232,3 +237,10 @@ async function checkLiquidFile(check: LiquidCheck, file: LiquidSourceCode): Prom
|
|
|
232
237
|
if (Object.keys(check).length > 0) await visitLiquid(file.ast, check);
|
|
233
238
|
if (check.onCodePathEnd) await check.onCodePathEnd(file as typeof file & { ast: LiquidHtmlNode });
|
|
234
239
|
}
|
|
240
|
+
|
|
241
|
+
async function checkYAMLFile(check: YAMLCheck, file: YAMLSourceCode): Promise<void> {
|
|
242
|
+
if (check.onCodePathStart) await check.onCodePathStart(file);
|
|
243
|
+
if (file.ast instanceof Error) return;
|
|
244
|
+
if (Object.keys(check).length > 0) await visitJSON(file.ast, check as any);
|
|
245
|
+
if (check.onCodePathEnd) await check.onCodePathEnd(file as typeof file & { ast: JSONNode });
|
|
246
|
+
}
|
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}'`;
|
|
@@ -208,29 +204,12 @@ export function generateTypeMismatchSuggestions(
|
|
|
208
204
|
return suggestions;
|
|
209
205
|
}
|
|
210
206
|
|
|
211
|
-
function isLastArg(
|
|
212
|
-
node: RenderMarkup | ContentForMarkup | FunctionMarkup,
|
|
213
|
-
arg: LiquidNamedArgument,
|
|
214
|
-
): boolean {
|
|
207
|
+
function isLastArg(node: RenderMarkup | FunctionMarkup, arg: LiquidNamedArgument): boolean {
|
|
215
208
|
return (
|
|
216
209
|
node.args.length == 1 || arg.position.start == node.args[node.args.length - 1].position.start
|
|
217
210
|
);
|
|
218
211
|
}
|
|
219
212
|
|
|
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
213
|
export function getPartialName(node: RenderMarkup | FunctionMarkup): string | undefined {
|
|
235
214
|
if (node.type === NodeTypes.RenderMarkup) {
|
|
236
215
|
if (!isLiquidString(node.snippet)) {
|
|
@@ -249,19 +228,27 @@ export function getPartialName(node: RenderMarkup | FunctionMarkup): string | un
|
|
|
249
228
|
|
|
250
229
|
export async function getLiquidDocParams(
|
|
251
230
|
context: Context<SourceCodeType.LiquidHtml>,
|
|
252
|
-
|
|
231
|
+
partialName: string,
|
|
253
232
|
) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
233
|
+
if (!context.getDocDefinition) return;
|
|
234
|
+
|
|
235
|
+
// Use DocumentsLocator to find the partial across all platformOS locations,
|
|
236
|
+
// including app/views/partials/, app/lib/, and module paths.
|
|
237
|
+
const locator = new DocumentsLocator(context.fs);
|
|
238
|
+
const fileUri = await locator.locate(URI.parse(context.config.rootUri), 'render', partialName);
|
|
239
|
+
if (!fileUri) return undefined;
|
|
240
|
+
|
|
241
|
+
const relativePath = relative(fileUri, context.config.rootUri);
|
|
242
|
+
const docDefinition = await context.getDocDefinition(relativePath);
|
|
243
|
+
if (docDefinition?.liquidDoc?.parameters) {
|
|
244
|
+
return new Map(docDefinition.liquidDoc.parameters.map((p) => [p.name, p]));
|
|
258
245
|
}
|
|
259
246
|
|
|
260
|
-
return
|
|
247
|
+
return undefined;
|
|
261
248
|
}
|
|
262
249
|
|
|
263
250
|
export function makeRemoveArgumentCorrector(
|
|
264
|
-
node:
|
|
251
|
+
node: RenderMarkup | FunctionMarkup,
|
|
265
252
|
arg: LiquidNamedArgument,
|
|
266
253
|
) {
|
|
267
254
|
return (fixer: StringCorrector) => {
|
|
@@ -287,7 +274,7 @@ export function makeRemoveArgumentCorrector(
|
|
|
287
274
|
}
|
|
288
275
|
|
|
289
276
|
export function makeAddArgumentCorrector(
|
|
290
|
-
node:
|
|
277
|
+
node: RenderMarkup | FunctionMarkup,
|
|
291
278
|
arg: LiquidDocParameter,
|
|
292
279
|
) {
|
|
293
280
|
return (fixer: StringCorrector) => {
|
package/src/liquid-doc/utils.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LiquidExpression, 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
|
/**
|
|
@@ -55,6 +54,8 @@ export function inferArgumentType(arg: LiquidExpression): BasicParamTypes {
|
|
|
55
54
|
return BasicParamTypes.Boolean;
|
|
56
55
|
case NodeTypes.Range:
|
|
57
56
|
case NodeTypes.VariableLookup:
|
|
57
|
+
case NodeTypes.JsonHashLiteral:
|
|
58
|
+
case NodeTypes.JsonArrayLiteral:
|
|
58
59
|
return BasicParamTypes.Object;
|
|
59
60
|
default:
|
|
60
61
|
// This ensures that we have a case for every possible type for arg.value
|
|
@@ -81,7 +82,7 @@ export function isTypeCompatible(expectedType: string, actualType: BasicParamTyp
|
|
|
81
82
|
* Checks if the provided file path supports the LiquidDoc tag.
|
|
82
83
|
*/
|
|
83
84
|
export function filePathSupportsLiquidDoc(uri: UriString) {
|
|
84
|
-
return
|
|
85
|
+
return isPartial(uri);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
/**
|
package/src/path.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractFileSystem, FileStat, FileTuple, FileType } from '@platformos/platformos-common';
|
|
2
2
|
import { deepGet } from '../utils';
|
|
3
3
|
import { normalize, relative } from '../path';
|
|
4
|
-
import {
|
|
4
|
+
import { MockApp } from './MockApp';
|
|
5
5
|
import * as path from '../path';
|
|
6
6
|
|
|
7
7
|
interface FileTree {
|
|
@@ -11,16 +11,19 @@ interface FileTree {
|
|
|
11
11
|
export class MockFileSystem implements AbstractFileSystem {
|
|
12
12
|
private rootUri: string;
|
|
13
13
|
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
private mockApp: MockApp,
|
|
16
|
+
rootUri = 'file:///',
|
|
17
|
+
) {
|
|
15
18
|
this.rootUri = normalize(rootUri);
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
async readFile(uri: string): Promise<string> {
|
|
19
22
|
const relativePath = this.rootRelative(uri);
|
|
20
|
-
if (this.
|
|
23
|
+
if (this.mockApp[relativePath] === undefined) {
|
|
21
24
|
throw new Error('File not found');
|
|
22
25
|
} else {
|
|
23
|
-
return this.
|
|
26
|
+
return this.mockApp[relativePath];
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -47,7 +50,7 @@ export class MockFileSystem implements AbstractFileSystem {
|
|
|
47
50
|
|
|
48
51
|
async stat(uri: string): Promise<FileStat> {
|
|
49
52
|
const relativePath = this.rootRelative(uri);
|
|
50
|
-
const source = this.
|
|
53
|
+
const source = this.mockApp[relativePath];
|
|
51
54
|
if (source) {
|
|
52
55
|
return {
|
|
53
56
|
type: FileType.File,
|
|
@@ -68,7 +71,7 @@ export class MockFileSystem implements AbstractFileSystem {
|
|
|
68
71
|
|
|
69
72
|
private get fileTree(): FileTree {
|
|
70
73
|
const result: FileTree = {};
|
|
71
|
-
for (const [relativePath, source] of Object.entries(this.
|
|
74
|
+
for (const [relativePath, source] of Object.entries(this.mockApp)) {
|
|
72
75
|
const segments = relativePath.split('/');
|
|
73
76
|
let current = result;
|
|
74
77
|
for (let i = 0; i < segments.length - 1; i++) {
|
package/src/test/index.ts
CHANGED