@platformos/platformos-check-common 0.0.7 → 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.
Files changed (309) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/AugmentedPlatformOSDocset.d.ts +11 -0
  3. package/dist/AugmentedPlatformOSDocset.js +81 -0
  4. package/dist/AugmentedPlatformOSDocset.js.map +1 -0
  5. package/dist/JSONValidator.js +1 -1
  6. package/dist/JSONValidator.js.map +1 -1
  7. package/dist/checks/deprecated-filter/index.js +4 -41
  8. package/dist/checks/deprecated-filter/index.js.map +1 -1
  9. package/dist/checks/deprecated-tag/index.js +21 -22
  10. package/dist/checks/deprecated-tag/index.js.map +1 -1
  11. package/dist/checks/duplicate-function-arguments/index.js +1 -1
  12. package/dist/checks/duplicate-function-arguments/index.js.map +1 -1
  13. package/dist/checks/duplicate-render-partial-arguments/index.js +1 -1
  14. package/dist/checks/duplicate-render-partial-arguments/index.js.map +1 -1
  15. package/dist/checks/graphql/index.js +1 -1
  16. package/dist/checks/graphql/index.js.map +1 -1
  17. package/dist/checks/img-width-and-height/index.js +1 -1
  18. package/dist/checks/img-width-and-height/index.js.map +1 -1
  19. package/dist/checks/index.d.ts +3 -3
  20. package/dist/checks/index.js +4 -79
  21. package/dist/checks/index.js.map +1 -1
  22. package/dist/checks/json-syntax-error/index.js +1 -1
  23. package/dist/checks/json-syntax-error/index.js.map +1 -1
  24. package/dist/checks/liquid-html-syntax-error/index.js +2 -2
  25. package/dist/checks/liquid-html-syntax-error/index.js.map +1 -1
  26. package/dist/checks/matching-translations/index.d.ts +2 -2
  27. package/dist/checks/matching-translations/index.js +20 -31
  28. package/dist/checks/matching-translations/index.js.map +1 -1
  29. package/dist/checks/metadata-params/index.js +6 -3
  30. package/dist/checks/metadata-params/index.js.map +1 -1
  31. package/dist/checks/missing-asset/index.js +1 -1
  32. package/dist/checks/missing-asset/index.js.map +1 -1
  33. package/dist/checks/missing-partial/index.d.ts +6 -0
  34. package/dist/checks/missing-partial/index.js +70 -0
  35. package/dist/checks/missing-partial/index.js.map +1 -0
  36. package/dist/checks/orphaned-partial/index.js +4 -4
  37. package/dist/checks/orphaned-partial/index.js.map +1 -1
  38. package/dist/checks/parser-blocking-script/index.js +10 -36
  39. package/dist/checks/parser-blocking-script/index.js.map +1 -1
  40. package/dist/checks/parser-blocking-script/suggestions.d.ts +1 -2
  41. package/dist/checks/parser-blocking-script/suggestions.js +1 -11
  42. package/dist/checks/parser-blocking-script/suggestions.js.map +1 -1
  43. package/dist/checks/reserved-doc-param-names/index.js +6 -5
  44. package/dist/checks/reserved-doc-param-names/index.js.map +1 -1
  45. package/dist/checks/translation-key-exists/index.js +1 -1
  46. package/dist/checks/translation-key-exists/index.js.map +1 -1
  47. package/dist/checks/unclosed-html-element/index.js +5 -1
  48. package/dist/checks/unclosed-html-element/index.js.map +1 -1
  49. package/dist/checks/undefined-object/index.js +7 -30
  50. package/dist/checks/undefined-object/index.js.map +1 -1
  51. package/dist/checks/unique-doc-param-names/index.js +1 -1
  52. package/dist/checks/unique-doc-param-names/index.js.map +1 -1
  53. package/dist/checks/unknown-filter/index.js +3 -3
  54. package/dist/checks/unknown-filter/index.js.map +1 -1
  55. package/dist/checks/unknown-property/index.js +1 -1
  56. package/dist/checks/unknown-property/index.js.map +1 -1
  57. package/dist/checks/unrecognized-render-partial-arguments/index.js +2 -2
  58. package/dist/checks/unrecognized-render-partial-arguments/index.js.map +1 -1
  59. package/dist/checks/unused-assign/index.js +1 -1
  60. package/dist/checks/unused-assign/index.js.map +1 -1
  61. package/dist/checks/unused-doc-param/index.js +1 -1
  62. package/dist/checks/unused-doc-param/index.js.map +1 -1
  63. package/dist/checks/utils.js +1 -1
  64. package/dist/checks/utils.js.map +1 -1
  65. package/dist/checks/valid-content-for-arguments/index.js +1 -1
  66. package/dist/checks/valid-content-for-arguments/index.js.map +1 -1
  67. package/dist/checks/valid-doc-param-types/index.js +4 -4
  68. package/dist/checks/valid-doc-param-types/index.js.map +1 -1
  69. package/dist/checks/valid-html-translation/index.d.ts +2 -2
  70. package/dist/checks/valid-html-translation/index.js +4 -4
  71. package/dist/checks/valid-html-translation/index.js.map +1 -1
  72. package/dist/checks/valid-json/index.js +1 -1
  73. package/dist/checks/valid-json/index.js.map +1 -1
  74. package/dist/checks/valid-render-partial-argument-types/index.js +2 -2
  75. package/dist/checks/valid-render-partial-argument-types/index.js.map +1 -1
  76. package/dist/checks/variable-name/index.js +1 -1
  77. package/dist/checks/variable-name/index.js.map +1 -1
  78. package/dist/context-utils.d.ts +2 -7
  79. package/dist/context-utils.js +39 -109
  80. package/dist/context-utils.js.map +1 -1
  81. package/dist/disabled-checks/index.js +4 -2
  82. package/dist/disabled-checks/index.js.map +1 -1
  83. package/dist/doc-generator/DocBlockGenerator.d.ts +16 -0
  84. package/dist/doc-generator/DocBlockGenerator.js +464 -0
  85. package/dist/doc-generator/DocBlockGenerator.js.map +1 -0
  86. package/dist/doc-generator/index.d.ts +1 -0
  87. package/dist/doc-generator/index.js +6 -0
  88. package/dist/doc-generator/index.js.map +1 -0
  89. package/dist/find-root.d.ts +7 -10
  90. package/dist/find-root.js +10 -17
  91. package/dist/find-root.js.map +1 -1
  92. package/dist/fixes/autofix.d.ts +4 -4
  93. package/dist/fixes/autofix.js +2 -2
  94. package/dist/fixes/autofix.js.map +1 -1
  95. package/dist/fixes/correctors/index.js +4 -0
  96. package/dist/fixes/correctors/index.js.map +1 -1
  97. package/dist/index.d.ts +4 -5
  98. package/dist/index.js +34 -17
  99. package/dist/index.js.map +1 -1
  100. package/dist/jsonc/parse.d.ts +1 -1
  101. package/dist/jsonc/parse.js +1 -1
  102. package/dist/liquid-doc/arguments.d.ts +7 -8
  103. package/dist/liquid-doc/arguments.js +20 -28
  104. package/dist/liquid-doc/arguments.js.map +1 -1
  105. package/dist/liquid-doc/liquidDoc.d.ts +1 -1
  106. package/dist/liquid-doc/liquidDoc.js.map +1 -1
  107. package/dist/liquid-doc/utils.d.ts +1 -1
  108. package/dist/liquid-doc/utils.js +4 -3
  109. package/dist/liquid-doc/utils.js.map +1 -1
  110. package/dist/path.d.ts +1 -0
  111. package/dist/path.js +5 -1
  112. package/dist/path.js.map +1 -1
  113. package/dist/test/MockApp.d.ts +16 -0
  114. package/dist/test/MockApp.js +16 -0
  115. package/dist/test/MockApp.js.map +1 -0
  116. package/dist/test/MockFileSystem.d.ts +3 -3
  117. package/dist/test/MockFileSystem.js +6 -6
  118. package/dist/test/MockFileSystem.js.map +1 -1
  119. package/dist/test/index.d.ts +1 -1
  120. package/dist/test/index.js +1 -1
  121. package/dist/test/index.js.map +1 -1
  122. package/dist/test/test-helper.d.ts +10 -9
  123. package/dist/test/test-helper.js +15 -106
  124. package/dist/test/test-helper.js.map +1 -1
  125. package/dist/to-schema.d.ts +1 -1
  126. package/dist/to-source-code.d.ts +3 -2
  127. package/dist/to-source-code.js +20 -0
  128. package/dist/to-source-code.js.map +1 -1
  129. package/dist/tsconfig.tsbuildinfo +1 -1
  130. package/dist/types/platformos-liquid-docs.d.ts +128 -0
  131. package/dist/types/platformos-liquid-docs.js +3 -0
  132. package/dist/types/platformos-liquid-docs.js.map +1 -0
  133. package/dist/types/schemas/index.d.ts +0 -2
  134. package/dist/types/schemas/index.js.map +1 -1
  135. package/dist/types.d.ts +18 -67
  136. package/dist/types.js +3 -5
  137. package/dist/types.js.map +1 -1
  138. package/dist/utils/block.js.map +1 -1
  139. package/dist/utils/index.d.ts +0 -1
  140. package/dist/utils/index.js +0 -1
  141. package/dist/utils/index.js.map +1 -1
  142. package/dist/yaml/parse.d.ts +5 -0
  143. package/dist/yaml/parse.js +94 -0
  144. package/dist/yaml/parse.js.map +1 -0
  145. package/package.json +4 -3
  146. package/src/{AugmentedThemeDocset.spec.ts → AugmentedPlatformOSDocset.spec.ts} +47 -34
  147. package/src/AugmentedPlatformOSDocset.ts +89 -0
  148. package/src/JSONValidator.ts +1 -1
  149. package/src/checks/deprecated-filter/index.spec.ts +76 -248
  150. package/src/checks/deprecated-filter/index.ts +5 -53
  151. package/src/checks/deprecated-tag/index.spec.ts +85 -34
  152. package/src/checks/deprecated-tag/index.ts +27 -22
  153. package/src/checks/duplicate-function-arguments/index.ts +1 -1
  154. package/src/checks/duplicate-render-partial-arguments/index.ts +1 -1
  155. package/src/checks/graphql/index.ts +1 -1
  156. package/src/checks/img-width-and-height/index.ts +1 -1
  157. package/src/checks/index.ts +11 -80
  158. package/src/checks/invalid-hash-assign-target/index.spec.ts +14 -14
  159. package/src/checks/json-syntax-error/index.ts +1 -1
  160. package/src/checks/liquid-html-syntax-error/checks/InvalidBooleanExpression.spec.ts +0 -11
  161. package/src/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.spec.ts +1 -2
  162. package/src/checks/liquid-html-syntax-error/index.spec.ts +1 -6
  163. package/src/checks/liquid-html-syntax-error/index.ts +2 -2
  164. package/src/checks/matching-translations/index.spec.ts +89 -346
  165. package/src/checks/matching-translations/index.ts +24 -35
  166. package/src/checks/metadata-params/index.ts +5 -7
  167. package/src/checks/missing-asset/index.ts +1 -1
  168. package/src/checks/{missing-template → missing-partial}/index.spec.ts +6 -6
  169. package/src/checks/{missing-template → missing-partial}/index.ts +6 -20
  170. package/src/checks/orphaned-partial/index.ts +3 -3
  171. package/src/checks/parser-blocking-script/index.spec.ts +0 -118
  172. package/src/checks/parser-blocking-script/index.ts +3 -33
  173. package/src/checks/parser-blocking-script/suggestions.ts +1 -28
  174. package/src/checks/translation-key-exists/index.ts +1 -1
  175. package/src/checks/unclosed-html-element/index.ts +5 -1
  176. package/src/checks/undefined-object/index.spec.ts +3 -109
  177. package/src/checks/undefined-object/index.ts +8 -33
  178. package/src/checks/unique-doc-param-names/index.ts +1 -1
  179. package/src/checks/unknown-filter/index.spec.ts +2 -2
  180. package/src/checks/unknown-filter/index.ts +3 -3
  181. package/src/checks/unknown-property/index.ts +1 -1
  182. package/src/checks/unrecognized-render-partial-arguments/index.spec.ts +5 -5
  183. package/src/checks/unrecognized-render-partial-arguments/index.ts +2 -5
  184. package/src/checks/unused-assign/index.spec.ts +0 -30
  185. package/src/checks/unused-assign/index.ts +1 -1
  186. package/src/checks/unused-doc-param/index.ts +1 -1
  187. package/src/checks/utils.ts +1 -1
  188. package/src/checks/valid-doc-param-types/index.ts +4 -4
  189. package/src/checks/valid-html-translation/index.spec.ts +42 -32
  190. package/src/checks/valid-html-translation/index.ts +7 -7
  191. package/src/checks/valid-json/index.ts +1 -1
  192. package/src/checks/valid-render-partial-argument-types/index.ts +2 -5
  193. package/src/checks/variable-name/index.ts +1 -1
  194. package/src/context-utils.spec.ts +49 -77
  195. package/src/context-utils.ts +39 -128
  196. package/src/disabled-checks/index.spec.ts +35 -0
  197. package/src/disabled-checks/index.ts +4 -2
  198. package/src/find-root.ts +12 -22
  199. package/src/fixes/autofix.spec.ts +2 -2
  200. package/src/fixes/autofix.ts +4 -4
  201. package/src/fixes/correctors/index.ts +4 -0
  202. package/src/ignore.spec.ts +0 -1
  203. package/src/index.ts +33 -21
  204. package/src/jsonc/parse.ts +1 -1
  205. package/src/liquid-doc/arguments.spec.ts +19 -45
  206. package/src/liquid-doc/arguments.ts +26 -39
  207. package/src/liquid-doc/liquidDoc.ts +1 -2
  208. package/src/liquid-doc/utils.ts +4 -3
  209. package/src/path.ts +1 -0
  210. package/src/test/{MockTheme.ts → MockApp.ts} +1 -1
  211. package/src/test/MockFileSystem.ts +6 -6
  212. package/src/test/index.ts +1 -1
  213. package/src/test/test-helper.ts +29 -127
  214. package/src/to-source-code.ts +20 -1
  215. package/src/types/{theme-liquid-docs.ts → platformos-liquid-docs.ts} +8 -13
  216. package/src/types/schemas/index.ts +0 -2
  217. package/src/types.ts +21 -92
  218. package/src/utils/index.ts +0 -1
  219. package/src/yaml/parse.ts +111 -0
  220. package/src/AugmentedThemeDocset.ts +0 -137
  221. package/src/checks/app-block-missing-schema/index.spec.ts +0 -121
  222. package/src/checks/app-block-missing-schema/index.ts +0 -46
  223. package/src/checks/app-block-valid-tags/index.spec.ts +0 -96
  224. package/src/checks/app-block-valid-tags/index.ts +0 -54
  225. package/src/checks/asset-preload/index.spec.ts +0 -78
  226. package/src/checks/asset-preload/index.ts +0 -65
  227. package/src/checks/asset-size-app-block-css/index.spec.ts +0 -88
  228. package/src/checks/asset-size-app-block-css/index.ts +0 -78
  229. package/src/checks/asset-size-app-block-javascript/index.spec.ts +0 -66
  230. package/src/checks/asset-size-app-block-javascript/index.ts +0 -78
  231. package/src/checks/asset-size-css/index.spec.ts +0 -166
  232. package/src/checks/asset-size-css/index.ts +0 -160
  233. package/src/checks/asset-size-javascript/index.spec.ts +0 -184
  234. package/src/checks/asset-size-javascript/index.ts +0 -144
  235. package/src/checks/block-id-usage/index.spec.ts +0 -76
  236. package/src/checks/block-id-usage/index.ts +0 -72
  237. package/src/checks/cdn-preconnect/index.spec.ts +0 -40
  238. package/src/checks/cdn-preconnect/index.ts +0 -43
  239. package/src/checks/content-for-header-modification/index.spec.ts +0 -65
  240. package/src/checks/content-for-header-modification/index.ts +0 -72
  241. package/src/checks/deprecate-bgsizes/index.spec.ts +0 -41
  242. package/src/checks/deprecate-bgsizes/index.ts +0 -49
  243. package/src/checks/deprecate-lazysizes/index.spec.ts +0 -26
  244. package/src/checks/deprecate-lazysizes/index.ts +0 -58
  245. package/src/checks/deprecated-filter/fixes.ts +0 -264
  246. package/src/checks/deprecated-fonts-on-sections-and-blocks/deprecated-fonts-data.ts +0 -1343
  247. package/src/checks/deprecated-fonts-on-sections-and-blocks/index.spec.ts +0 -613
  248. package/src/checks/deprecated-fonts-on-sections-and-blocks/index.ts +0 -284
  249. package/src/checks/deprecated-fonts-on-settings-schema/index.spec.ts +0 -102
  250. package/src/checks/deprecated-fonts-on-settings-schema/index.ts +0 -66
  251. package/src/checks/duplicate-content-for-arguments/index.spec.ts +0 -98
  252. package/src/checks/duplicate-content-for-arguments/index.ts +0 -43
  253. package/src/checks/empty-block-content/index.spec.ts +0 -117
  254. package/src/checks/empty-block-content/index.ts +0 -60
  255. package/src/checks/hardcoded-routes/index.spec.ts +0 -58
  256. package/src/checks/hardcoded-routes/index.ts +0 -100
  257. package/src/checks/json-missing-block/index.spec.ts +0 -435
  258. package/src/checks/json-missing-block/index.ts +0 -56
  259. package/src/checks/json-missing-block/missing-block-utils.ts +0 -147
  260. package/src/checks/liquid-free-settings/index.spec.ts +0 -180
  261. package/src/checks/liquid-free-settings/index.ts +0 -79
  262. package/src/checks/missing-content-for-arguments/index.spec.ts +0 -144
  263. package/src/checks/missing-content-for-arguments/index.ts +0 -46
  264. package/src/checks/pagination-size/index.spec.ts +0 -158
  265. package/src/checks/pagination-size/index.ts +0 -104
  266. package/src/checks/remote-asset/index.spec.ts +0 -280
  267. package/src/checks/remote-asset/index.ts +0 -238
  268. package/src/checks/reserved-doc-param-names/index.spec.ts +0 -62
  269. package/src/checks/reserved-doc-param-names/index.ts +0 -57
  270. package/src/checks/schema-presets-block-order/index.spec.ts +0 -344
  271. package/src/checks/schema-presets-block-order/index.ts +0 -154
  272. package/src/checks/schema-presets-static-blocks/index.spec.ts +0 -145
  273. package/src/checks/schema-presets-static-blocks/index.ts +0 -126
  274. package/src/checks/static-stylesheet-and-javascript-tags/index.spec.ts +0 -257
  275. package/src/checks/static-stylesheet-and-javascript-tags/index.ts +0 -48
  276. package/src/checks/unique-settings-id/index.spec.ts +0 -24
  277. package/src/checks/unique-settings-id/index.ts +0 -84
  278. package/src/checks/unique-settings-id/test-data.ts +0 -1191
  279. package/src/checks/unique-static-block-id/index.spec.ts +0 -55
  280. package/src/checks/unique-static-block-id/index.ts +0 -60
  281. package/src/checks/unrecognized-content-for-arguments/index.spec.ts +0 -145
  282. package/src/checks/unrecognized-content-for-arguments/index.ts +0 -55
  283. package/src/checks/valid-block-target/index.spec.ts +0 -1396
  284. package/src/checks/valid-block-target/index.ts +0 -142
  285. package/src/checks/valid-content-for-argument-types/index.spec.ts +0 -382
  286. package/src/checks/valid-content-for-argument-types/index.ts +0 -42
  287. package/src/checks/valid-content-for-arguments/index.spec.ts +0 -107
  288. package/src/checks/valid-content-for-arguments/index.ts +0 -98
  289. package/src/checks/valid-local-blocks/index.spec.ts +0 -286
  290. package/src/checks/valid-local-blocks/index.ts +0 -100
  291. package/src/checks/valid-local-blocks/valid-block-utils.ts +0 -97
  292. package/src/checks/valid-schema/index.spec.ts +0 -174
  293. package/src/checks/valid-schema/index.ts +0 -41
  294. package/src/checks/valid-schema-name/index.spec.ts +0 -112
  295. package/src/checks/valid-schema-name/index.ts +0 -75
  296. package/src/checks/valid-settings-key/index.spec.ts +0 -321
  297. package/src/checks/valid-settings-key/index.ts +0 -144
  298. package/src/checks/valid-static-block-type/index.spec.ts +0 -38
  299. package/src/checks/valid-static-block-type/index.ts +0 -58
  300. package/src/checks/valid-visible-if/index.spec.ts +0 -619
  301. package/src/checks/valid-visible-if/index.ts +0 -184
  302. package/src/checks/valid-visible-if/visible-if-utils.ts +0 -158
  303. package/src/tags/content-for.ts +0 -25
  304. package/src/to-schema.ts +0 -231
  305. package/src/types/schemas/section.ts +0 -86
  306. package/src/types/schemas/theme-block.ts +0 -34
  307. package/src/types/theme-schemas.ts +0 -80
  308. package/src/utils/block.ts +0 -300
  309. package/src/utils/markup.ts +0 -10
@@ -1,103 +1,75 @@
1
1
  import { beforeEach, describe, expect, it } from 'vitest';
2
- import {
3
- makeGetDefaultLocale,
4
- makeGetDefaultTranslations,
5
- makeGetMetafieldDefinitions,
6
- } from './context-utils';
2
+ import { makeGetDefaultLocale, makeGetDefaultTranslations } from './context-utils';
7
3
  import { MockFileSystem } from './test';
8
4
  import { AbstractFileSystem } from '@platformos/platformos-common';
9
5
 
10
6
  describe('Unit: getDefaultLocale', () => {
11
- let fs: AbstractFileSystem;
12
- beforeEach(() => {
13
- fs = new MockFileSystem(
7
+ it('should always return en (en.yml is the reference locale file)', async () => {
8
+ const fs: AbstractFileSystem = new MockFileSystem(
14
9
  {
15
- 'gitRootTheme/locales/en.default.json': JSON.stringify({ beverage: 'coffee' }),
16
- 'gitRootTheme/locales/fr.json': JSON.stringify({ beverage: 'coffee' }),
17
- 'gitRootTheme/snippet/foo.liquid': JSON.stringify({ beverage: 'coffee' }),
18
- 'frenchDefault/locales/fr.default.json': JSON.stringify({ beverage: 'café' }),
19
- 'frenchDefault/snippet/foo.liquid': JSON.stringify({ beverage: 'coffee' }),
20
- '.shopify/metafields.json': JSON.stringify({
21
- product: [
22
- {
23
- key: 'color',
24
- name: 'color',
25
- namespace: 'custom',
26
- description: 'the color of the product',
27
- type: {
28
- category: 'COLOR',
29
- name: 'color',
30
- },
31
- },
32
- ],
33
- }),
10
+ 'app/translations/en.yml': 'en:\n beverage: coffee\n',
11
+ 'app/translations/fr.yml': 'fr:\n beverage: café\n',
34
12
  },
35
- 'shopify-vfs:/',
13
+ 'platformos-vfs:/',
36
14
  );
37
- });
38
15
 
39
- it('should return the correct translations depending on the root', async () => {
40
- let getDefaultLocale = makeGetDefaultLocale(fs, 'shopify-vfs:/gitRootTheme');
16
+ const getDefaultLocale = makeGetDefaultLocale(fs, 'platformos-vfs:/');
41
17
  expect(await getDefaultLocale()).to.eql('en');
42
-
43
- getDefaultLocale = makeGetDefaultLocale(fs, 'shopify-vfs:/frenchDefault');
44
- expect(await getDefaultLocale()).to.eql('fr');
45
18
  });
46
19
 
47
- describe('Unit: makeGetMetafieldDefinitions', () => {
48
- it('should return metafield definitions in correct format', async () => {
49
- const getMetafieldDefinitions = makeGetMetafieldDefinitions(fs);
50
-
51
- let definitions = await getMetafieldDefinitions('shopify-vfs:/');
20
+ it('should return en even when no translation files exist', async () => {
21
+ const fs: AbstractFileSystem = new MockFileSystem({}, 'platformos-vfs:/');
22
+ const getDefaultLocale = makeGetDefaultLocale(fs, 'platformos-vfs:/');
23
+ expect(await getDefaultLocale()).to.eql('en');
24
+ });
52
25
 
53
- expect(definitions.product).toHaveLength(1);
54
- expect(definitions.product[0]).deep.equals({
55
- key: 'color',
56
- name: 'color',
57
- namespace: 'custom',
58
- description: 'the color of the product',
59
- type: {
60
- category: 'COLOR',
61
- name: 'color',
26
+ describe('Unit: getDefaultTranslationsFactory', () => {
27
+ it('should return translations from en.yml stripped of the locale prefix', async () => {
28
+ const fs: AbstractFileSystem = new MockFileSystem(
29
+ {
30
+ 'app/translations/en.yml': 'en:\n beverage: coffee\n',
31
+ 'app/translations/fr.yml': 'fr:\n beverage: café\n',
62
32
  },
63
- });
33
+ 'platformos-vfs:/',
34
+ );
35
+
36
+ const getDefaultTranslations = makeGetDefaultTranslations(fs, [], 'platformos-vfs:/');
37
+ expect(await getDefaultTranslations()).to.eql({ beverage: 'coffee' });
64
38
  });
65
39
 
66
- it("should return no metafield definitions if file isn't in correct format", async () => {
67
- fs = new MockFileSystem(
40
+ it('should return empty object when no en.yml exists', async () => {
41
+ const fs: AbstractFileSystem = new MockFileSystem(
68
42
  {
69
- '.shopify/metafields.json': JSON.stringify('uhoh'),
43
+ 'app/translations/fr.yml': 'fr:\n beverage: café\n',
70
44
  },
71
- 'shopify-vfs:/',
45
+ 'platformos-vfs:/',
72
46
  );
73
- const getMetafieldDefinitions = makeGetMetafieldDefinitions(fs);
74
47
 
75
- let definitions = await getMetafieldDefinitions('shopify-vfs:/');
76
-
77
- expect(definitions).deep.equals({
78
- article: [],
79
- blog: [],
80
- collection: [],
81
- company: [],
82
- company_location: [],
83
- location: [],
84
- market: [],
85
- order: [],
86
- page: [],
87
- product: [],
88
- variant: [],
89
- shop: [],
90
- });
48
+ const getDefaultTranslations = makeGetDefaultTranslations(fs, [], 'platformos-vfs:/');
49
+ expect(await getDefaultTranslations()).to.eql({});
91
50
  });
92
- });
93
51
 
94
- describe('Unit: getDefaultTranslationsFactory', () => {
95
- it('should return the correct translations depending on the root', async () => {
96
- let getDefaultTranslations = makeGetDefaultTranslations(fs, [], 'shopify-vfs:/gitRootTheme');
97
- expect(await getDefaultTranslations()).to.eql({ beverage: 'coffee' });
52
+ it('should prefer translations from the in-memory app buffer over the filesystem', async () => {
53
+ const fs: AbstractFileSystem = new MockFileSystem(
54
+ {
55
+ 'app/translations/en.yml': 'en:\n beverage: coffee\n',
56
+ },
57
+ 'platformos-vfs:/',
58
+ );
98
59
 
99
- getDefaultTranslations = makeGetDefaultTranslations(fs, [], 'shopify-vfs:/frenchDefault');
100
- expect(await getDefaultTranslations()).to.eql({ beverage: 'café' });
60
+ // Simulate an open buffer with different content
61
+ const { toSourceCode } = await import('./to-source-code');
62
+ const bufferedSourceCode = toSourceCode(
63
+ 'platformos-vfs:/app/translations/en.yml',
64
+ 'en:\n beverage: tea\n',
65
+ );
66
+
67
+ const getDefaultTranslations = makeGetDefaultTranslations(
68
+ fs,
69
+ [bufferedSourceCode],
70
+ 'platformos-vfs:/',
71
+ );
72
+ expect(await getDefaultTranslations()).to.eql({ beverage: 'tea' });
101
73
  });
102
74
  });
103
75
  });
@@ -1,15 +1,7 @@
1
- import { URI, Utils } from 'vscode-uri';
1
+ import { load } from 'js-yaml';
2
2
  import { AbstractFileSystem, FileTuple, FileType, UriString } from '@platformos/platformos-common';
3
- import { parseJSON } from './json';
4
3
  import { join } from './path';
5
- import {
6
- MetafieldCategory,
7
- MetafieldDefinitionMap,
8
- SourceCodeType,
9
- Theme,
10
- Translations,
11
- } from './types';
12
- import { isError } from './utils';
4
+ import { SourceCodeType, App, Translations } from './types';
13
5
 
14
6
  export type FileExists = (uri: string) => Promise<boolean>;
15
7
 
@@ -33,71 +25,49 @@ export const makeFileSize = (fs: AbstractFileSystem) =>
33
25
  }
34
26
  };
35
27
 
36
- export const makeGetDefaultLocaleFileUri = getDefaultLocaleFileUriFactoryFactory('default.json');
37
- export const makeGetDefaultSchemaLocaleFileUri =
38
- getDefaultLocaleFileUriFactoryFactory('.default.schema.json');
39
- function getDefaultLocaleFileUriFactoryFactory(postfix = '.default.json') {
40
- return function getDefaultLocaleFileUriFactory(fs: AbstractFileSystem) {
41
- return (rootUri: string) => getDefaultLocaleFile(fs, rootUri, postfix);
42
- };
43
- }
28
+ export const makeGetDefaultLocaleFileUri = (fs: AbstractFileSystem) => (rootUri: string) =>
29
+ getDefaultLocaleFile(fs, rootUri);
44
30
 
45
- export const makeGetDefaultLocale = getDefaultLocaleFactoryFactory('.default.json');
46
- export const makeGetDefaultSchemaLocale = getDefaultLocaleFactoryFactory('.default.schema.json');
47
- function getDefaultLocaleFactoryFactory(postfix = '.default.json') {
48
- return function getDefaultLocaleFactory(fs: AbstractFileSystem, rootUri: string) {
49
- return cached(() => getDefaultLocale(fs, rootUri, postfix));
50
- };
51
- }
31
+ export const makeGetDefaultLocale = (fs: AbstractFileSystem, rootUri: string) =>
32
+ cached(() => getDefaultLocale(fs, rootUri));
52
33
 
53
- export const makeGetDefaultTranslations = getDefaultTranslationsFactoryFactory('.default.json');
54
- export const makeGetDefaultSchemaTranslations =
55
- getDefaultTranslationsFactoryFactory('.default.schema.json');
56
- // prettier-ignore
57
- function getDefaultTranslationsFactoryFactory(postfix = '.default.json') {
58
- return function getDefaultTranslationsFactory(fs: AbstractFileSystem, theme: Theme, rootUri: string) {
59
- return cached(() => getDefaultTranslations(fs, theme, rootUri, postfix));
60
- };
61
- }
34
+ export const makeGetDefaultTranslations = (fs: AbstractFileSystem, app: App, rootUri: string) =>
35
+ cached(() => getDefaultTranslations(fs, app, rootUri));
62
36
 
63
37
  async function getDefaultLocaleFile(
64
38
  fs: AbstractFileSystem,
65
39
  rootUri: string,
66
- postfix = '.default.json',
67
- ) {
68
- const files = await fs.readDirectory(join(rootUri, 'locales'));
69
- return files.find(([uri]) => uri.endsWith(postfix))?.[0];
70
- }
71
-
72
- async function getDefaultLocale(
73
- fs: AbstractFileSystem,
74
- rootUri: string,
75
- postfix: string,
76
- ): Promise<string> {
40
+ ): Promise<string | undefined> {
41
+ const enYmlUri = join(rootUri, 'app/translations/en.yml');
77
42
  try {
78
- const defaultLocaleFile = await getDefaultLocaleFile(fs, rootUri, postfix);
79
- if (!defaultLocaleFile) return 'en';
80
- const defaultLocaleFileName = Utils.basename(URI.parse(defaultLocaleFile));
81
- return defaultLocaleFileName.split('.')[0];
82
- } catch (error) {
83
- console.error(error);
84
- return 'en';
43
+ await fs.stat(enYmlUri);
44
+ return enYmlUri;
45
+ } catch {
46
+ return undefined;
85
47
  }
86
48
  }
87
49
 
50
+ async function getDefaultLocale(_fs: AbstractFileSystem, _rootUri: string): Promise<string> {
51
+ // In platformOS, en.yml is always the reference translation file
52
+ return 'en';
53
+ }
54
+
88
55
  async function getDefaultTranslations(
89
56
  fs: AbstractFileSystem,
90
- theme: Theme,
57
+ app: App,
91
58
  rootUri: string,
92
- postfix: string,
93
59
  ): Promise<Translations> {
94
60
  try {
95
- const bufferTranslations = getDefaultTranslationsFromBuffer(theme, postfix);
61
+ const bufferTranslations = getDefaultTranslationsFromBuffer(app);
96
62
  if (bufferTranslations) return bufferTranslations;
97
- const defaultLocaleFile = await getDefaultLocaleFile(fs, rootUri, postfix);
63
+ const defaultLocaleFile = await getDefaultLocaleFile(fs, rootUri);
98
64
  if (!defaultLocaleFile) return {};
99
- const defaultTranslationsFile = await fs.readFile(defaultLocaleFile);
100
- return parseJSON(defaultTranslationsFile, {});
65
+ const yamlContent = await fs.readFile(defaultLocaleFile);
66
+ const data = load(yamlContent) as Record<string, any>;
67
+ if (!data || typeof data !== 'object') return {};
68
+ // YAML translation files wrap content under the locale key: { en: { hello: 'Hello' } }
69
+ const localeKey = Object.keys(data)[0];
70
+ return (localeKey && data[localeKey]) ?? {};
101
71
  } catch (error) {
102
72
  console.error(error);
103
73
  return {};
@@ -105,17 +75,19 @@ async function getDefaultTranslations(
105
75
  }
106
76
 
107
77
  /** It might be that you have an open buffer, we prefer translations from there if available */
108
- function getDefaultTranslationsFromBuffer(theme: Theme, postfix: string): Translations | undefined {
109
- const defaultTranslationsSourceCode = theme.find(
110
- (sourceCode) =>
111
- sourceCode.type === SourceCodeType.JSON &&
112
- sourceCode.uri.match(/locales/) &&
113
- sourceCode.uri.endsWith(postfix),
78
+ function getDefaultTranslationsFromBuffer(app: App): Translations | undefined {
79
+ const defaultTranslationsSourceCode = app.find(
80
+ (sourceCode) => sourceCode.type === SourceCodeType.YAML && sourceCode.uri.endsWith('/en.yml'),
114
81
  );
115
82
  if (!defaultTranslationsSourceCode) return undefined;
116
- const translations = parseJSON(defaultTranslationsSourceCode.source);
117
- if (isError(translations)) return undefined;
118
- return translations;
83
+ try {
84
+ const data = load(defaultTranslationsSourceCode.source) as Record<string, any>;
85
+ if (!data || typeof data !== 'object') return undefined;
86
+ const localeKey = Object.keys(data)[0];
87
+ return (localeKey && data[localeKey]) ?? undefined;
88
+ } catch {
89
+ return undefined;
90
+ }
119
91
  }
120
92
 
121
93
  function cached<T>(fn: () => Promise<T>): () => Promise<T>;
@@ -157,64 +129,3 @@ const ignoredFolders = ['.git', 'node_modules', 'dist', 'build', 'tmp', 'vendor'
157
129
  function isIgnored([uri, type]: FileTuple) {
158
130
  return type === FileType.Directory && ignoredFolders.some((folder) => uri.endsWith(folder));
159
131
  }
160
-
161
- export const FETCHED_METAFIELD_CATEGORIES: MetafieldCategory[] = [
162
- 'article',
163
- 'blog',
164
- 'collection',
165
- 'company',
166
- 'company_location',
167
- 'location',
168
- 'market',
169
- 'order',
170
- 'page',
171
- 'product',
172
- 'variant',
173
- 'shop',
174
- ];
175
-
176
- export const makeGetMetafieldDefinitions = (fs: AbstractFileSystem) =>
177
- async function (rootUri: string): Promise<MetafieldDefinitionMap> {
178
- const definitions = {
179
- article: [],
180
- blog: [],
181
- collection: [],
182
- company: [],
183
- company_location: [],
184
- location: [],
185
- market: [],
186
- order: [],
187
- page: [],
188
- product: [],
189
- variant: [],
190
- shop: [],
191
- } as MetafieldDefinitionMap;
192
-
193
- try {
194
- const content = await fs.readFile(join(rootUri, '.shopify', 'metafields.json'));
195
- const json = parseJSON(content);
196
-
197
- if (isError(json)) return definitions;
198
-
199
- return FETCHED_METAFIELD_CATEGORIES.reduce((definitions, group) => {
200
- try {
201
- definitions[group] = json[group].map((definition: any) => ({
202
- key: definition.key,
203
- name: definition.name,
204
- namespace: definition.namespace,
205
- description: definition.description,
206
- type: {
207
- category: definition.type.category,
208
- name: definition.type.name,
209
- },
210
- }));
211
- } catch (error) {
212
- // If there are errors in the file, we ignore it
213
- }
214
-
215
- return definitions;
216
- }, definitions);
217
- } catch (err) {
218
- return definitions;
219
- }
220
- };
@@ -259,4 +259,39 @@ ${buildComment('theme-check-enable')}
259
259
  });
260
260
  });
261
261
  });
262
+
263
+ describe('platformos-check prefix', () => {
264
+ it('should disable checks using platformos-check-disable prefix', async () => {
265
+ for (const buildComment of commentTypes) {
266
+ const file = `${buildComment('platformos-check-disable LiquidFilter')}
267
+ {{ 'asset' | random_filter }}
268
+ {% render 'something' %}`;
269
+
270
+ const offenses = await check({ 'code.liquid': file }, checks);
271
+ expect(offenses).to.have.length(1);
272
+ expectRenderMarkupOffense(offenses, 'something.liquid');
273
+ }
274
+ });
275
+
276
+ it('should disable all checks using platformos-check-disable prefix', async () => {
277
+ for (const buildComment of commentTypes) {
278
+ const file = `${buildComment('platformos-check-disable')}
279
+ {{ 'asset' | random_filter }}
280
+ {% render 'something' %}`;
281
+
282
+ const offenses = await check({ 'code.liquid': file }, checks);
283
+ expect(offenses).to.have.length(0);
284
+ }
285
+ });
286
+
287
+ it('should disable next line using platformos-check-disable-next-line prefix', async () => {
288
+ const file = `{% # platformos-check-disable-next-line %}
289
+ {% render 'something' %}
290
+ {% render 'other-thing' %}`;
291
+
292
+ const offenses = await check({ 'code.liquid': file }, checks);
293
+ expect(offenses).to.have.length(1);
294
+ expectRenderMarkupOffense(offenses, 'other-thing.liquid');
295
+ });
296
+ });
262
297
  });
@@ -24,7 +24,9 @@ export function createDisabledChecksModule() {
24
24
  node: LiquidTag | LiquidRawTag,
25
25
  ) {
26
26
  const [_, command, checksJoined] =
27
- value.trim().match(/^(?:theme\-check\-(disable-next-line|disable|enable)) ?(.*)/) || [];
27
+ value
28
+ .trim()
29
+ .match(/^(?:(?:platformos|theme)\-check\-(disable-next-line|disable|enable)) ?(.*)/) || [];
28
30
 
29
31
  const checks = checksJoined ? checksJoined.split(/,[ ]*/) : [SPECIFIC_CHECK_NOT_DEFINED];
30
32
 
@@ -133,7 +135,7 @@ export function findNextLinePosition(
133
135
  * E.g. The following disables check for `elsif` tag
134
136
  *
135
137
  * {% if condition %}
136
- * {% #theme-check-disable-next-line %}
138
+ * {% #platformos-check-disable-next-line %}
137
139
  * {% elsif other_condition %}
138
140
  * {{ prouduct }}
139
141
  * {% endif %}
package/src/find-root.ts CHANGED
@@ -5,13 +5,11 @@ type FileExists = (uri: string) => Promise<boolean>;
5
5
 
6
6
  async function isRoot(dir: UriString, fileExists: FileExists) {
7
7
  return or(
8
- // .pos config file and app directory exists
9
- and(
10
- fileExists(path.join(dir, '.pos')),
11
- fileExists(path.join(dir, 'app')),
12
- fileExists(path.join(dir, 'modules')),
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 "root" of a theme or theme app extension. The root is the
35
- * directory that contains a `.theme-check.yml` file, a `.git` directory, or a
36
- * `shopify.extension.toml` file.
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
- * So you can think of this function as the function that infers where a .theme-check.yml
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: that this is not the theme root. The config file might have a `root` entry in it
45
- * that points to somewhere else.
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 mockTheme = {
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(mockTheme, offenses);
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({
@@ -1,4 +1,4 @@
1
- import { FixApplicator, Offense, SourceCodeType, Theme } from '../types';
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 a theme, list of offenses and a fixApplicator and runs all the
12
- * safe ones on the theme.
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: Theme, offenses: Offense[], applyFixes: FixApplicator) {
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
  }
@@ -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,