@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,619 +0,0 @@
1
- import { expect, describe, it } from 'vitest';
2
- import { check } from '../../test';
3
- import { ValidVisibleIf, ValidVisibleIfSettingsSchema } from './index';
4
-
5
- type ThemeSchema = { [key: string]: unknown; settings?: Record<string, unknown>[] };
6
- type Theme = { [key: `${string}.json`]: ThemeSchema[]; [key: `${string}.liquid`]: ThemeSchema };
7
-
8
- const toLiquid = (schema: unknown) => `
9
- {% schema %}
10
- ${JSON.stringify(schema, undefined, 2)}
11
- {% endschema %}
12
- `;
13
-
14
- const makeTheme = (themeData: Record<string, unknown>) =>
15
- Object.fromEntries(
16
- Object.entries(themeData).map(([key, value]) => [
17
- key,
18
- key.endsWith('.json') ? JSON.stringify(value, undefined, 2) : toLiquid(value),
19
- ]),
20
- );
21
-
22
- const checkRule = (themeData: Theme) =>
23
- check(makeTheme(themeData), [ValidVisibleIf, ValidVisibleIfSettingsSchema]);
24
-
25
- const baseThemeData: Theme = {
26
- 'sections/example.liquid': {
27
- name: 'My Section',
28
- settings: [{ id: 'some-section-setting' }],
29
- },
30
- 'blocks/example.liquid': {
31
- name: 'My Block',
32
- settings: [{ id: 'some-block-setting' }],
33
- },
34
- 'config/settings_schema.json': [
35
- {
36
- name: 'theme_info',
37
- theme_name: 'Test Theme',
38
- theme_version: '0.1.0',
39
- theme_author: 'Shopify',
40
- },
41
- {
42
- name: 't:some.namespace',
43
- settings: [
44
- { type: 'header', content: 't:some.other.namespace' },
45
- { id: 'some-global-setting' },
46
- ],
47
- },
48
- ],
49
- };
50
-
51
- describe('Module: ValidVisibleIf', () => {
52
- it('reports no error for a valid reference to a block schema setting (simple lookup)', async () => {
53
- const themeData = structuredClone(baseThemeData);
54
-
55
- themeData['blocks/example.liquid'].settings!.push({
56
- id: 'some-other-setting',
57
- visible_if: '{{ block.settings.some-block-setting }}',
58
- });
59
-
60
- const offenses = await checkRule(themeData);
61
- expect(offenses).toEqual([]);
62
- });
63
-
64
- it('reports no error for a valid reference to a block schema setting (expression)', async () => {
65
- const themeData = structuredClone(baseThemeData);
66
-
67
- themeData['blocks/example.liquid'].settings!.push({
68
- id: 'some-other-setting',
69
- visible_if: '{{ block.settings.some-block-setting != "null" }}',
70
- });
71
-
72
- const offenses = await checkRule(themeData);
73
- expect(offenses).toEqual([]);
74
- });
75
-
76
- it('reports no error for a valid reference to a global setting (simple lookup)', async () => {
77
- const themeData = structuredClone(baseThemeData);
78
-
79
- themeData['blocks/example.liquid'].settings!.push({
80
- id: 'some-other-setting',
81
- visible_if: '{{ settings.some-global-setting }}',
82
- });
83
-
84
- const offenses = await checkRule(themeData);
85
- expect(offenses).toEqual([]);
86
- });
87
-
88
- it('reports no error for a valid reference to a global setting (expression)', async () => {
89
- const themeData = structuredClone(baseThemeData);
90
-
91
- themeData['blocks/example.liquid'].settings!.push({
92
- id: 'some-other-setting',
93
- visible_if: '{{ "null" != settings.some-global-setting }}',
94
- });
95
-
96
- const offenses = await checkRule(themeData);
97
- expect(offenses).toEqual([]);
98
- });
99
-
100
- it('reports no error for a valid reference to a section schema (simple lookup)', async () => {
101
- const themeData = structuredClone(baseThemeData);
102
-
103
- themeData['sections/example.liquid'].settings!.push({
104
- id: 'some-other-setting',
105
- visible_if: '{{ section.settings.some-section-setting }}',
106
- });
107
-
108
- const offenses = await checkRule(themeData);
109
- expect(offenses).toEqual([]);
110
- });
111
-
112
- it('reports no error for a valid reference to a section schema (simple lookup) in a block schema', async () => {
113
- const themeData = structuredClone(baseThemeData);
114
-
115
- themeData['sections/example.liquid'].settings!.push({
116
- id: 'some-other-setting',
117
- });
118
-
119
- themeData['blocks/example.liquid'].settings!.push({
120
- visible_if: '{{ section.settings.some-section-setting }}',
121
- });
122
-
123
- const offenses = await checkRule(themeData);
124
- expect(offenses).toEqual([]);
125
- });
126
-
127
- it('reports no error for a valid reference to a section schema (expression)', async () => {
128
- const themeData = structuredClone(baseThemeData);
129
-
130
- themeData['sections/example.liquid'].settings!.push({
131
- id: 'some-other-setting',
132
- visible_if: '{{ section.settings.some-section-setting != "null" }}',
133
- });
134
-
135
- const offenses = await checkRule(themeData);
136
- expect(offenses).toEqual([]);
137
- });
138
-
139
- it('reports no error for a valid reference to a global setting (in theme settings)', async () => {
140
- const themeData = structuredClone(baseThemeData);
141
-
142
- themeData['config/settings_schema.json'].at(-1)!.settings!.push({
143
- id: 'some-other-setting',
144
- visible_if: '{{ settings.some-global-setting }}',
145
- });
146
-
147
- const offenses = await checkRule(themeData);
148
- expect(offenses).toEqual([]);
149
- });
150
-
151
- it('reports an error for an invalid reference to a global variable (in block)', async () => {
152
- const themeData = structuredClone(baseThemeData);
153
-
154
- themeData['blocks/example.liquid'].settings!.push({
155
- id: 'some-other-setting',
156
- visible_if: '{{ some-nonexistent-whatever }}',
157
- });
158
-
159
- const offenses = await checkRule(themeData);
160
- expect(offenses).toMatchInlineSnapshot(`
161
- [
162
- {
163
- "check": "ValidVisibleIf",
164
- "end": {
165
- "character": 49,
166
- "index": 195,
167
- "line": 10,
168
- },
169
- "fix": undefined,
170
- "message": "Invalid variable: "some-nonexistent-whatever" was not found.",
171
- "severity": 0,
172
- "start": {
173
- "character": 24,
174
- "index": 170,
175
- "line": 10,
176
- },
177
- "suggest": undefined,
178
- "type": "LiquidHtml",
179
- "uri": "file:///blocks/example.liquid",
180
- },
181
- ]
182
- `);
183
- });
184
-
185
- it('reports an error for an invalid reference to a block schema setting (simple lookup)', async () => {
186
- const themeData = structuredClone(baseThemeData);
187
-
188
- themeData['blocks/example.liquid'].settings!.push({
189
- id: 'some-other-setting',
190
- visible_if: '{{ block.settings.some-nonexistent-block-setting }}',
191
- });
192
-
193
- const offenses = await checkRule(themeData);
194
- expect(offenses).toMatchInlineSnapshot(`
195
- [
196
- {
197
- "check": "ValidVisibleIf",
198
- "end": {
199
- "character": 69,
200
- "index": 215,
201
- "line": 10,
202
- },
203
- "fix": undefined,
204
- "message": "Invalid variable: "block.settings.some-nonexistent-block-setting" was not found.",
205
- "severity": 0,
206
- "start": {
207
- "character": 24,
208
- "index": 170,
209
- "line": 10,
210
- },
211
- "suggest": undefined,
212
- "type": "LiquidHtml",
213
- "uri": "file:///blocks/example.liquid",
214
- },
215
- ]
216
- `);
217
- });
218
-
219
- it('reports an error for an invalid reference to a block schema setting (expression)', async () => {
220
- const themeData = structuredClone(baseThemeData);
221
-
222
- themeData['blocks/example.liquid'].settings!.push({
223
- id: 'some-other-setting',
224
- visible_if: '{{ block.settings.some-nonexistent-block-setting != "null" }}',
225
- });
226
-
227
- const offenses = await checkRule(themeData);
228
- expect(offenses).toMatchInlineSnapshot(`
229
- [
230
- {
231
- "check": "ValidVisibleIf",
232
- "end": {
233
- "character": 69,
234
- "index": 215,
235
- "line": 10,
236
- },
237
- "fix": undefined,
238
- "message": "Invalid variable: "block.settings.some-nonexistent-block-setting" was not found.",
239
- "severity": 0,
240
- "start": {
241
- "character": 24,
242
- "index": 170,
243
- "line": 10,
244
- },
245
- "suggest": undefined,
246
- "type": "LiquidHtml",
247
- "uri": "file:///blocks/example.liquid",
248
- },
249
- ]
250
- `);
251
- });
252
-
253
- it('reports an error for an invalid reference to a section schema (simple lookup)', async () => {
254
- const themeData = structuredClone(baseThemeData);
255
-
256
- themeData['sections/example.liquid'].settings!.push({
257
- id: 'some-other-setting',
258
- visible_if: '{{ section.settings.some-nonexistent-section-setting }}',
259
- });
260
-
261
- const offenses = await checkRule(themeData);
262
- expect(offenses).toMatchInlineSnapshot(`
263
- [
264
- {
265
- "check": "ValidVisibleIf",
266
- "end": {
267
- "character": 73,
268
- "index": 223,
269
- "line": 10,
270
- },
271
- "fix": undefined,
272
- "message": "Invalid variable: "section.settings.some-nonexistent-section-setting" was not found.",
273
- "severity": 0,
274
- "start": {
275
- "character": 24,
276
- "index": 174,
277
- "line": 10,
278
- },
279
- "suggest": undefined,
280
- "type": "LiquidHtml",
281
- "uri": "file:///sections/example.liquid",
282
- },
283
- ]
284
- `);
285
- });
286
-
287
- it('reports an error for an invalid reference to a section schema (expression)', async () => {
288
- const themeData = structuredClone(baseThemeData);
289
-
290
- themeData['sections/example.liquid'].settings!.push({
291
- id: 'some-other-setting',
292
- visible_if: '{{ section.settings.some-nonexistent-section-setting != "null" }}',
293
- });
294
-
295
- const offenses = await checkRule(themeData);
296
- expect(offenses).toMatchInlineSnapshot(`
297
- [
298
- {
299
- "check": "ValidVisibleIf",
300
- "end": {
301
- "character": 73,
302
- "index": 223,
303
- "line": 10,
304
- },
305
- "fix": undefined,
306
- "message": "Invalid variable: "section.settings.some-nonexistent-section-setting" was not found.",
307
- "severity": 0,
308
- "start": {
309
- "character": 24,
310
- "index": 174,
311
- "line": 10,
312
- },
313
- "suggest": undefined,
314
- "type": "LiquidHtml",
315
- "uri": "file:///sections/example.liquid",
316
- },
317
- ]
318
- `);
319
- });
320
-
321
- it('reports an error for an invalid reference to a global setting (in theme settings)', async () => {
322
- const themeData = structuredClone(baseThemeData);
323
-
324
- themeData['config/settings_schema.json'].at(-1)!.settings!.push({
325
- id: 'some-other-setting',
326
- visible_if: '{{ settings.some-non-existent-setting }}',
327
- });
328
-
329
- const offenses = await checkRule(themeData);
330
- expect(offenses).toMatchInlineSnapshot(`
331
- [
332
- {
333
- "check": "ValidVisibleIf",
334
- "end": {
335
- "character": 60,
336
- "index": 427,
337
- "line": 19,
338
- },
339
- "fix": undefined,
340
- "message": "Invalid variable: "settings.some-non-existent-setting" was not found.",
341
- "severity": 0,
342
- "start": {
343
- "character": 26,
344
- "index": 393,
345
- "line": 19,
346
- },
347
- "suggest": undefined,
348
- "type": "JSON",
349
- "uri": "file:///config/settings_schema.json",
350
- },
351
- ]
352
- `);
353
- });
354
-
355
- it('reports a detailed error when trying to use a block var in a section', async () => {
356
- const themeData = structuredClone(baseThemeData);
357
-
358
- themeData['sections/example.liquid'].settings!.push({
359
- id: 'some-other-setting',
360
- visible_if: '{{ block.settings.some-section-setting != "null" }}',
361
- });
362
-
363
- const offenses = await checkRule(themeData);
364
- expect(offenses).toMatchInlineSnapshot(`
365
- [
366
- {
367
- "check": "ValidVisibleIf",
368
- "end": {
369
- "character": 59,
370
- "index": 209,
371
- "line": 10,
372
- },
373
- "fix": undefined,
374
- "message": "Invalid visible_if: can't refer to "block" when not in a block file.",
375
- "severity": 0,
376
- "start": {
377
- "character": 24,
378
- "index": 174,
379
- "line": 10,
380
- },
381
- "suggest": undefined,
382
- "type": "LiquidHtml",
383
- "uri": "file:///sections/example.liquid",
384
- },
385
- ]
386
- `);
387
- });
388
-
389
- it('reports a detailed error when trying to use a block var in theme settings', async () => {
390
- const themeData = structuredClone(baseThemeData);
391
-
392
- themeData['config/settings_schema.json'].at(-1)!.settings!.push({
393
- id: 'some-other-setting',
394
- visible_if: '{{ block.settings.some-block-setting }}',
395
- });
396
-
397
- const offenses = await checkRule(themeData);
398
- expect(offenses).toMatchInlineSnapshot(`
399
- [
400
- {
401
- "check": "ValidVisibleIf",
402
- "end": {
403
- "character": 59,
404
- "index": 426,
405
- "line": 19,
406
- },
407
- "fix": undefined,
408
- "message": "Invalid visible_if: can't refer to "block" when not in a block file.",
409
- "severity": 0,
410
- "start": {
411
- "character": 26,
412
- "index": 393,
413
- "line": 19,
414
- },
415
- "suggest": undefined,
416
- "type": "JSON",
417
- "uri": "file:///config/settings_schema.json",
418
- },
419
- ]
420
- `);
421
- });
422
-
423
- it('reports a detailed error when attempting to use a namespace as a var', async () => {
424
- const themeData = structuredClone(baseThemeData);
425
-
426
- themeData['blocks/example.liquid'].settings!.push({
427
- id: 'some-other-setting',
428
- visible_if: '{{ block.settings }}',
429
- });
430
-
431
- const offenses = await checkRule(themeData);
432
- expect(offenses).toMatchInlineSnapshot(`
433
- [
434
- {
435
- "check": "ValidVisibleIf",
436
- "end": {
437
- "character": 38,
438
- "index": 184,
439
- "line": 10,
440
- },
441
- "fix": undefined,
442
- "message": "Invalid variable: "block.settings" refers to a namespace, but is being used here as a variable.",
443
- "severity": 0,
444
- "start": {
445
- "character": 24,
446
- "index": 170,
447
- "line": 10,
448
- },
449
- "suggest": undefined,
450
- "type": "LiquidHtml",
451
- "uri": "file:///blocks/example.liquid",
452
- },
453
- ]
454
- `);
455
- });
456
-
457
- it('reports a detailed error when attempting to use a var as a namespace', async () => {
458
- const themeData = structuredClone(baseThemeData);
459
-
460
- themeData['blocks/example.liquid'].settings!.push({
461
- id: 'some-other-setting',
462
- visible_if: '{{ block.settings.some-block-setting.another-thing }}',
463
- });
464
-
465
- const offenses = await checkRule(themeData);
466
- expect(offenses).toMatchInlineSnapshot(`
467
- [
468
- {
469
- "check": "ValidVisibleIf",
470
- "end": {
471
- "character": 71,
472
- "index": 217,
473
- "line": 10,
474
- },
475
- "fix": undefined,
476
- "message": "Invalid variable: "block.settings.some-block-setting" refers to a variable, but is being used here as a namespace.",
477
- "severity": 0,
478
- "start": {
479
- "character": 24,
480
- "index": 170,
481
- "line": 10,
482
- },
483
- "suggest": undefined,
484
- "type": "LiquidHtml",
485
- "uri": "file:///blocks/example.liquid",
486
- },
487
- ]
488
- `);
489
- });
490
-
491
- it('reports visible_if fields declared with incorrect or missing brackets', async () => {
492
- const themeData = structuredClone(baseThemeData);
493
-
494
- themeData['sections/example.liquid'].settings!.push({
495
- id: 'some-other-setting',
496
- visible_if: '{% section.settings.some-section-setting != "null" %}',
497
- });
498
-
499
- const offenses = await checkRule(themeData);
500
- expect(offenses).toMatchInlineSnapshot(`
501
- [
502
- {
503
- "check": "ValidVisibleIf",
504
- "end": {
505
- "character": 77,
506
- "index": 227,
507
- "line": 10,
508
- },
509
- "fix": undefined,
510
- "message": "Invalid visible_if expression. It should take the form "{{ <expression> }}".",
511
- "severity": 0,
512
- "start": {
513
- "character": 20,
514
- "index": 170,
515
- "line": 10,
516
- },
517
- "suggest": undefined,
518
- "type": "LiquidHtml",
519
- "uri": "file:///sections/example.liquid",
520
- },
521
- ]
522
- `);
523
- });
524
-
525
- it('reports malformed visible_if fields', async () => {
526
- const themeData = structuredClone(baseThemeData);
527
-
528
- themeData['sections/example.liquid'].settings!.push({
529
- id: 'some-other-setting',
530
- visible_if: '{{ section.settings.some-section-setting !r=erf "null" }}',
531
- });
532
-
533
- const offenses = await checkRule(themeData);
534
- expect(offenses).toMatchInlineSnapshot(`
535
- [
536
- {
537
- "check": "ValidVisibleIf",
538
- "end": {
539
- "character": 81,
540
- "index": 231,
541
- "line": 10,
542
- },
543
- "fix": undefined,
544
- "message": "Syntax error: cannot parse visible_if expression.",
545
- "severity": 0,
546
- "start": {
547
- "character": 20,
548
- "index": 170,
549
- "line": 10,
550
- },
551
- "suggest": undefined,
552
- "type": "LiquidHtml",
553
- "uri": "file:///sections/example.liquid",
554
- },
555
- ]
556
- `);
557
- });
558
-
559
- it('does not reports when true or false is hardcoded', async () => {
560
- for (const bool of ['true', 'false']) {
561
- const themeData = structuredClone(baseThemeData);
562
-
563
- themeData['sections/example.liquid'].settings!.push({
564
- id: 'some-other-setting',
565
- visible_if: `{{ ${bool} }}`,
566
- });
567
-
568
- const offenses = await checkRule(themeData);
569
- expect(offenses).to.be.empty;
570
- }
571
- });
572
-
573
- it('reports a warning for unparseable expressions', async () => {
574
- const themeData = structuredClone(baseThemeData);
575
-
576
- themeData['sections/example.liquid'].settings!.push({
577
- id: 'some-other-setting',
578
- visible_if: `{{ something $ unparseable }}`,
579
- });
580
-
581
- const offenses = await checkRule(themeData);
582
- expect(offenses).to.be.lengthOf(1);
583
- expect(offenses).to.containOffense('Syntax error: cannot parse visible_if expression.');
584
- });
585
-
586
- it('reports when no variable lookup is found', async () => {
587
- const themeData = structuredClone(baseThemeData);
588
-
589
- themeData['sections/example.liquid'].settings!.push({
590
- id: 'some-other-setting',
591
- visible_if: '{{ "some random string" }}',
592
- });
593
-
594
- const offenses = await checkRule(themeData);
595
- expect(offenses).toMatchInlineSnapshot(`
596
- [
597
- {
598
- "check": "ValidVisibleIf",
599
- "end": {
600
- "character": 50,
601
- "index": 200,
602
- "line": 10,
603
- },
604
- "fix": undefined,
605
- "message": "visible_if expression contains no references to any settings. This is likely an error.",
606
- "severity": 0,
607
- "start": {
608
- "character": 20,
609
- "index": 170,
610
- "line": 10,
611
- },
612
- "suggest": undefined,
613
- "type": "LiquidHtml",
614
- "uri": "file:///sections/example.liquid",
615
- },
616
- ]
617
- `);
618
- });
619
- });