@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.
Files changed (304) hide show
  1. package/CHANGELOG.md +16 -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/find-root.d.ts +7 -10
  84. package/dist/find-root.js +10 -17
  85. package/dist/find-root.js.map +1 -1
  86. package/dist/fixes/autofix.d.ts +4 -4
  87. package/dist/fixes/autofix.js +2 -2
  88. package/dist/fixes/autofix.js.map +1 -1
  89. package/dist/fixes/correctors/index.js +4 -0
  90. package/dist/fixes/correctors/index.js.map +1 -1
  91. package/dist/index.d.ts +4 -5
  92. package/dist/index.js +34 -17
  93. package/dist/index.js.map +1 -1
  94. package/dist/jsonc/parse.d.ts +1 -1
  95. package/dist/jsonc/parse.js +1 -1
  96. package/dist/liquid-doc/arguments.d.ts +7 -8
  97. package/dist/liquid-doc/arguments.js +20 -28
  98. package/dist/liquid-doc/arguments.js.map +1 -1
  99. package/dist/liquid-doc/liquidDoc.d.ts +1 -1
  100. package/dist/liquid-doc/liquidDoc.js.map +1 -1
  101. package/dist/liquid-doc/utils.d.ts +1 -1
  102. package/dist/liquid-doc/utils.js +4 -3
  103. package/dist/liquid-doc/utils.js.map +1 -1
  104. package/dist/path.d.ts +1 -0
  105. package/dist/path.js +5 -1
  106. package/dist/path.js.map +1 -1
  107. package/dist/test/MockApp.d.ts +16 -0
  108. package/dist/test/MockApp.js +16 -0
  109. package/dist/test/MockApp.js.map +1 -0
  110. package/dist/test/MockFileSystem.d.ts +3 -3
  111. package/dist/test/MockFileSystem.js +6 -6
  112. package/dist/test/MockFileSystem.js.map +1 -1
  113. package/dist/test/index.d.ts +1 -1
  114. package/dist/test/index.js +1 -1
  115. package/dist/test/index.js.map +1 -1
  116. package/dist/test/test-helper.d.ts +10 -9
  117. package/dist/test/test-helper.js +15 -106
  118. package/dist/test/test-helper.js.map +1 -1
  119. package/dist/to-source-code.d.ts +4 -3
  120. package/dist/to-source-code.js +20 -0
  121. package/dist/to-source-code.js.map +1 -1
  122. package/dist/tsconfig.tsbuildinfo +1 -1
  123. package/dist/types/platformos-liquid-docs.d.ts +128 -0
  124. package/dist/types/platformos-liquid-docs.js +3 -0
  125. package/dist/types/platformos-liquid-docs.js.map +1 -0
  126. package/dist/types/schemas/index.d.ts +0 -2
  127. package/dist/types/schemas/index.js.map +1 -1
  128. package/dist/types.d.ts +18 -67
  129. package/dist/types.js +3 -5
  130. package/dist/types.js.map +1 -1
  131. package/dist/utils/file-utils.js +1 -2
  132. package/dist/utils/file-utils.js.map +1 -1
  133. package/dist/utils/index.d.ts +0 -1
  134. package/dist/utils/index.js +0 -1
  135. package/dist/utils/index.js.map +1 -1
  136. package/dist/yaml/parse.d.ts +5 -0
  137. package/dist/yaml/parse.js +94 -0
  138. package/dist/yaml/parse.js.map +1 -0
  139. package/package.json +9 -9
  140. package/src/{AugmentedThemeDocset.spec.ts → AugmentedPlatformOSDocset.spec.ts} +47 -34
  141. package/src/AugmentedPlatformOSDocset.ts +89 -0
  142. package/src/JSONValidator.ts +1 -1
  143. package/src/checks/deprecated-filter/index.spec.ts +76 -248
  144. package/src/checks/deprecated-filter/index.ts +5 -53
  145. package/src/checks/deprecated-tag/index.spec.ts +85 -34
  146. package/src/checks/deprecated-tag/index.ts +27 -22
  147. package/src/checks/duplicate-function-arguments/index.ts +1 -1
  148. package/src/checks/duplicate-render-partial-arguments/index.ts +1 -1
  149. package/src/checks/graphql/index.ts +1 -1
  150. package/src/checks/img-width-and-height/index.ts +1 -1
  151. package/src/checks/index.ts +11 -80
  152. package/src/checks/invalid-hash-assign-target/index.spec.ts +14 -14
  153. package/src/checks/json-syntax-error/index.ts +1 -1
  154. package/src/checks/liquid-html-syntax-error/checks/InvalidBooleanExpression.spec.ts +0 -11
  155. package/src/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.spec.ts +1 -2
  156. package/src/checks/liquid-html-syntax-error/index.spec.ts +1 -6
  157. package/src/checks/liquid-html-syntax-error/index.ts +2 -2
  158. package/src/checks/matching-translations/index.spec.ts +89 -346
  159. package/src/checks/matching-translations/index.ts +24 -35
  160. package/src/checks/metadata-params/index.ts +5 -7
  161. package/src/checks/missing-asset/index.ts +1 -1
  162. package/src/checks/{missing-template → missing-partial}/index.spec.ts +6 -6
  163. package/src/checks/{missing-template → missing-partial}/index.ts +6 -20
  164. package/src/checks/orphaned-partial/index.ts +3 -3
  165. package/src/checks/parser-blocking-script/index.spec.ts +0 -118
  166. package/src/checks/parser-blocking-script/index.ts +3 -33
  167. package/src/checks/parser-blocking-script/suggestions.ts +1 -28
  168. package/src/checks/translation-key-exists/index.ts +1 -1
  169. package/src/checks/unclosed-html-element/index.ts +5 -1
  170. package/src/checks/undefined-object/index.spec.ts +3 -109
  171. package/src/checks/undefined-object/index.ts +8 -33
  172. package/src/checks/unique-doc-param-names/index.ts +1 -1
  173. package/src/checks/unknown-filter/index.spec.ts +2 -2
  174. package/src/checks/unknown-filter/index.ts +3 -3
  175. package/src/checks/unknown-property/index.ts +1 -1
  176. package/src/checks/unrecognized-render-partial-arguments/index.spec.ts +5 -5
  177. package/src/checks/unrecognized-render-partial-arguments/index.ts +2 -5
  178. package/src/checks/unused-assign/index.spec.ts +0 -30
  179. package/src/checks/unused-assign/index.ts +1 -1
  180. package/src/checks/unused-doc-param/index.ts +1 -1
  181. package/src/checks/utils.ts +1 -1
  182. package/src/checks/valid-doc-param-types/index.ts +4 -4
  183. package/src/checks/valid-html-translation/index.spec.ts +42 -32
  184. package/src/checks/valid-html-translation/index.ts +7 -7
  185. package/src/checks/valid-json/index.ts +1 -1
  186. package/src/checks/valid-render-partial-argument-types/index.ts +2 -5
  187. package/src/checks/variable-name/index.ts +1 -1
  188. package/src/context-utils.spec.ts +49 -77
  189. package/src/context-utils.ts +39 -128
  190. package/src/disabled-checks/index.spec.ts +35 -0
  191. package/src/disabled-checks/index.ts +4 -2
  192. package/src/find-root.ts +12 -22
  193. package/src/fixes/autofix.spec.ts +2 -2
  194. package/src/fixes/autofix.ts +4 -4
  195. package/src/fixes/correctors/index.ts +4 -0
  196. package/src/ignore.spec.ts +0 -1
  197. package/src/index.ts +33 -21
  198. package/src/jsonc/parse.ts +1 -1
  199. package/src/liquid-doc/arguments.spec.ts +19 -45
  200. package/src/liquid-doc/arguments.ts +26 -39
  201. package/src/liquid-doc/liquidDoc.ts +1 -2
  202. package/src/liquid-doc/utils.ts +4 -3
  203. package/src/path.ts +1 -0
  204. package/src/test/{MockTheme.ts → MockApp.ts} +1 -1
  205. package/src/test/MockFileSystem.ts +9 -6
  206. package/src/test/index.ts +1 -1
  207. package/src/test/test-helper.ts +29 -127
  208. package/src/to-source-code.ts +20 -1
  209. package/src/types/{theme-liquid-docs.ts → platformos-liquid-docs.ts} +8 -13
  210. package/src/types/schemas/index.ts +0 -2
  211. package/src/types.ts +21 -92
  212. package/src/utils/file-utils.ts +0 -1
  213. package/src/utils/index.ts +0 -1
  214. package/src/yaml/parse.ts +111 -0
  215. package/src/AugmentedThemeDocset.ts +0 -137
  216. package/src/checks/app-block-missing-schema/index.spec.ts +0 -121
  217. package/src/checks/app-block-missing-schema/index.ts +0 -46
  218. package/src/checks/app-block-valid-tags/index.spec.ts +0 -96
  219. package/src/checks/app-block-valid-tags/index.ts +0 -54
  220. package/src/checks/asset-preload/index.spec.ts +0 -78
  221. package/src/checks/asset-preload/index.ts +0 -65
  222. package/src/checks/asset-size-app-block-css/index.spec.ts +0 -88
  223. package/src/checks/asset-size-app-block-css/index.ts +0 -78
  224. package/src/checks/asset-size-app-block-javascript/index.spec.ts +0 -66
  225. package/src/checks/asset-size-app-block-javascript/index.ts +0 -78
  226. package/src/checks/asset-size-css/index.spec.ts +0 -166
  227. package/src/checks/asset-size-css/index.ts +0 -160
  228. package/src/checks/asset-size-javascript/index.spec.ts +0 -184
  229. package/src/checks/asset-size-javascript/index.ts +0 -144
  230. package/src/checks/block-id-usage/index.spec.ts +0 -76
  231. package/src/checks/block-id-usage/index.ts +0 -72
  232. package/src/checks/cdn-preconnect/index.spec.ts +0 -40
  233. package/src/checks/cdn-preconnect/index.ts +0 -43
  234. package/src/checks/content-for-header-modification/index.spec.ts +0 -65
  235. package/src/checks/content-for-header-modification/index.ts +0 -72
  236. package/src/checks/deprecate-bgsizes/index.spec.ts +0 -41
  237. package/src/checks/deprecate-bgsizes/index.ts +0 -49
  238. package/src/checks/deprecate-lazysizes/index.spec.ts +0 -26
  239. package/src/checks/deprecate-lazysizes/index.ts +0 -58
  240. package/src/checks/deprecated-filter/fixes.ts +0 -264
  241. package/src/checks/deprecated-fonts-on-sections-and-blocks/deprecated-fonts-data.ts +0 -1343
  242. package/src/checks/deprecated-fonts-on-sections-and-blocks/index.spec.ts +0 -613
  243. package/src/checks/deprecated-fonts-on-sections-and-blocks/index.ts +0 -284
  244. package/src/checks/deprecated-fonts-on-settings-schema/index.spec.ts +0 -102
  245. package/src/checks/deprecated-fonts-on-settings-schema/index.ts +0 -66
  246. package/src/checks/duplicate-content-for-arguments/index.spec.ts +0 -98
  247. package/src/checks/duplicate-content-for-arguments/index.ts +0 -43
  248. package/src/checks/empty-block-content/index.spec.ts +0 -117
  249. package/src/checks/empty-block-content/index.ts +0 -60
  250. package/src/checks/hardcoded-routes/index.spec.ts +0 -58
  251. package/src/checks/hardcoded-routes/index.ts +0 -100
  252. package/src/checks/json-missing-block/index.spec.ts +0 -435
  253. package/src/checks/json-missing-block/index.ts +0 -56
  254. package/src/checks/json-missing-block/missing-block-utils.ts +0 -147
  255. package/src/checks/liquid-free-settings/index.spec.ts +0 -180
  256. package/src/checks/liquid-free-settings/index.ts +0 -79
  257. package/src/checks/missing-content-for-arguments/index.spec.ts +0 -144
  258. package/src/checks/missing-content-for-arguments/index.ts +0 -46
  259. package/src/checks/pagination-size/index.spec.ts +0 -158
  260. package/src/checks/pagination-size/index.ts +0 -104
  261. package/src/checks/remote-asset/index.spec.ts +0 -280
  262. package/src/checks/remote-asset/index.ts +0 -238
  263. package/src/checks/reserved-doc-param-names/index.spec.ts +0 -62
  264. package/src/checks/reserved-doc-param-names/index.ts +0 -57
  265. package/src/checks/schema-presets-block-order/index.spec.ts +0 -344
  266. package/src/checks/schema-presets-block-order/index.ts +0 -154
  267. package/src/checks/schema-presets-static-blocks/index.spec.ts +0 -145
  268. package/src/checks/schema-presets-static-blocks/index.ts +0 -126
  269. package/src/checks/static-stylesheet-and-javascript-tags/index.spec.ts +0 -257
  270. package/src/checks/static-stylesheet-and-javascript-tags/index.ts +0 -48
  271. package/src/checks/unique-settings-id/index.spec.ts +0 -24
  272. package/src/checks/unique-settings-id/index.ts +0 -84
  273. package/src/checks/unique-settings-id/test-data.ts +0 -1191
  274. package/src/checks/unique-static-block-id/index.spec.ts +0 -55
  275. package/src/checks/unique-static-block-id/index.ts +0 -60
  276. package/src/checks/unrecognized-content-for-arguments/index.spec.ts +0 -145
  277. package/src/checks/unrecognized-content-for-arguments/index.ts +0 -55
  278. package/src/checks/valid-block-target/index.spec.ts +0 -1396
  279. package/src/checks/valid-block-target/index.ts +0 -142
  280. package/src/checks/valid-content-for-argument-types/index.spec.ts +0 -382
  281. package/src/checks/valid-content-for-argument-types/index.ts +0 -42
  282. package/src/checks/valid-content-for-arguments/index.spec.ts +0 -107
  283. package/src/checks/valid-content-for-arguments/index.ts +0 -98
  284. package/src/checks/valid-local-blocks/index.spec.ts +0 -286
  285. package/src/checks/valid-local-blocks/index.ts +0 -100
  286. package/src/checks/valid-local-blocks/valid-block-utils.ts +0 -97
  287. package/src/checks/valid-schema/index.spec.ts +0 -174
  288. package/src/checks/valid-schema/index.ts +0 -41
  289. package/src/checks/valid-schema-name/index.spec.ts +0 -112
  290. package/src/checks/valid-schema-name/index.ts +0 -75
  291. package/src/checks/valid-settings-key/index.spec.ts +0 -321
  292. package/src/checks/valid-settings-key/index.ts +0 -144
  293. package/src/checks/valid-static-block-type/index.spec.ts +0 -38
  294. package/src/checks/valid-static-block-type/index.ts +0 -58
  295. package/src/checks/valid-visible-if/index.spec.ts +0 -619
  296. package/src/checks/valid-visible-if/index.ts +0 -184
  297. package/src/checks/valid-visible-if/visible-if-utils.ts +0 -158
  298. package/src/tags/content-for.ts +0 -25
  299. package/src/to-schema.ts +0 -231
  300. package/src/types/schemas/section.ts +0 -86
  301. package/src/types/schemas/theme-block.ts +0 -34
  302. package/src/types/theme-schemas.ts +0 -80
  303. package/src/utils/block.ts +0 -300
  304. package/src/utils/markup.ts +0 -10
@@ -1,1396 +0,0 @@
1
- import { expect, describe, it } from 'vitest';
2
- import { ValidBlockTarget } from './index';
3
- import { check, MockTheme } from '../../test';
4
- import { Preset, Setting } from '../../types/schemas';
5
-
6
- describe('Module: ValidBlockTarget', () => {
7
- const paths = ['sections', 'blocks'];
8
-
9
- describe('File Existence Tests', () => {
10
- paths.forEach((path) => {
11
- it(`should ignore @app and @theme block types in ${path} bucket`, async () => {
12
- const theme: MockTheme = {
13
- [`${path}/app-theme.liquid`]: `
14
- {% schema %}
15
- {
16
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
17
- "blocks": [
18
- {
19
- "type": "@app"
20
- },
21
- {
22
- "type": "@theme"
23
- }
24
- ]
25
- }
26
- {% endschema %}
27
- `,
28
- };
29
-
30
- const offenses = await check(theme, [ValidBlockTarget]);
31
- expect(offenses).to.be.empty;
32
- });
33
-
34
- it(`should not report any errors when all block files exist (${path} bucket)`, async () => {
35
- const theme: MockTheme = {
36
- 'blocks/text.liquid': '',
37
- [`${path}/valid.liquid`]: `
38
- {% schema %}
39
- {
40
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
41
- "blocks": [
42
- {
43
- "type": "text"
44
- }
45
- ]
46
- }
47
- {% endschema %}
48
- `,
49
- };
50
-
51
- const offenses = await check(theme, [ValidBlockTarget]);
52
- expect(offenses).to.be.empty;
53
- });
54
-
55
- it(`should report errors when root level block file does not exist (${path} bucket)`, async () => {
56
- const theme: MockTheme = {
57
- [`${path}/invalid-section.liquid`]: `
58
- {% schema %}
59
- {
60
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
61
- "blocks": [
62
- {
63
- "type": "invalid"
64
- }
65
- ]
66
- }
67
- {% endschema %}
68
- `,
69
- };
70
-
71
- const offenses = await check(theme, [ValidBlockTarget]);
72
- expect(offenses).to.have.length(1);
73
- expect(offenses[0].message).to.equal("Theme block 'blocks/invalid.liquid' does not exist.");
74
- });
75
-
76
- it(`should report an error when a preset defined block file does not exist (${path} bucket)`, async () => {
77
- const theme: MockTheme = {
78
- [`${path}/invalid-block.liquid`]: `
79
- {% schema %}
80
- {
81
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
82
- "blocks": [
83
- {
84
- "type": "@theme"
85
- }
86
- ],
87
- "presets": [
88
- {
89
- "name": "Default",
90
- "blocks": [
91
- {
92
- "type": "missing_block"
93
- }
94
- ]
95
- }
96
- ]
97
- }
98
- {% endschema %}
99
- `,
100
- };
101
-
102
- const offenses = await check(theme, [ValidBlockTarget]);
103
- expect(offenses).to.have.length(1);
104
- expect(offenses[0].message).to.equal(
105
- "Theme block 'blocks/missing_block.liquid' does not exist.",
106
- );
107
- });
108
-
109
- if (path === 'sections') {
110
- it(`should report an error when default defined block file does not exist`, async () => {
111
- const theme: MockTheme = {
112
- [`${path}/invalid-file.liquid`]: `
113
- {% schema %}
114
- {
115
- "name": "Section name",
116
- "blocks": [
117
- {
118
- "type": "@theme"
119
- }
120
- ],
121
- "default": {
122
- "title": "Default",
123
- "blocks": [
124
- {
125
- "name": "some block",
126
- "type": "missing_block"
127
- }
128
- ]
129
- }
130
- }
131
- {% endschema %}
132
- `,
133
- };
134
-
135
- const offenses = await check(theme, [ValidBlockTarget]);
136
- expect(offenses).to.have.length(1);
137
- expect(offenses).to.containOffense(
138
- "Theme block 'blocks/missing_block.liquid' does not exist.",
139
- );
140
- });
141
- }
142
-
143
- it(`should not report subsequent errors in present defined blocks if error in root level (${path} bucket)`, async () => {
144
- const theme: MockTheme = {
145
- [`${path}/invalid-block.liquid`]: `
146
- {% schema %}
147
- {
148
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
149
- "blocks": [
150
- {
151
- "type": "invalid"
152
- }
153
- ],
154
- "presets": [
155
- {
156
- "name": "Default",
157
- "blocks": [
158
- {
159
- "type": "text"
160
- }
161
- ]
162
- }
163
- ]
164
- }
165
- {% endschema %}
166
- `,
167
- };
168
-
169
- const offenses = await check(theme, [ValidBlockTarget]);
170
- expect(offenses).to.have.length(1);
171
- expect(offenses[0].message).to.equal("Theme block 'blocks/invalid.liquid' does not exist.");
172
- });
173
-
174
- it(`should report an error when a preset defined block file does not exist with hash-style presets (${path} bucket)`, async () => {
175
- const theme: MockTheme = {
176
- [`${path}/invalid-block.liquid`]: `
177
- {% schema %}
178
- {
179
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
180
- "blocks": [
181
- {
182
- "type": "@theme"
183
- }
184
- ],
185
- "presets": [
186
- {
187
- "name": "Default",
188
- "blocks": {
189
- "missing_block_hash": {
190
- "type": "missing_block"
191
- }
192
- },
193
- "block_order": ["missing_block_hash"]
194
- }
195
- ]
196
- }
197
- {% endschema %}
198
- `,
199
- };
200
-
201
- const offenses = await check(theme, [ValidBlockTarget]);
202
- expect(offenses).to.have.length(1);
203
- expect(offenses[0].message).to.equal(
204
- "Theme block 'blocks/missing_block.liquid' does not exist.",
205
- );
206
- });
207
-
208
- it(`should not report an error when a preset defined block file exists with hash-style presets (${path} bucket)`, async () => {
209
- const theme: MockTheme = {
210
- 'blocks/text.liquid': '',
211
- [`${path}/invalid-block.liquid`]: `
212
- {% schema %}
213
- {
214
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
215
- "blocks": [
216
- {
217
- "type": "@theme"
218
- }
219
- ],
220
- "presets": [
221
- {
222
- "name": "Default",
223
- "blocks": {
224
- "text_block": {
225
- "type": "text"
226
- }
227
- },
228
- "block_order": ["text_block"]
229
- }
230
- ]
231
- }
232
- {% endschema %}
233
- `,
234
- };
235
-
236
- const offenses = await check(theme, [ValidBlockTarget]);
237
- expect(offenses).to.be.empty;
238
- });
239
- });
240
-
241
- it('should not report errors for locally scoped blocks at root level', async () => {
242
- const theme: MockTheme = {
243
- 'sections/local-blocks.liquid': `
244
- {% schema %}
245
- {
246
- "name": "Section name",
247
- "blocks": [
248
- {
249
- "type": "local_block",
250
- "name": "Local block"
251
- }
252
- ]
253
- }
254
- {% endschema %}
255
- `,
256
- };
257
-
258
- const offenses = await check(theme, [ValidBlockTarget]);
259
- expect(offenses).to.be.empty;
260
- });
261
- });
262
-
263
- describe('Allowed Targeting Tests', () => {
264
- paths.forEach((path) => {
265
- it(`should report an error when a preset defined block is not specified at root level (${path} bucket)`, async () => {
266
- const theme: MockTheme = {
267
- 'blocks/text.liquid': '',
268
- [`${path}/invalid-preset.liquid`]: `
269
- {% schema %}
270
- {
271
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
272
- "blocks": [
273
- {
274
- "type": "text"
275
- }
276
- ],
277
- "presets": [
278
- {
279
- "name": "Default preset",
280
- "blocks": [
281
- {
282
- "type": "invalid_preset_block"
283
- }
284
- ]
285
- }
286
- ]
287
- }
288
- {% endschema %}
289
- `,
290
- };
291
-
292
- const offenses = await check(theme, [ValidBlockTarget]);
293
- expect(offenses).to.have.length(2);
294
- expect(offenses).to.containOffense(
295
- 'Theme block type "invalid_preset_block" must be allowed in "blocks" at the root of this schema.',
296
- );
297
- expect(offenses).to.containOffense(
298
- "Theme block 'blocks/invalid_preset_block.liquid' does not exist.",
299
- );
300
- });
301
-
302
- if (path === 'sections') {
303
- it(`should report an error when a default defined block is not specified at root level`, async () => {
304
- const theme: MockTheme = {
305
- 'blocks/text.liquid': '',
306
- [`${path}/invalid-preset.liquid`]: `
307
- {% schema %}
308
- {
309
- "name": "Section name",
310
- "blocks": [
311
- {
312
- "type": "text"
313
- }
314
- ],
315
- "default": {
316
- "name": "Default",
317
- "blocks": [
318
- {
319
- "name": "invalid_preset_block",
320
- "type": "invalid_preset_block"
321
- }
322
- ]
323
- }
324
- }
325
- {% endschema %}
326
- `,
327
- };
328
-
329
- const offenses = await check(theme, [ValidBlockTarget]);
330
- expect(offenses).to.have.length(2);
331
- expect(offenses).to.containOffense(
332
- 'Theme block type "invalid_preset_block" must be allowed in "blocks" at the root of this schema.',
333
- );
334
- expect(offenses).to.containOffense(
335
- "Theme block 'blocks/invalid_preset_block.liquid' does not exist.",
336
- );
337
- });
338
- }
339
-
340
- it(`should report errors in presets for private blocks even when @theme is specified at root level (${path} bucket)`, async () => {
341
- const theme: MockTheme = {
342
- 'blocks/_private.liquid': '',
343
- [`${path}/private-blocks.liquid`]: `
344
- {% schema %}
345
- {
346
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
347
- "blocks": [
348
- {
349
- "type": "@theme"
350
- }
351
- ],
352
- "presets": [
353
- {
354
- "name": "Default",
355
- "blocks": [
356
- {
357
- "type": "_private"
358
- }
359
- ]
360
- }
361
- ]
362
- }
363
- {% endschema %}
364
- `,
365
- };
366
-
367
- const offenses = await check(theme, [ValidBlockTarget]);
368
- expect(offenses).to.have.length(1);
369
- expect(offenses).to.containOffense(
370
- 'Theme block type "_private" is a private block so it must be explicitly allowed in "blocks" at the root of this schema.',
371
- );
372
- });
373
-
374
- if (path === 'sections') {
375
- it(`should report errors in default for private blocks even when @theme is specified at root level`, async () => {
376
- const theme: MockTheme = {
377
- 'blocks/_private.liquid': '',
378
- [`${path}/private-blocks.liquid`]: `
379
- {% schema %}
380
- {
381
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
382
- "blocks": [
383
- {
384
- "type": "@theme"
385
- }
386
- ],
387
- "default": {
388
- "name": "Default",
389
- "blocks": [
390
- {
391
- "name": "private",
392
- "type": "_private"
393
- }
394
- ]
395
- }
396
- }
397
- {% endschema %}
398
- `,
399
- };
400
-
401
- const offenses = await check(theme, [ValidBlockTarget]);
402
- expect(offenses).to.have.length(1);
403
- expect(offenses).to.containOffense(
404
- 'Theme block type "_private" is a private block so it must be explicitly allowed in "blocks" at the root of this schema.',
405
- );
406
- });
407
- }
408
-
409
- it(`should report errors with correct indices (${path} bucket)`, async () => {
410
- const theme: MockTheme = {
411
- [`${path}/private-blocks.liquid`]: `
412
- {% schema %}
413
- {
414
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
415
- "blocks": [
416
- {
417
- "type": "@theme"
418
- }
419
- ],
420
- "presets": [
421
- {
422
- "name": "Default",
423
- "blocks": [
424
- {
425
- "type": "_private"
426
- }
427
- ]
428
- }
429
- ]
430
- }
431
- {% endschema %}
432
- `,
433
- };
434
-
435
- const offenses = await check(theme, [ValidBlockTarget]);
436
- expect(offenses).to.have.length(2);
437
-
438
- for (const offense of offenses) {
439
- const content = theme[`${path}/private-blocks.liquid`];
440
- const erroredContent = content.slice(offense.start.index, offense.end.index);
441
- expect(erroredContent).to.equal('"_private"');
442
- }
443
- });
444
-
445
- it(`should not report errors for private blocks when listed at root level (${path} bucket)`, async () => {
446
- const theme: MockTheme = {
447
- 'blocks/_private.liquid': '',
448
- [`${path}/private-blocks.liquid`]: `
449
- {% schema %}
450
- {
451
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
452
- "blocks": [
453
- {
454
- "type": "_private"
455
- }
456
- ],
457
- "presets": [
458
- {
459
- "name": "Default",
460
- "blocks": [
461
- {
462
- "type": "_private"
463
- }
464
- ]
465
- }
466
- ]
467
- }
468
- {% endschema %}
469
- `,
470
- };
471
-
472
- const offenses = await check(theme, [ValidBlockTarget]);
473
- expect(offenses).to.be.empty;
474
- });
475
-
476
- it(`should handle mixed private and public blocks correctly (${path} bucket)`, async () => {
477
- const theme: MockTheme = {
478
- 'blocks/_private.liquid': '',
479
- 'blocks/custom.liquid': '',
480
- [`${path}/mixed-blocks.liquid`]: `
481
- {% schema %}
482
- {
483
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
484
- "blocks": [
485
- {
486
- "type": "@theme"
487
- },
488
- {
489
- "type": "_private"
490
- }
491
- ],
492
- "presets": [
493
- {
494
- "name": "Default",
495
- "blocks": [
496
- {
497
- "type": "_private"
498
- },
499
- {
500
- "type": "custom"
501
- }
502
- ]
503
- }
504
- ]
505
- }
506
- {% endschema %}
507
- `,
508
- };
509
-
510
- const offenses = await check(theme, [ValidBlockTarget]);
511
- expect(offenses).to.be.empty;
512
- });
513
-
514
- it(`should report an error when a preset defined block is not specified at root level with hash-style presets (${path} bucket)`, async () => {
515
- const theme: MockTheme = {
516
- 'blocks/text.liquid': '',
517
- [`${path}/invalid-preset.liquid`]: `
518
- {% schema %}
519
- {
520
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
521
- "blocks": [
522
- {
523
- "type": "text"
524
- }
525
- ],
526
- "presets": [
527
- {
528
- "name": "Default preset",
529
- "blocks": {
530
- "invalid_preset_block_hash": {
531
- "type": "invalid_preset_block"
532
- }
533
- },
534
- "block_order": ["invalid_preset_block_hash"]
535
- }
536
- ]
537
- }
538
- {% endschema %}
539
- `,
540
- };
541
-
542
- const offenses = await check(theme, [ValidBlockTarget]);
543
- expect(offenses).to.have.length(2);
544
- expect(offenses).to.containOffense(
545
- 'Theme block type "invalid_preset_block" must be allowed in "blocks" at the root of this schema.',
546
- );
547
- expect(offenses).to.containOffense(
548
- "Theme block 'blocks/invalid_preset_block.liquid' does not exist.",
549
- );
550
- });
551
-
552
- it(`should report errors for private blocks even when @theme is specified at root level with hash-style presets (${path} bucket)`, async () => {
553
- const theme: MockTheme = {
554
- 'blocks/_private.liquid': '',
555
- [`${path}/private-blocks.liquid`]: `
556
- {% schema %}
557
- {
558
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
559
- "blocks": [
560
- {
561
- "type": "@theme"
562
- }
563
- ],
564
- "presets": [
565
- {
566
- "name": "Default",
567
- "blocks": {
568
- "private_hash": {
569
- "type": "_private"
570
- }
571
- },
572
- "block_order": ["private_hash"]
573
- }
574
- ]
575
- }
576
- {% endschema %}
577
- `,
578
- };
579
-
580
- const offenses = await check(theme, [ValidBlockTarget]);
581
- expect(offenses).to.have.length(1);
582
- expect(offenses[0].message).to.equal(
583
- 'Theme block type "_private" is a private block so it must be explicitly allowed in "blocks" at the root of this schema.',
584
- );
585
- });
586
-
587
- it(`should not report errors for private blocks when listed at root level with hash-style presets (${path} bucket)`, async () => {
588
- const theme: MockTheme = {
589
- 'blocks/_private.liquid': '',
590
- [`${path}/private-blocks.liquid`]: `
591
- {% schema %}
592
- {
593
- "name": "${path === 'sections' ? 'Section' : 'Block'} name",
594
- "blocks": [
595
- {
596
- "type": "_private"
597
- }
598
- ],
599
- "presets": [
600
- {
601
- "name": "Default",
602
- "blocks": {
603
- "private_hash": {
604
- "type": "_private"
605
- }
606
- },
607
- "block_order": ["private_hash"]
608
- }
609
- ]
610
- }
611
- {% endschema %}
612
- `,
613
- };
614
-
615
- const offenses = await check(theme, [ValidBlockTarget]);
616
- expect(offenses).to.be.empty;
617
- });
618
-
619
- it(`should report errors for nested blocks when they are not allowed (${path} bucket)`, async () => {
620
- const theme: MockTheme = {
621
- 'blocks/image.liquid': '',
622
- 'blocks/group.liquid': '',
623
- 'blocks/text.liquid': '',
624
- 'blocks/slide.liquid': `
625
- {% schema %}
626
- {
627
- "name": "Slide",
628
- "blocks": [
629
- {
630
- "type": "text"
631
- },
632
- {
633
- "type": "image"
634
- }
635
- ]
636
- }
637
- {% endschema %}
638
- `,
639
- [`${path}/slideshow.liquid`]: `
640
- {% schema %}
641
- {
642
- "name": "Slideshow",
643
- "blocks": [
644
- {
645
- "type": "slide"
646
- }
647
- ],
648
- "presets": [
649
- {
650
- "name": "Default",
651
- "blocks": [
652
- {
653
- "type": "slide",
654
- "blocks": [
655
- {
656
- "type": "group"
657
- }
658
- ]
659
- }
660
- ]
661
- }
662
- ]
663
- }
664
- {% endschema %}
665
- `,
666
- };
667
-
668
- const offenses = await check(theme, [ValidBlockTarget]);
669
- expect(offenses).to.have.length(1);
670
- expect(offenses[0].message).to.equal(
671
- 'Block type "group" is not allowed in "slide" blocks. Allowed types are: text, image.',
672
- );
673
- });
674
-
675
- it(`should report errors for nested private blocks when they are not allowed (${path} bucket)`, async () => {
676
- const theme: MockTheme = {
677
- 'blocks/image.liquid': '',
678
- 'blocks/_private.liquid': '',
679
- 'blocks/text.liquid': '',
680
- 'blocks/slide.liquid': `
681
- {% schema %}
682
- {
683
- "name": "Slide",
684
- "blocks": [
685
- {
686
- "type": "text"
687
- },
688
- {
689
- "type": "image"
690
- }
691
- ]
692
- }
693
- {% endschema %}
694
- `,
695
- [`${path}/slideshow.liquid`]: `
696
- {% schema %}
697
- {
698
- "name": "Slideshow",
699
- "blocks": [
700
- {
701
- "type": "slide"
702
- }
703
- ],
704
- "presets": [
705
- {
706
- "name": "Default",
707
- "blocks": [
708
- {
709
- "type": "slide",
710
- "blocks": [
711
- {
712
- "type": "_private"
713
- }
714
- ]
715
- }
716
- ]
717
- }
718
- ]
719
- }
720
- {% endschema %}
721
- `,
722
- };
723
-
724
- const offenses = await check(theme, [ValidBlockTarget]);
725
- expect(offenses).to.have.length(1);
726
- expect(offenses[0].message).to.equal(
727
- 'Private block type "_private" is not allowed in "slide" blocks.',
728
- );
729
- });
730
-
731
- it(`should report errors for nested blocks when they are not allowed with hash-style presets (${path} bucket)`, async () => {
732
- const theme: MockTheme = {
733
- 'blocks/image.liquid': '',
734
- 'blocks/group.liquid': '',
735
- 'blocks/text.liquid': '',
736
- 'blocks/slide.liquid': `
737
- {% schema %}
738
- {
739
- "name": "Slide",
740
- "blocks": [
741
- {
742
- "type": "text"
743
- },
744
- {
745
- "type": "image"
746
- }
747
- ]
748
- }
749
- {% endschema %}
750
- `,
751
- [`${path}/slideshow.liquid`]: `
752
- {% schema %}
753
- {
754
- "name": "Slideshow",
755
- "blocks": [
756
- {
757
- "type": "slide"
758
- }
759
- ],
760
- "presets": [
761
- {
762
- "name": "Default",
763
- "blocks": {
764
- "slide_hash": {
765
- "type": "slide",
766
- "blocks": {
767
- "group_hash": {
768
- "type": "group"
769
- }
770
- }
771
- }
772
- }
773
- }
774
- ]
775
- }
776
- {% endschema %}
777
- `,
778
- };
779
-
780
- const offenses = await check(theme, [ValidBlockTarget]);
781
- expect(offenses).to.have.length(1);
782
- expect(offenses[0].message).to.equal(
783
- 'Block type "group" is not allowed in "slide" blocks. Allowed types are: text, image.',
784
- );
785
- });
786
-
787
- it(`should report errors for further nested blocks when they are not allowed (${path} bucket)`, async () => {
788
- const theme: MockTheme = {
789
- 'blocks/image.liquid': '',
790
- 'blocks/group.liquid': `
791
- {% schema %}
792
- {
793
- "name": "Group",
794
- "blocks": [
795
- {
796
- "type": "text"
797
- }
798
- ]
799
- }
800
- {% endschema %}
801
- `,
802
- 'blocks/text.liquid': '',
803
- 'blocks/slide.liquid': `
804
- {% schema %}
805
- {
806
- "name": "Slide",
807
- "blocks": [
808
- {
809
- "type": "group"
810
- }
811
- ]
812
- }
813
- {% endschema %}
814
- `,
815
- [`${path}/slideshow.liquid`]: `
816
- {% schema %}
817
- {
818
- "name": "Slideshow",
819
- "blocks": [
820
- {
821
- "type": "slide"
822
- }
823
- ],
824
- "presets": [
825
- {
826
- "name": "Default",
827
- "blocks": [
828
- {
829
- "type": "slide",
830
- "blocks": [
831
- {
832
- "type": "group",
833
- "blocks": [
834
- {
835
- "type": "image"
836
- }
837
- ]
838
- }
839
- ]
840
- }
841
- ]
842
- }
843
- ]
844
- }
845
- {% endschema %}
846
- `,
847
- };
848
-
849
- const offenses = await check(theme, [ValidBlockTarget]);
850
- expect(offenses).to.have.length(1);
851
- expect(offenses[0].message).to.equal(
852
- 'Block type "image" is not allowed in "group" blocks. Allowed types are: text.',
853
- );
854
- });
855
-
856
- describe(`Static Blocks used in a ${path} file`, () => {
857
- const textSetting: Setting.Text = {
858
- type: 'text' as Setting.Type.Text,
859
- id: 'text',
860
- label: 'Text',
861
- };
862
-
863
- describe('When presets are defined as a hash', () => {
864
- describe('When the static block is used in the same file', () => {
865
- const makeTheme = (
866
- preset: Preset.PresetBlockHash,
867
- blocks_order: string[] = [],
868
- ): MockTheme => {
869
- return {
870
- [`${path}/slideshow.liquid`]: `
871
- # Static block is defined in the body of the file
872
- {% content_for "block", type: "static", id: "static_id" %}
873
-
874
- {% schema %}
875
- {
876
- "name": "Slideshow",
877
- "presets": [
878
- {
879
- "name": "Default",
880
- "blocks": ${JSON.stringify(preset, null, 2)},
881
- "block_order": ${JSON.stringify(blocks_order)}
882
- }
883
- ]
884
- }
885
- {% endschema %}
886
- `,
887
- 'blocks/static.liquid': `
888
- {% schema %}
889
- {
890
- "name": "some static block",
891
- "settings": [${JSON.stringify(textSetting)}]
892
- }
893
- {% endschema %}
894
- `,
895
- };
896
- };
897
-
898
- it(`is silent for valid static blocks references`, async () => {
899
- const theme: MockTheme = makeTheme({
900
- static_id: {
901
- type: 'static',
902
- static: true,
903
- settings: {
904
- text: 'some text',
905
- },
906
- },
907
- });
908
- const offenses = await check(theme, [ValidBlockTarget]);
909
- expect(offenses).to.be.empty;
910
- });
911
-
912
- it(`reports a warning for missing (or mismatching) static blocks references`, async () => {
913
- const theme: MockTheme = makeTheme({
914
- mismatching_id: {
915
- type: 'static',
916
- static: true,
917
- settings: {
918
- text: 'some text',
919
- },
920
- },
921
- });
922
-
923
- const offenses = await check(theme, [ValidBlockTarget]);
924
- expect(offenses).not.to.be.empty;
925
- expect(offenses).to.containOffense(
926
- 'Could not find a static block of type "static" with id "mismatching_id" in this file.',
927
- );
928
- });
929
- });
930
-
931
- describe('When the static block preset is defined in a nested block', () => {
932
- const makeTheme = (
933
- preset: Preset.PresetBlockHash,
934
- blocks_order: string[] = [],
935
- ): MockTheme => {
936
- return {
937
- [`${path}/slideshow-container.liquid`]: `
938
- # This file demonstrates how a static block can be used inside a nested block's preset
939
- {% content_for "blocks" %}
940
-
941
- {% schema %}
942
- {
943
- "name": "Slideshow container",
944
- "blocks": [{ "type": "slideshow" }],
945
- "presets": [{
946
- "name": "default",
947
- "block_order": ["slideshow1"],
948
- "blocks": {
949
- "slideshow1": {
950
- "type": "slideshow",
951
- "blocks": ${JSON.stringify(preset, null, 2)},
952
- "block_order": ${JSON.stringify(blocks_order)}
953
- }
954
- }
955
- }]
956
- }
957
- {% endschema %}
958
- `,
959
- [`blocks/slideshow.liquid`]: `
960
- # Static block is defined in the body of the file
961
- {% content_for "block", type: "static", id: "static_id" %}
962
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
963
-
964
- {% schema %}
965
- { "name": "Slideshow" }
966
- {% endschema %}
967
- `,
968
- 'blocks/static.liquid': `
969
- {% schema %}
970
- {
971
- "name": "some static block",
972
- "settings": [${JSON.stringify(textSetting)}]
973
- }
974
- {% endschema %}
975
- `,
976
- };
977
- };
978
-
979
- it('is silent for valid static blocks references', async () => {
980
- const theme = makeTheme({
981
- static_id: {
982
- type: 'static',
983
- static: true,
984
- },
985
- });
986
- const offenses = await check(theme, [ValidBlockTarget]);
987
- expect(offenses).to.be.empty;
988
- });
989
-
990
- it('reports warnings when using a mismatching (or nonexisting) static block', async () => {
991
- const theme = makeTheme({
992
- mismatching_id: {
993
- type: 'static',
994
- static: true,
995
- },
996
- });
997
- const offenses = await check(theme, [ValidBlockTarget]);
998
- expect(offenses).not.to.be.empty;
999
- expect(offenses).to.containOffense(
1000
- 'Could not find a static block of type "static" with id "mismatching_id" in "blocks/slideshow.liquid".',
1001
- );
1002
- });
1003
- });
1004
- });
1005
-
1006
- describe('When preset are defined as an array', () => {
1007
- describe('When the static block is used in the same file', () => {
1008
- const makeTheme = (preset: Preset.PresetBlockForArray[]): MockTheme => {
1009
- return {
1010
- 'blocks/static.liquid': `
1011
- {% schema %}
1012
- {
1013
- "name": "some static block",
1014
- "settings": [{ "label": "some setting", "type": "text", "id": "text" }],
1015
- }
1016
- {% endschema %}
1017
- `,
1018
- [`${path}/slideshow.liquid`]: `
1019
-
1020
- # Static block is defined in the body of the file
1021
- {% content_for "block", type: "static", id: "static_id" %}
1022
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1023
-
1024
- {% schema %}
1025
- {
1026
- "name": "Slideshow",
1027
- "presets": [
1028
- {
1029
- "name": "Default",
1030
- "blocks": ${JSON.stringify(preset, null, 2)}
1031
- }
1032
- ]
1033
- }
1034
- {% endschema %}
1035
- `,
1036
- };
1037
- };
1038
-
1039
- it(`is silent for valid static blocks references (${path} bucket)`, async () => {
1040
- const theme: MockTheme = makeTheme([
1041
- {
1042
- type: 'static',
1043
- id: 'static_id',
1044
- static: true,
1045
- settings: {
1046
- text: 'some text',
1047
- },
1048
- },
1049
- ]);
1050
- const offenses = await check(theme, [ValidBlockTarget]);
1051
- expect(offenses).to.be.empty;
1052
- });
1053
-
1054
- it(`reports a warning for missing (or mismatching) static blocks references (${path} bucket)`, async () => {
1055
- const theme: MockTheme = makeTheme([
1056
- {
1057
- type: 'static',
1058
- id: 'mismatching_id',
1059
- static: true,
1060
- settings: {
1061
- text: 'some text',
1062
- },
1063
- },
1064
- ]);
1065
-
1066
- const offenses = await check(theme, [ValidBlockTarget]);
1067
- expect(offenses).not.to.be.empty;
1068
- expect(offenses).to.containOffense(
1069
- 'Could not find a static block of type "static" with id "mismatching_id" in this file.',
1070
- );
1071
- });
1072
- });
1073
- });
1074
-
1075
- describe('When the static block preset is defined in a nested block', () => {
1076
- const makeTheme = (
1077
- preset: Preset.PresetBlockForArray[],
1078
- blocks_order: string[] = [],
1079
- ): MockTheme => {
1080
- return {
1081
- [`${path}/slideshow-container.liquid`]: `
1082
- # This file demonstrates how a static block can be used inside a nested block's preset
1083
- {% content_for "blocks" %}
1084
-
1085
- {% schema %}
1086
- {
1087
- "name": "Slideshow container",
1088
- "blocks": [{ "type": "slideshow" }],
1089
- "presets": [{
1090
- "name": "default",
1091
- "blocks": [
1092
- {
1093
- "type": "slideshow",
1094
- "id": "slideshow1",
1095
- "blocks": ${JSON.stringify(preset, null, 2)},
1096
- }
1097
- ]
1098
- }]
1099
- }
1100
- {% endschema %}
1101
- `,
1102
- [`blocks/slideshow.liquid`]: `
1103
- # Static block is defined in the body of the file
1104
- {% content_for "block", type: "static", id: "static_id" %}
1105
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1106
-
1107
- {% schema %}
1108
- { "name": "Slideshow" }
1109
- {% endschema %}
1110
- `,
1111
- 'blocks/static.liquid': `
1112
- {% schema %}
1113
- {
1114
- "name": "some static block",
1115
- "settings": [${JSON.stringify(textSetting)}]
1116
- }
1117
- {% endschema %}
1118
- `,
1119
- };
1120
- };
1121
-
1122
- it('is silent for valid static blocks references', async () => {
1123
- const theme = makeTheme([
1124
- {
1125
- id: 'static_id',
1126
- type: 'static',
1127
- static: true,
1128
- },
1129
- ]);
1130
- const offenses = await check(theme, [ValidBlockTarget]);
1131
- expect(offenses).to.be.empty;
1132
- });
1133
-
1134
- it('reports warnings when using a mismatching (or nonexisting) static block', async () => {
1135
- const theme = makeTheme([
1136
- {
1137
- id: 'mismatching_id',
1138
- type: 'static',
1139
- static: true,
1140
- },
1141
- ]);
1142
- const offenses = await check(theme, [ValidBlockTarget]);
1143
- expect(offenses).not.to.be.empty;
1144
- expect(offenses).to.containOffense(
1145
- 'Could not find a static block of type "static" with id "mismatching_id" in "blocks/slideshow.liquid".',
1146
- );
1147
- });
1148
- });
1149
- });
1150
-
1151
- it(`should report errors with correct indices for nested blocks when they are not allowed (${path} bucket)`, async () => {
1152
- const theme: MockTheme = {
1153
- 'blocks/image.liquid': '',
1154
- 'blocks/group.liquid': '',
1155
- 'blocks/text.liquid': '',
1156
- 'blocks/slide.liquid': `
1157
- {% schema %}
1158
- {
1159
- "name": "Slide",
1160
- "blocks": [
1161
- {
1162
- "type": "text"
1163
- },
1164
- {
1165
- "type": "image"
1166
- }
1167
- ]
1168
- }
1169
- {% endschema %}
1170
- `,
1171
- [`${path}/slideshow.liquid`]: `
1172
- {% schema %}
1173
- {
1174
- "name": "Slideshow",
1175
- "blocks": [
1176
- {
1177
- "type": "slide"
1178
- }
1179
- ],
1180
- "presets": [
1181
- {
1182
- "name": "Default",
1183
- "blocks": [
1184
- {
1185
- "type": "slide",
1186
- "blocks": [
1187
- {
1188
- "type": "group"
1189
- }
1190
- ]
1191
- }
1192
- ]
1193
- }
1194
- ]
1195
- }
1196
- {% endschema %}
1197
- `,
1198
- };
1199
-
1200
- const offenses = await check(theme, [ValidBlockTarget]);
1201
- expect(offenses).to.have.length(1);
1202
- const content = theme[`${path}/slideshow.liquid`];
1203
- const erroredContent = content.slice(offenses[0].start.index, offenses[0].end.index);
1204
- expect(erroredContent).to.equal('"group"');
1205
- });
1206
-
1207
- it(`should not report errors for nested blocks when they are allowed (${path} bucket)`, async () => {
1208
- const theme: MockTheme = {
1209
- 'blocks/image.liquid': '',
1210
- 'blocks/text.liquid': '',
1211
- 'blocks/slide.liquid': `
1212
- {% schema %}
1213
- {
1214
- "name": "Slide",
1215
- "blocks": [
1216
- {
1217
- "type": "text"
1218
- },
1219
- {
1220
- "type": "image"
1221
- }
1222
- ]
1223
- }
1224
- {% endschema %}
1225
- `,
1226
- [`${path}/slideshow.liquid`]: `
1227
- {% schema %}
1228
- {
1229
- "name": "Slideshow",
1230
- "blocks": [
1231
- {
1232
- "type": "slide"
1233
- }
1234
- ],
1235
- "presets": [
1236
- {
1237
- "name": "Default",
1238
- "blocks": [
1239
- {
1240
- "type": "slide",
1241
- "blocks": [
1242
- {
1243
- "type": "image"
1244
- }
1245
- ]
1246
- }
1247
- ]
1248
- }
1249
- ]
1250
- }
1251
- {% endschema %}
1252
- `,
1253
- };
1254
-
1255
- const offenses = await check(theme, [ValidBlockTarget]);
1256
- expect(offenses).to.be.empty;
1257
- });
1258
-
1259
- it(`should report errors on the correct file for nested blocks when they are not allowed (${path} bucket)`, async () => {
1260
- const theme: MockTheme = {
1261
- 'blocks/image.liquid': '',
1262
- 'blocks/group.liquid': '',
1263
- 'blocks/text.liquid': '',
1264
- 'blocks/slide.liquid': `
1265
- {% schema %}
1266
- {
1267
- "name": "Slide",
1268
- "blocks": [
1269
- {
1270
- "type": "text"
1271
- },
1272
- {
1273
- "type": "image"
1274
- }
1275
- ]
1276
- }
1277
- {% endschema %}
1278
- `,
1279
- [`${path}/slideshow.liquid`]: `
1280
- {% schema %}
1281
- {
1282
- "name": "Slideshow",
1283
- "blocks": [
1284
- {
1285
- "type": "slide"
1286
- }
1287
- ],
1288
- "presets": [
1289
- {
1290
- "name": "Default",
1291
- "blocks": [
1292
- {
1293
- "type": "slide",
1294
- "blocks": [
1295
- {
1296
- "type": "group"
1297
- }
1298
- ]
1299
- }
1300
- ]
1301
- }
1302
- ]
1303
- }
1304
- {% endschema %}
1305
- `,
1306
- };
1307
-
1308
- const offenses = await check(theme, [ValidBlockTarget]);
1309
- expect(offenses).to.have.lengthOf(1);
1310
- expect(offenses[0].uri).to.equal(`file:///${path}/slideshow.liquid`);
1311
- });
1312
-
1313
- it('should not crash or timeout with cyclical nested block relationships', async () => {
1314
- const theme: MockTheme = {
1315
- 'blocks/block-b.liquid': `
1316
- {% schema %}
1317
- {
1318
- "name": "Block B",
1319
- "blocks": [
1320
- {
1321
- "type": "block-c"
1322
- }
1323
- ]
1324
- }
1325
- {% endschema %}
1326
- `,
1327
- 'blocks/block-a.liquid': `
1328
- {% schema %}
1329
- {
1330
- "name": "Block A",
1331
- "blocks": [
1332
- {
1333
- "type": "block-b"
1334
- }
1335
- ],
1336
- "presets": [
1337
- {
1338
- "name": "Default",
1339
- "blocks": [
1340
- {
1341
- "type": "block-b",
1342
- "blocks": [
1343
- {
1344
- "type": "block-c"
1345
- }
1346
- ]
1347
- }
1348
- ]
1349
- }
1350
- ]
1351
- }
1352
- {% endschema %}
1353
- `,
1354
- 'blocks/block-c.liquid': `
1355
- {% schema %}
1356
- {
1357
- "name": "Block C",
1358
- "blocks": [
1359
- {
1360
- "type": "block-a"
1361
- }
1362
- ],
1363
- "presets": [
1364
- {
1365
- "name": "Default",
1366
- "blocks": [
1367
- {
1368
- "type": "block-a",
1369
- "blocks": [
1370
- {
1371
- "type": "block-b"
1372
- }
1373
- ]
1374
- }
1375
- ]
1376
- }
1377
- ]
1378
- }
1379
- {% endschema %}
1380
- `,
1381
- };
1382
-
1383
- const timeout = new Promise((_, reject) =>
1384
- setTimeout(() => reject(new Error('Test exceeded 500 ms')), 500),
1385
- );
1386
-
1387
- const testPromise = (async () => {
1388
- const offenses = await check(theme, [ValidBlockTarget]);
1389
- expect(offenses).to.be.empty;
1390
- })();
1391
-
1392
- await Promise.race([testPromise, timeout]);
1393
- });
1394
- });
1395
- });
1396
- });