@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/context-utils.ts
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractFileSystem, FileTuple, FileType, UriString } from '@platformos/platformos-common';
|
|
3
|
-
import { parseJSON } from './json';
|
|
4
|
-
import { join } from './path';
|
|
1
|
+
import { load } from 'js-yaml';
|
|
5
2
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from '
|
|
12
|
-
import {
|
|
3
|
+
AbstractFileSystem,
|
|
4
|
+
FileTuple,
|
|
5
|
+
FileType,
|
|
6
|
+
TranslationProvider,
|
|
7
|
+
UriString,
|
|
8
|
+
} from '@platformos/platformos-common';
|
|
9
|
+
import { URI } from 'vscode-uri';
|
|
10
|
+
import { join } from './path';
|
|
11
|
+
import { SourceCodeType, App, Translations } from './types';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns a function that loads and merges ALL translation files for a given
|
|
15
|
+
* locale within a specific translations base directory URI
|
|
16
|
+
* (e.g. `file:///app/translations` or
|
|
17
|
+
* `file:///modules/common-styling/public/translations`).
|
|
18
|
+
*
|
|
19
|
+
* Covers both the single-file layout (`{base}/{locale}.yml`) and the split-file
|
|
20
|
+
* layout (`{base}/{locale}/*.yml`).
|
|
21
|
+
*
|
|
22
|
+
* Only files whose first YAML key matches `locale` are included — this mirrors
|
|
23
|
+
* how platformOS determines a file's locale from its content, not its path.
|
|
24
|
+
*
|
|
25
|
+
* In-memory editor buffers take precedence over the filesystem so that unsaved
|
|
26
|
+
* changes are reflected immediately.
|
|
27
|
+
*/
|
|
28
|
+
export const makeGetTranslationsForBase = (fs: AbstractFileSystem, app: App) => {
|
|
29
|
+
const provider = new TranslationProvider(fs);
|
|
30
|
+
const cache = new Map<string, Promise<Translations>>();
|
|
31
|
+
|
|
32
|
+
return (translationBaseUri: string, locale: string): Promise<Translations> => {
|
|
33
|
+
const key = `${translationBaseUri}::${locale}`;
|
|
34
|
+
if (!cache.has(key)) {
|
|
35
|
+
const contentOverride = (uri: string): string | undefined =>
|
|
36
|
+
app.find((sc) => sc.type === SourceCodeType.YAML && sc.uri === uri)?.source;
|
|
37
|
+
|
|
38
|
+
cache.set(
|
|
39
|
+
key,
|
|
40
|
+
provider.loadAllTranslationsForBase(URI.parse(translationBaseUri), locale, contentOverride),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return cache.get(key)!;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
13
46
|
|
|
14
47
|
export type FileExists = (uri: string) => Promise<boolean>;
|
|
15
48
|
|
|
@@ -33,71 +66,49 @@ export const makeFileSize = (fs: AbstractFileSystem) =>
|
|
|
33
66
|
}
|
|
34
67
|
};
|
|
35
68
|
|
|
36
|
-
export const makeGetDefaultLocaleFileUri =
|
|
37
|
-
|
|
38
|
-
getDefaultLocaleFileUriFactoryFactory('.default.schema.json');
|
|
39
|
-
function getDefaultLocaleFileUriFactoryFactory(postfix = '.default.json') {
|
|
40
|
-
return function getDefaultLocaleFileUriFactory(fs: AbstractFileSystem) {
|
|
41
|
-
return (rootUri: string) => getDefaultLocaleFile(fs, rootUri, postfix);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
69
|
+
export const makeGetDefaultLocaleFileUri = (fs: AbstractFileSystem) => (rootUri: string) =>
|
|
70
|
+
getDefaultLocaleFile(fs, rootUri);
|
|
44
71
|
|
|
45
|
-
export const makeGetDefaultLocale =
|
|
46
|
-
|
|
47
|
-
function getDefaultLocaleFactoryFactory(postfix = '.default.json') {
|
|
48
|
-
return function getDefaultLocaleFactory(fs: AbstractFileSystem, rootUri: string) {
|
|
49
|
-
return cached(() => getDefaultLocale(fs, rootUri, postfix));
|
|
50
|
-
};
|
|
51
|
-
}
|
|
72
|
+
export const makeGetDefaultLocale = (fs: AbstractFileSystem, rootUri: string) =>
|
|
73
|
+
cached(() => getDefaultLocale(fs, rootUri));
|
|
52
74
|
|
|
53
|
-
export const makeGetDefaultTranslations =
|
|
54
|
-
|
|
55
|
-
getDefaultTranslationsFactoryFactory('.default.schema.json');
|
|
56
|
-
// prettier-ignore
|
|
57
|
-
function getDefaultTranslationsFactoryFactory(postfix = '.default.json') {
|
|
58
|
-
return function getDefaultTranslationsFactory(fs: AbstractFileSystem, theme: Theme, rootUri: string) {
|
|
59
|
-
return cached(() => getDefaultTranslations(fs, theme, rootUri, postfix));
|
|
60
|
-
};
|
|
61
|
-
}
|
|
75
|
+
export const makeGetDefaultTranslations = (fs: AbstractFileSystem, app: App, rootUri: string) =>
|
|
76
|
+
cached(() => getDefaultTranslations(fs, app, rootUri));
|
|
62
77
|
|
|
63
78
|
async function getDefaultLocaleFile(
|
|
64
79
|
fs: AbstractFileSystem,
|
|
65
80
|
rootUri: string,
|
|
66
|
-
|
|
67
|
-
)
|
|
68
|
-
const files = await fs.readDirectory(join(rootUri, 'locales'));
|
|
69
|
-
return files.find(([uri]) => uri.endsWith(postfix))?.[0];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function getDefaultLocale(
|
|
73
|
-
fs: AbstractFileSystem,
|
|
74
|
-
rootUri: string,
|
|
75
|
-
postfix: string,
|
|
76
|
-
): Promise<string> {
|
|
81
|
+
): Promise<string | undefined> {
|
|
82
|
+
const enYmlUri = join(rootUri, 'app/translations/en.yml');
|
|
77
83
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error(error);
|
|
84
|
-
return 'en';
|
|
84
|
+
await fs.stat(enYmlUri);
|
|
85
|
+
return enYmlUri;
|
|
86
|
+
} catch {
|
|
87
|
+
return undefined;
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
|
|
91
|
+
async function getDefaultLocale(_fs: AbstractFileSystem, _rootUri: string): Promise<string> {
|
|
92
|
+
// In platformOS, en.yml is always the reference translation file
|
|
93
|
+
return 'en';
|
|
94
|
+
}
|
|
95
|
+
|
|
88
96
|
async function getDefaultTranslations(
|
|
89
97
|
fs: AbstractFileSystem,
|
|
90
|
-
|
|
98
|
+
app: App,
|
|
91
99
|
rootUri: string,
|
|
92
|
-
postfix: string,
|
|
93
100
|
): Promise<Translations> {
|
|
94
101
|
try {
|
|
95
|
-
const bufferTranslations = getDefaultTranslationsFromBuffer(
|
|
102
|
+
const bufferTranslations = getDefaultTranslationsFromBuffer(app);
|
|
96
103
|
if (bufferTranslations) return bufferTranslations;
|
|
97
|
-
const defaultLocaleFile = await getDefaultLocaleFile(fs, rootUri
|
|
104
|
+
const defaultLocaleFile = await getDefaultLocaleFile(fs, rootUri);
|
|
98
105
|
if (!defaultLocaleFile) return {};
|
|
99
|
-
const
|
|
100
|
-
|
|
106
|
+
const yamlContent = await fs.readFile(defaultLocaleFile);
|
|
107
|
+
const data = load(yamlContent) as Record<string, any>;
|
|
108
|
+
if (!data || typeof data !== 'object') return {};
|
|
109
|
+
// YAML translation files wrap content under the locale key: { en: { hello: 'Hello' } }
|
|
110
|
+
const localeKey = Object.keys(data)[0];
|
|
111
|
+
return (localeKey && data[localeKey]) ?? {};
|
|
101
112
|
} catch (error) {
|
|
102
113
|
console.error(error);
|
|
103
114
|
return {};
|
|
@@ -105,17 +116,19 @@ async function getDefaultTranslations(
|
|
|
105
116
|
}
|
|
106
117
|
|
|
107
118
|
/** It might be that you have an open buffer, we prefer translations from there if available */
|
|
108
|
-
function getDefaultTranslationsFromBuffer(
|
|
109
|
-
const defaultTranslationsSourceCode =
|
|
110
|
-
(sourceCode) =>
|
|
111
|
-
sourceCode.type === SourceCodeType.JSON &&
|
|
112
|
-
sourceCode.uri.match(/locales/) &&
|
|
113
|
-
sourceCode.uri.endsWith(postfix),
|
|
119
|
+
function getDefaultTranslationsFromBuffer(app: App): Translations | undefined {
|
|
120
|
+
const defaultTranslationsSourceCode = app.find(
|
|
121
|
+
(sourceCode) => sourceCode.type === SourceCodeType.YAML && sourceCode.uri.endsWith('/en.yml'),
|
|
114
122
|
);
|
|
115
123
|
if (!defaultTranslationsSourceCode) return undefined;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
try {
|
|
125
|
+
const data = load(defaultTranslationsSourceCode.source) as Record<string, any>;
|
|
126
|
+
if (!data || typeof data !== 'object') return undefined;
|
|
127
|
+
const localeKey = Object.keys(data)[0];
|
|
128
|
+
return (localeKey && data[localeKey]) ?? undefined;
|
|
129
|
+
} catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
function cached<T>(fn: () => Promise<T>): () => Promise<T>;
|
|
@@ -157,64 +170,3 @@ const ignoredFolders = ['.git', 'node_modules', 'dist', 'build', 'tmp', 'vendor'
|
|
|
157
170
|
function isIgnored([uri, type]: FileTuple) {
|
|
158
171
|
return type === FileType.Directory && ignoredFolders.some((folder) => uri.endsWith(folder));
|
|
159
172
|
}
|
|
160
|
-
|
|
161
|
-
export const FETCHED_METAFIELD_CATEGORIES: MetafieldCategory[] = [
|
|
162
|
-
'article',
|
|
163
|
-
'blog',
|
|
164
|
-
'collection',
|
|
165
|
-
'company',
|
|
166
|
-
'company_location',
|
|
167
|
-
'location',
|
|
168
|
-
'market',
|
|
169
|
-
'order',
|
|
170
|
-
'page',
|
|
171
|
-
'product',
|
|
172
|
-
'variant',
|
|
173
|
-
'shop',
|
|
174
|
-
];
|
|
175
|
-
|
|
176
|
-
export const makeGetMetafieldDefinitions = (fs: AbstractFileSystem) =>
|
|
177
|
-
async function (rootUri: string): Promise<MetafieldDefinitionMap> {
|
|
178
|
-
const definitions = {
|
|
179
|
-
article: [],
|
|
180
|
-
blog: [],
|
|
181
|
-
collection: [],
|
|
182
|
-
company: [],
|
|
183
|
-
company_location: [],
|
|
184
|
-
location: [],
|
|
185
|
-
market: [],
|
|
186
|
-
order: [],
|
|
187
|
-
page: [],
|
|
188
|
-
product: [],
|
|
189
|
-
variant: [],
|
|
190
|
-
shop: [],
|
|
191
|
-
} as MetafieldDefinitionMap;
|
|
192
|
-
|
|
193
|
-
try {
|
|
194
|
-
const content = await fs.readFile(join(rootUri, '.shopify', 'metafields.json'));
|
|
195
|
-
const json = parseJSON(content);
|
|
196
|
-
|
|
197
|
-
if (isError(json)) return definitions;
|
|
198
|
-
|
|
199
|
-
return FETCHED_METAFIELD_CATEGORIES.reduce((definitions, group) => {
|
|
200
|
-
try {
|
|
201
|
-
definitions[group] = json[group].map((definition: any) => ({
|
|
202
|
-
key: definition.key,
|
|
203
|
-
name: definition.name,
|
|
204
|
-
namespace: definition.namespace,
|
|
205
|
-
description: definition.description,
|
|
206
|
-
type: {
|
|
207
|
-
category: definition.type.category,
|
|
208
|
-
name: definition.type.name,
|
|
209
|
-
},
|
|
210
|
-
}));
|
|
211
|
-
} catch (error) {
|
|
212
|
-
// If there are errors in the file, we ignore it
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return definitions;
|
|
216
|
-
}, definitions);
|
|
217
|
-
} catch (err) {
|
|
218
|
-
return definitions;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
@@ -34,10 +34,10 @@ describe('Module: DisabledChecks', () => {
|
|
|
34
34
|
describe(`Comment variant`, () => {
|
|
35
35
|
it('should disable checks for the entire document if comment is placed on the first line', async () => {
|
|
36
36
|
for (const buildComment of commentTypes) {
|
|
37
|
-
const file = `${buildComment('
|
|
37
|
+
const file = `${buildComment('platformos-check-disable LiquidFilter')}
|
|
38
38
|
{% comment %}
|
|
39
39
|
This is some comment about the file...
|
|
40
|
-
Adding a comment here should not mess with
|
|
40
|
+
Adding a comment here should not mess with platformos-check-disable
|
|
41
41
|
{% endcomment %}
|
|
42
42
|
{{ 'asset' | random_filter }}
|
|
43
43
|
{% render 'something' %}`;
|
|
@@ -50,7 +50,7 @@ describe('Module: DisabledChecks', () => {
|
|
|
50
50
|
|
|
51
51
|
it('should disable all checks even if comment has additional spaces', async () => {
|
|
52
52
|
for (const buildComment of commentTypes) {
|
|
53
|
-
const file = `${buildComment('
|
|
53
|
+
const file = `${buildComment(' platformos-check-disable ')}
|
|
54
54
|
{{ 'asset' | random_filter }}
|
|
55
55
|
{% render 'something' %}`;
|
|
56
56
|
|
|
@@ -63,10 +63,10 @@ describe('Module: DisabledChecks', () => {
|
|
|
63
63
|
for (const buildComment of commentTypes) {
|
|
64
64
|
const file = `{{ 'asset-1' | random_filter }}
|
|
65
65
|
{% render 'something-1' %}
|
|
66
|
-
${buildComment('
|
|
66
|
+
${buildComment('platformos-check-disable')}
|
|
67
67
|
{{ 'asset-2' | random_filter }}
|
|
68
68
|
{% render 'something-2' %}
|
|
69
|
-
${buildComment('
|
|
69
|
+
${buildComment('platformos-check-enable')}
|
|
70
70
|
{{ 'asset-3' | random_filter }}`;
|
|
71
71
|
|
|
72
72
|
const offenses = await check({ 'code.liquid': file }, checks);
|
|
@@ -79,10 +79,10 @@ ${buildComment('theme-check-enable')}
|
|
|
79
79
|
|
|
80
80
|
it('should disable a specific check if check is included in the comment', async () => {
|
|
81
81
|
for (const buildComment of commentTypes) {
|
|
82
|
-
const file = `${buildComment('
|
|
82
|
+
const file = `${buildComment('platformos-check-disable LiquidFilter')}
|
|
83
83
|
{{ 'asset-1' | random_filter }}
|
|
84
84
|
{% render 'something' %}
|
|
85
|
-
${buildComment('
|
|
85
|
+
${buildComment('platformos-check-enable LiquidFilter')}
|
|
86
86
|
{{ 'asset-2' | random_filter }}`;
|
|
87
87
|
|
|
88
88
|
const offenses = await check({ 'code.liquid': file }, checks);
|
|
@@ -94,10 +94,10 @@ ${buildComment('theme-check-enable LiquidFilter')}
|
|
|
94
94
|
|
|
95
95
|
it('should disable multiple checks if checks are separated by a comma (and maybe some spaces)', async () => {
|
|
96
96
|
for (const buildComment of commentTypes) {
|
|
97
|
-
const file = `${buildComment('
|
|
97
|
+
const file = `${buildComment('platformos-check-disable LiquidFilter, RenderMarkup')}
|
|
98
98
|
{{ 'asset-1' | random_filter }}
|
|
99
99
|
{% render 'something' %}
|
|
100
|
-
${buildComment('
|
|
100
|
+
${buildComment('platformos-check-enable LiquidFilter,RenderMarkup')}
|
|
101
101
|
{{ 'asset-2' | random_filter }}`;
|
|
102
102
|
|
|
103
103
|
const offenses = await check({ 'code.liquid': file }, checks);
|
|
@@ -108,13 +108,13 @@ ${buildComment('theme-check-enable LiquidFilter,RenderMarkup')}
|
|
|
108
108
|
|
|
109
109
|
it('should enable specific checks individually', async () => {
|
|
110
110
|
for (const buildComment of commentTypes) {
|
|
111
|
-
const file = `${buildComment('
|
|
111
|
+
const file = `${buildComment('platformos-check-disable LiquidFilter, RenderMarkup')}
|
|
112
112
|
{{ 'asset-1' | random_filter }}
|
|
113
113
|
{% render 'something-1' %}
|
|
114
|
-
${buildComment('
|
|
114
|
+
${buildComment('platformos-check-enable RenderMarkup')}
|
|
115
115
|
{{ 'asset-2' | random_filter }}
|
|
116
116
|
{% render 'something-2' %}
|
|
117
|
-
${buildComment('
|
|
117
|
+
${buildComment('platformos-check-enable LiquidFilter')}
|
|
118
118
|
{{ 'asset-3' | random_filter }}
|
|
119
119
|
{% render 'something-3' %}`;
|
|
120
120
|
|
|
@@ -129,10 +129,10 @@ ${buildComment('theme-check-enable LiquidFilter')}
|
|
|
129
129
|
describe('Mix of general and specific commands', () => {
|
|
130
130
|
it('should not reenable specific check when all checks have been disabled before', async () => {
|
|
131
131
|
for (const buildComment of commentTypes) {
|
|
132
|
-
const file = `${buildComment('
|
|
132
|
+
const file = `${buildComment('platformos-check-disable')}
|
|
133
133
|
{{ 'asset-1' | random_filter }}
|
|
134
134
|
{% render 'something-1' %}
|
|
135
|
-
${buildComment('
|
|
135
|
+
${buildComment('platformos-check-enable RenderMarkup')}
|
|
136
136
|
{{ 'asset-2' | random_filter }}
|
|
137
137
|
{% render 'something-2' %}`;
|
|
138
138
|
const offenses = await check({ 'code.liquid': file }, checks);
|
|
@@ -142,10 +142,10 @@ ${buildComment('theme-check-enable RenderMarkup')}
|
|
|
142
142
|
|
|
143
143
|
it('should reenable all checks when specific ones have been disabled before', async () => {
|
|
144
144
|
for (const buildComment of commentTypes) {
|
|
145
|
-
const file = `${buildComment('
|
|
145
|
+
const file = `${buildComment('platformos-check-disable LiquidFilter, RenderMarkup')}
|
|
146
146
|
{{ 'asset-3' | random_filter }}
|
|
147
147
|
{% render 'something-3' %}
|
|
148
|
-
${buildComment('
|
|
148
|
+
${buildComment('platformos-check-enable')}
|
|
149
149
|
{{ 'asset-4' | random_filter }}
|
|
150
150
|
{% render 'something-4' %}`;
|
|
151
151
|
|
|
@@ -159,7 +159,7 @@ ${buildComment('theme-check-enable')}
|
|
|
159
159
|
|
|
160
160
|
describe('disable next line', () => {
|
|
161
161
|
it('should disable the next line if there is one', async () => {
|
|
162
|
-
const file = `{% #
|
|
162
|
+
const file = `{% # platformos-check-disable-next-line %}
|
|
163
163
|
{% render 'something' %}
|
|
164
164
|
{% render 'other-thing' %}`;
|
|
165
165
|
|
|
@@ -168,8 +168,8 @@ ${buildComment('theme-check-enable')}
|
|
|
168
168
|
expectRenderMarkupOffense(offenses, 'other-thing.liquid');
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
-
it("should not disable the liquid tag's children node if
|
|
172
|
-
const file = `{% #
|
|
171
|
+
it("should not disable the liquid tag's children node if platformos-check is disabled", async () => {
|
|
172
|
+
const file = `{% # platformos-check-disable-next-line %}
|
|
173
173
|
{% if condition %}
|
|
174
174
|
{% render 'something' %}
|
|
175
175
|
{% endif %}
|
|
@@ -183,7 +183,7 @@ ${buildComment('theme-check-enable')}
|
|
|
183
183
|
|
|
184
184
|
it('should disable the next line inside a liquid tag if there is one', async () => {
|
|
185
185
|
const file = `{% liquid
|
|
186
|
-
#
|
|
186
|
+
# platformos-check-disable-next-line
|
|
187
187
|
render 'something'
|
|
188
188
|
render 'other-thing'
|
|
189
189
|
%}`;
|
|
@@ -193,10 +193,10 @@ ${buildComment('theme-check-enable')}
|
|
|
193
193
|
expectRenderMarkupOffense(offenses, 'other-thing.liquid');
|
|
194
194
|
});
|
|
195
195
|
|
|
196
|
-
it("should disable the parent node's next node if
|
|
196
|
+
it("should disable the parent node's next node if platformos-check is disabled as the last child node", async () => {
|
|
197
197
|
const file = `{% liquid
|
|
198
198
|
if condition
|
|
199
|
-
#
|
|
199
|
+
# platformos-check-disable-next-line
|
|
200
200
|
elsif other_condition
|
|
201
201
|
endif
|
|
202
202
|
%}`;
|
|
@@ -210,11 +210,11 @@ ${buildComment('theme-check-enable')}
|
|
|
210
210
|
);
|
|
211
211
|
});
|
|
212
212
|
|
|
213
|
-
it('should not disable any checks if
|
|
213
|
+
it('should not disable any checks if platformos-check is disabled at the end', async () => {
|
|
214
214
|
const file = `{% liquid
|
|
215
215
|
echo hello
|
|
216
216
|
echo everyone
|
|
217
|
-
#
|
|
217
|
+
# platformos-check-disable-next-line
|
|
218
218
|
%}`;
|
|
219
219
|
|
|
220
220
|
const offenses = await check({ 'code.liquid': file }, [UndefinedObject]);
|
|
@@ -232,7 +232,7 @@ ${buildComment('theme-check-enable')}
|
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
it('should disable the next line if the content is an HTML tag with liquid', async () => {
|
|
235
|
-
const file = `{% #
|
|
235
|
+
const file = `{% # platformos-check-disable-next-line %}
|
|
236
236
|
<div class="{{ foo }}"></div>
|
|
237
237
|
<div class="{{ bar }}"></div>`;
|
|
238
238
|
|
|
@@ -246,7 +246,7 @@ ${buildComment('theme-check-enable')}
|
|
|
246
246
|
});
|
|
247
247
|
|
|
248
248
|
it('should not disable the next line if the specified rule does not exist', async () => {
|
|
249
|
-
const file = `{% #
|
|
249
|
+
const file = `{% # platformos-check-disable-next-line FAKE_RULE %}
|
|
250
250
|
<div class="{{ foo }}"></div>`;
|
|
251
251
|
|
|
252
252
|
const offenses = await check({ 'code.liquid': file }, [UndefinedObject]);
|
|
@@ -24,7 +24,7 @@ export function createDisabledChecksModule() {
|
|
|
24
24
|
node: LiquidTag | LiquidRawTag,
|
|
25
25
|
) {
|
|
26
26
|
const [_, command, checksJoined] =
|
|
27
|
-
value.trim().match(/^(?:
|
|
27
|
+
value.trim().match(/^(?:platformos\-check\-(disable-next-line|disable|enable)) ?(.*)/) || [];
|
|
28
28
|
|
|
29
29
|
const checks = checksJoined ? checksJoined.split(/,[ ]*/) : [SPECIFIC_CHECK_NOT_DEFINED];
|
|
30
30
|
|
|
@@ -133,7 +133,7 @@ export function findNextLinePosition(
|
|
|
133
133
|
* E.g. The following disables check for `elsif` tag
|
|
134
134
|
*
|
|
135
135
|
* {% if condition %}
|
|
136
|
-
* {% #
|
|
136
|
+
* {% # platformos-check-disable-next-line %}
|
|
137
137
|
* {% elsif other_condition %}
|
|
138
138
|
* {{ prouduct }}
|
|
139
139
|
* {% endif %}
|
|
@@ -45,14 +45,14 @@ export const RenderMarkup: LiquidCheckDefinition = {
|
|
|
45
45
|
create(context) {
|
|
46
46
|
return {
|
|
47
47
|
async RenderMarkup(node) {
|
|
48
|
-
if (node.
|
|
48
|
+
if (node.partial.type === NodeTypes.VariableLookup) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
context.report({
|
|
53
|
-
message: `'${node.
|
|
54
|
-
startIndex: node.
|
|
55
|
-
endIndex: node.
|
|
53
|
+
message: `'${node.partial.value}.liquid' can not be rendered`,
|
|
54
|
+
startIndex: node.partial.position.start,
|
|
55
|
+
endIndex: node.partial.position.end,
|
|
56
56
|
});
|
|
57
57
|
},
|
|
58
58
|
};
|
package/src/find-root.ts
CHANGED
|
@@ -5,13 +5,11 @@ type FileExists = (uri: string) => Promise<boolean>;
|
|
|
5
5
|
|
|
6
6
|
async function isRoot(dir: UriString, fileExists: FileExists) {
|
|
7
7
|
return or(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
fileExists(path.join(dir, '.git')),
|
|
14
|
-
),
|
|
8
|
+
fileExists(path.join(dir, '.pos')),
|
|
9
|
+
fileExists(path.join(dir, '.platformos-check.yml')),
|
|
10
|
+
fileExists(path.join(dir, 'app')),
|
|
11
|
+
// modules/ is a root indicator only when not inside app/ (app/modules/ is a valid subdirectory)
|
|
12
|
+
and(fileExists(path.join(dir, 'modules')), Promise.resolve(path.basename(dir) !== 'app')),
|
|
15
13
|
);
|
|
16
14
|
}
|
|
17
15
|
|
|
@@ -25,24 +23,16 @@ async function or(...promises: Promise<boolean>[]) {
|
|
|
25
23
|
return bools.reduce((a, b) => a || b, false);
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
async function not(ap: Promise<boolean>) {
|
|
29
|
-
const a = await ap;
|
|
30
|
-
return !a;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
/**
|
|
34
|
-
* Returns the
|
|
35
|
-
*
|
|
36
|
-
* `
|
|
37
|
-
*
|
|
38
|
-
* There are cases where .theme-check.yml is not defined and we have to infer the root.
|
|
39
|
-
* We'll assume that the root is the directory that contains a `snippets` directory.
|
|
27
|
+
* Returns the root of a platformOS app. The root is the directory that contains
|
|
28
|
+
* a `.pos` sentinel file, a `.platformos-check.yml` config file, an `app/` directory,
|
|
29
|
+
* or a `modules/` directory (when not inside `app/`).
|
|
40
30
|
*
|
|
41
|
-
*
|
|
42
|
-
* should be.
|
|
31
|
+
* Note: `modules/` inside `app/` (i.e. `app/modules/`) is a valid subdirectory and
|
|
32
|
+
* should not be treated as a root indicator.
|
|
43
33
|
*
|
|
44
|
-
* Note:
|
|
45
|
-
*
|
|
34
|
+
* Note: this is not the app root itself. The config file might have a `root` entry that
|
|
35
|
+
* points to somewhere else.
|
|
46
36
|
*/
|
|
47
37
|
export async function findRoot(curr: UriString, fileExists: FileExists): Promise<UriString | null> {
|
|
48
38
|
const currIsRoot = await isRoot(curr, fileExists);
|
|
@@ -4,7 +4,7 @@ import { Offense, SourceCodeType } from '../types';
|
|
|
4
4
|
|
|
5
5
|
describe('Module: autofix', () => {
|
|
6
6
|
it('should apply a list of all safe changes', async () => {
|
|
7
|
-
const
|
|
7
|
+
const mockApp = {
|
|
8
8
|
'a.liquid': 'Banana world',
|
|
9
9
|
'b.json': prettyJSON({ a: 'b' }),
|
|
10
10
|
};
|
|
@@ -69,7 +69,7 @@ describe('Module: autofix', () => {
|
|
|
69
69
|
},
|
|
70
70
|
];
|
|
71
71
|
|
|
72
|
-
const fixed = await autofix(
|
|
72
|
+
const fixed = await autofix(mockApp, offenses);
|
|
73
73
|
expect(fixed['a.liquid']).to.eql('Bananananana world');
|
|
74
74
|
expect(fixed['b.json']).to.eql(
|
|
75
75
|
prettyJSON({
|
package/src/fixes/autofix.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FixApplicator, Offense, SourceCodeType,
|
|
1
|
+
import { FixApplicator, Offense, SourceCodeType, App } from '../types';
|
|
2
2
|
import { WithRequired } from '../utils/types';
|
|
3
3
|
import { createCorrector } from './correctors';
|
|
4
4
|
import { flattenFixes } from './utils';
|
|
@@ -8,13 +8,13 @@ type FixableOffense<S extends SourceCodeType> = S extends SourceCodeType
|
|
|
8
8
|
: never;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Takes
|
|
12
|
-
* safe ones on the
|
|
11
|
+
* Takes an app, list of offenses and a fixApplicator and runs all the
|
|
12
|
+
* safe ones on the app.
|
|
13
13
|
*
|
|
14
14
|
* Note that offense.fix is assumed to be safe, unlike offense.suggest
|
|
15
15
|
* options.
|
|
16
16
|
*/
|
|
17
|
-
export async function autofix(sourceCodes:
|
|
17
|
+
export async function autofix(sourceCodes: App, offenses: Offense[], applyFixes: FixApplicator) {
|
|
18
18
|
const fixableOffenses = offenses.filter(
|
|
19
19
|
(offense): offense is FixableOffense<SourceCodeType> => 'fix' in offense && !!offense.fix,
|
|
20
20
|
);
|
|
@@ -18,6 +18,10 @@ export function createCorrector<S extends SourceCodeType>(
|
|
|
18
18
|
}
|
|
19
19
|
case SourceCodeType.GraphQL:
|
|
20
20
|
return new GraphQLCorrector(source) as Corrector<typeof sourceCodeType>;
|
|
21
|
+
case SourceCodeType.YAML: {
|
|
22
|
+
// YAML autofix is not yet supported; this case should not be reached
|
|
23
|
+
throw new Error('YAML autofix is not supported');
|
|
24
|
+
}
|
|
21
25
|
default: {
|
|
22
26
|
return assertNever(sourceCodeType);
|
|
23
27
|
}
|
package/src/ignore.spec.ts
CHANGED
|
@@ -47,7 +47,7 @@ describe('Function: isIgnored', () => {
|
|
|
47
47
|
const result = isIgnored(
|
|
48
48
|
toUri('app/views/partials/foo.liquid'),
|
|
49
49
|
config({
|
|
50
|
-
checkIgnore: ['!
|
|
50
|
+
checkIgnore: ['!other-dir/*'],
|
|
51
51
|
globalIgnore: [],
|
|
52
52
|
}),
|
|
53
53
|
checkDef,
|
|
@@ -73,7 +73,7 @@ describe('Function: isIgnored', () => {
|
|
|
73
73
|
const result = isIgnored(
|
|
74
74
|
toUri('app/views/partials/foo.liquid'),
|
|
75
75
|
config({
|
|
76
|
-
checkIgnore: ['other-
|
|
76
|
+
checkIgnore: ['other-dir/*.liquid'],
|
|
77
77
|
globalIgnore: [],
|
|
78
78
|
}),
|
|
79
79
|
checkDef,
|
|
@@ -165,10 +165,10 @@ describe('Function: isIgnored', () => {
|
|
|
165
165
|
|
|
166
166
|
it('should work with only global ignore as well', () => {
|
|
167
167
|
const result = isIgnored(
|
|
168
|
-
toUri('layout
|
|
168
|
+
toUri('app/views/layouts/layout.liquid'),
|
|
169
169
|
config({
|
|
170
170
|
checkIgnore: [],
|
|
171
|
-
globalIgnore: ['layout
|
|
171
|
+
globalIgnore: ['app/views/layouts/layout.liquid'],
|
|
172
172
|
}),
|
|
173
173
|
);
|
|
174
174
|
|
|
@@ -188,7 +188,6 @@ function config({
|
|
|
188
188
|
globalIgnore?: string[];
|
|
189
189
|
}): Config {
|
|
190
190
|
return {
|
|
191
|
-
context: 'theme',
|
|
192
191
|
settings: {
|
|
193
192
|
MockCheck: {
|
|
194
193
|
enabled: true,
|