@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,7 +1,7 @@
1
1
  import {
2
- JSONCheckDefinition,
2
+ YAMLCheckDefinition,
3
3
  JSONNode,
4
- JSONSourceCode,
4
+ YAMLSourceCode,
5
5
  Severity,
6
6
  SourceCodeType,
7
7
  PropertyNode,
@@ -9,16 +9,16 @@ import {
9
9
 
10
10
  const PLURALIZATION_KEYS = new Set(['zero', 'one', 'two', 'few', 'many', 'other']);
11
11
 
12
- export const MatchingTranslations: JSONCheckDefinition = {
12
+ export const MatchingTranslations: YAMLCheckDefinition = {
13
13
  meta: {
14
14
  code: 'MatchingTranslations',
15
15
  name: 'Translation files should have the same keys',
16
16
  docs: {
17
17
  description: 'TODO',
18
18
  recommended: true,
19
- url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/matching-translations',
19
+ url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/matching-translations',
20
20
  },
21
- type: SourceCodeType.JSON,
21
+ type: SourceCodeType.YAML,
22
22
  severity: Severity.ERROR,
23
23
  schema: {},
24
24
  targets: [],
@@ -29,18 +29,17 @@ export const MatchingTranslations: JSONCheckDefinition = {
29
29
  const defaultTranslations = new Set<string>();
30
30
  const missingTranslations = new Set<string>();
31
31
  const nodesByPath = new Map<string, PropertyNode>();
32
- const file = context.file;
32
+ const file = context.file as YAMLSourceCode;
33
33
  const fileUri = file.uri;
34
34
  const relativePath = context.toRelativePath(fileUri);
35
35
  const ast = file.ast;
36
- const isLocaleFile = relativePath.startsWith('locales/');
37
- const isDefaultTranslationsFile =
38
- fileUri.endsWith('.default.json') || fileUri.endsWith('.default.schema.json');
39
- const isSchemaTranslationFile = fileUri.endsWith('.schema.json');
40
-
41
- if (!isLocaleFile || isDefaultTranslationsFile || ast instanceof Error) {
42
- // No need to lint a file that isn't a translation file, we return an
43
- // empty object as the check for those.
36
+ const isTranslationFile = relativePath.includes('/translations/');
37
+ // In platformOS, en.yml is the reference locale; skip running the check on it
38
+ const basename = fileUri.split('/').pop() ?? '';
39
+ const isDefaultTranslationsFile = basename.replace(/\.ya?ml$/, '') === 'en';
40
+
41
+ if (!isTranslationFile || isDefaultTranslationsFile || ast instanceof Error) {
42
+ // No need to lint a file that isn't a non-default translation file
44
43
  return {};
45
44
  }
46
45
 
@@ -48,7 +47,6 @@ export const MatchingTranslations: JSONCheckDefinition = {
48
47
  const hasDefaultTranslations = () => defaultTranslations.size > 0;
49
48
  const isTerminalNode = ({ type }: JSONNode) => type === 'Literal';
50
49
  const isPluralizationNode = (node: PropertyNode) => PLURALIZATION_KEYS.has(node.key.value);
51
- const isShopifyPath = (path: string) => path.startsWith('shopify.');
52
50
 
53
51
  const hasDefaultTranslation = (translationPath: string) =>
54
52
  defaultTranslations.has(translationPath) ?? false;
@@ -71,10 +69,15 @@ export const MatchingTranslations: JSONCheckDefinition = {
71
69
  }, []);
72
70
  };
73
71
 
72
+ // Strip the locale prefix (first Property in the ancestors chain).
73
+ // YAML files wrap content under a locale key: { en: { hello: 'Hello' } }
74
+ // We want paths like 'hello', not 'en.hello'.
74
75
  const objectPath = (nodes: JSONNode[]) => {
75
- return nodes
76
- .filter((node): node is PropertyNode => node.type === 'Property')
77
- .reduce((acc: string[], val) => acc.concat(val.key.value), [])
76
+ const props = nodes.filter((n): n is PropertyNode => n.type === 'Property');
77
+ if (props.length <= 1) return ''; // locale key itself, or empty
78
+ return props
79
+ .slice(1)
80
+ .map((p) => p.key.value)
78
81
  .join('.');
79
82
  };
80
83
 
@@ -110,10 +113,7 @@ export const MatchingTranslations: JSONCheckDefinition = {
110
113
 
111
114
  return {
112
115
  async onCodePathStart() {
113
- const getDefaultTranslations = isSchemaTranslationFile
114
- ? context.getDefaultSchemaTranslations
115
- : context.getDefaultTranslations;
116
- const defaultTranslationPaths = await getDefaultTranslations().then(jsonPaths);
116
+ const defaultTranslationPaths = await context.getDefaultTranslations().then(jsonPaths);
117
117
  defaultTranslationPaths.forEach(Set.prototype.add, defaultTranslations);
118
118
 
119
119
  // At the `onCodePathStart`, we assume that all translations are missing,
@@ -124,12 +124,13 @@ export const MatchingTranslations: JSONCheckDefinition = {
124
124
  async Property(node, ancestors) {
125
125
  const path = objectPath(ancestors.concat(node));
126
126
 
127
+ if (!path) return; // skip the root locale key (e.g. 'pt-BR')
128
+
127
129
  nodesByPath.set(path, node);
128
130
 
129
131
  if (!hasDefaultTranslations()) return;
130
132
  if (isPluralizationNode(node)) return;
131
133
  if (!isTerminalNode(node.value)) return;
132
- if (isShopifyPath(path)) return;
133
134
 
134
135
  if (hasDefaultTranslation(path)) {
135
136
  // As `path` is present, we remove it from the
@@ -142,14 +143,6 @@ export const MatchingTranslations: JSONCheckDefinition = {
142
143
  message: `A default translation for '${path}' does not exist`,
143
144
  startIndex: node.loc!.start.offset,
144
145
  endIndex: node.loc!.end.offset,
145
- suggest: [
146
- {
147
- message: 'Delete unneeded translation key',
148
- fix(corrector) {
149
- corrector.remove(path);
150
- },
151
- },
152
- ],
153
146
  });
154
147
  },
155
148
 
@@ -158,15 +151,11 @@ export const MatchingTranslations: JSONCheckDefinition = {
158
151
  const closest = closestTranslationKey(path);
159
152
 
160
153
  if (isPluralizationPath(path)) return;
161
- if (isShopifyPath(path)) return;
162
154
 
163
155
  context.report({
164
156
  message: `The translation for '${path}' is missing`,
165
157
  startIndex: closest.loc!.start.offset,
166
158
  endIndex: closest.loc!.end.offset,
167
- fix(corrector) {
168
- corrector.add(path, 'TODO');
169
- },
170
159
  });
171
160
  });
172
161
  },
@@ -3,7 +3,6 @@ import yaml from 'js-yaml';
3
3
  import { DocumentsLocator, DocumentType } from '@platformos/platformos-common';
4
4
  import { URI } from 'vscode-uri';
5
5
  import { LiquidNamedArgument, Position } from '@platformos/liquid-html-parser';
6
- import { getLiquidDocParams } from '../../liquid-doc/arguments';
7
6
  import { relative } from '../../path';
8
7
 
9
8
  type Metadata = {
@@ -64,12 +63,11 @@ export const MetadataParamsCheck: LiquidCheckDefinition = {
64
63
  }
65
64
  let params = extractMetadataParams(await context.fs.readFile(locatedFile));
66
65
  if (!params) {
67
- const liquidDocParameters = await getLiquidDocParams(
68
- context,
69
- relative(locatedFile, context.config.rootUri),
70
- );
71
-
72
- if (!liquidDocParameters) return;
66
+ if (!context.getDocDefinition) return;
67
+ const relativePath = relative(locatedFile, context.config.rootUri);
68
+ const docDef = await context.getDocDefinition(relativePath);
69
+ if (!docDef?.liquidDoc?.parameters) return;
70
+ const liquidDocParameters = new Map(docDef.liquidDoc.parameters.map((p) => [p.name, p]));
73
71
 
74
72
  params = Array.from(liquidDocParameters.values())
75
73
  .filter((p) => p.required)
@@ -11,7 +11,7 @@ export const MissingAsset: LiquidCheckDefinition = {
11
11
  docs: {
12
12
  description: 'Reports missing asset files',
13
13
  recommended: true,
14
- url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/missing-asset',
14
+ url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/missing-asset',
15
15
  },
16
16
  type: SourceCodeType.LiquidHtml,
17
17
  severity: Severity.ERROR,
@@ -1,9 +1,9 @@
1
1
  import { expect, describe, it } from 'vitest';
2
- import { MissingTemplate } from '.';
2
+ import { MissingPartial } from '.';
3
3
  import { check } from '../../test';
4
4
 
5
- describe('Module: MissingTemplate', () => {
6
- it('should report missing template errors', async () => {
5
+ describe('Module: MissingPartial', () => {
6
+ it('should report missing partial errors', async () => {
7
7
  const testCases = [
8
8
  {
9
9
  testCase: 'should report the missing partial to be rendered with "render"',
@@ -12,7 +12,7 @@ describe('Module: MissingTemplate', () => {
12
12
  {% render myvariable %}
13
13
  `,
14
14
  expected: {
15
- check: 'MissingTemplate',
15
+ check: 'MissingPartial',
16
16
  end: {
17
17
  character: 27,
18
18
  index: 28,
@@ -49,11 +49,11 @@ describe('Module: MissingTemplate', () => {
49
49
  },
50
50
  ];
51
51
  for (const { testCase, file, expected, filesWith } of testCases) {
52
- const offenses = await check(filesWith(file), [MissingTemplate]);
52
+ const offenses = await check(filesWith(file), [MissingPartial]);
53
53
 
54
54
  expect(offenses).to.have.length(1);
55
55
  expect(offenses, testCase).to.containOffense({
56
- check: MissingTemplate.meta.code,
56
+ check: MissingPartial.meta.code,
57
57
  ...expected,
58
58
  });
59
59
  }
@@ -1,19 +1,5 @@
1
- import {
2
- LiquidTag,
3
- LiquidTagNamed,
4
- NamedTags,
5
- NodeTypes,
6
- Position,
7
- } from '@platformos/liquid-html-parser';
8
- import { minimatch } from 'minimatch';
9
- import {
10
- LiquidCheckDefinition,
11
- RelativePath,
12
- SchemaProp,
13
- Severity,
14
- SourceCodeType,
15
- } from '../../types';
16
- import { doesFileExist } from '../../utils/file-utils';
1
+ import { NodeTypes } from '@platformos/liquid-html-parser';
2
+ import { LiquidCheckDefinition, SchemaProp, Severity, SourceCodeType } from '../../types';
17
3
  import { DocumentsLocator } from '@platformos/platformos-common';
18
4
  import { URI } from 'vscode-uri';
19
5
 
@@ -21,14 +7,14 @@ const schema = {
21
7
  ignoreMissing: SchemaProp.array(SchemaProp.string(), []),
22
8
  };
23
9
 
24
- export const MissingTemplate: LiquidCheckDefinition<typeof schema> = {
10
+ export const MissingPartial: LiquidCheckDefinition<typeof schema> = {
25
11
  meta: {
26
- code: 'MissingTemplate',
27
- name: 'Avoid rendering missing templates',
12
+ code: 'MissingPartial',
13
+ name: 'Avoid rendering missing partials',
28
14
  docs: {
29
15
  description: 'Reports missing partial liquid file',
30
16
  recommended: true,
31
- url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/missing-template',
17
+ url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/missing-partial',
32
18
  },
33
19
  type: SourceCodeType.LiquidHtml,
34
20
  severity: Severity.ERROR,
@@ -1,4 +1,4 @@
1
- import { isPartial } from '../../to-schema';
1
+ import { isPartial } from '../../path';
2
2
  import { LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';
3
3
 
4
4
  export const OrphanedPartial: LiquidCheckDefinition = {
@@ -6,9 +6,9 @@ export const OrphanedPartial: LiquidCheckDefinition = {
6
6
  code: 'OrphanedPartial',
7
7
  name: 'Prevent orphaned partials',
8
8
  docs: {
9
- description: 'This check exists to prevent orphaned partials in themes.',
9
+ description: 'This check exists to prevent orphaned partials in platformOS apps.',
10
10
  recommended: true,
11
- url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/orphaned-partial',
11
+ url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/orphaned-partial',
12
12
  },
13
13
  type: SourceCodeType.LiquidHtml,
14
14
  severity: Severity.WARNING,
@@ -3,26 +3,6 @@ import { ParserBlockingScript } from '.';
3
3
  import { applySuggestions, check as reportOffenses } from '../../test';
4
4
 
5
5
  describe('Module: ParserBlockingScript', () => {
6
- it('should report the correct offense for the Liquid filter', async () => {
7
- const file = "{{ 'asset' | script_tag }}";
8
- const startIndex = file.indexOf('script_tag');
9
- const endIndex = startIndex + 'script_tag'.length;
10
-
11
- const offenses = await reportOffenses(
12
- {
13
- 'code.liquid': file,
14
- },
15
- [ParserBlockingScript],
16
- );
17
-
18
- expect(offenses).to.have.length(1);
19
- const { check, message, start, end } = offenses[0];
20
- expect(check).to.equal(ParserBlockingScript.meta.code);
21
- expect(message).to.contain('Use a <script> tag with async');
22
- expect(start.index).to.equal(startIndex);
23
- expect(end.index).to.equal(endIndex);
24
- });
25
-
26
6
  it('should report the correct offense when using the script tag', async () => {
27
7
  const file = `
28
8
  <script src="https://foo.bar/baz.js"></script>
@@ -45,104 +25,6 @@ describe('Module: ParserBlockingScript', () => {
45
25
  expect(end.index).to.equal(endIndex);
46
26
  });
47
27
 
48
- describe('Case: LiquidFilter corrections', () => {
49
- it('should suggest to replace a LiquidVariableOutput with a script tag that has the expression as URL', async () => {
50
- const file = "{{ 'asset' | script_tag }}";
51
- const offenses = await reportOffenses(
52
- {
53
- 'code.liquid': file,
54
- },
55
- [ParserBlockingScript],
56
- );
57
-
58
- expect(offenses).to.have.length(1);
59
- const offense = offenses[0]!;
60
- expect(offense).to.suggest(file, `Use an HTML script tag with the defer attribute instead`, {
61
- startIndex: 0,
62
- endIndex: file.length,
63
- insert: `<script src="{{ 'asset' }}" defer></script>`,
64
- });
65
- expect(offense).to.suggest(file, `Use an HTML script tag with the async attribute instead`, {
66
- startIndex: 0,
67
- endIndex: file.length,
68
- insert: `<script src="{{ 'asset' }}" async></script>`,
69
- });
70
-
71
- const suggestions = applySuggestions(file, offense);
72
- expect(suggestions).to.include(`<script src="{{ 'asset' }}" defer></script>`);
73
- expect(suggestions).to.include(`<script src="{{ 'asset' }}" async></script>`);
74
- });
75
-
76
- it('should suggest to replace a LiquidVariableOutput with a script tag that has the expression and previous filters as URL', async () => {
77
- const file = "{{ 'asset' | asset_url | script_tag }}";
78
- const offenses = await reportOffenses(
79
- {
80
- 'code.liquid': file,
81
- },
82
- [ParserBlockingScript],
83
- );
84
-
85
- expect(offenses).to.have.length(1);
86
- const offense = offenses[0];
87
- expect(offense).to.suggest(file, `Use an HTML script tag with the defer attribute instead`, {
88
- startIndex: 0,
89
- endIndex: file.length,
90
- insert: `<script src="{{ 'asset' | asset_url }}" defer></script>`,
91
- });
92
- expect(offense).to.suggest(file, `Use an HTML script tag with the async attribute instead`, {
93
- startIndex: 0,
94
- endIndex: file.length,
95
- insert: `<script src="{{ 'asset' | asset_url }}" async></script>`,
96
- });
97
-
98
- const suggestions = applySuggestions(file, offense);
99
- expect(suggestions).to.include(`<script src="{{ 'asset' | asset_url }}" defer></script>`);
100
- expect(suggestions).to.include(`<script src="{{ 'asset' | asset_url }}" async></script>`);
101
- });
102
-
103
- it('should not suggest anything if the script_tag appears in an echo tag', async () => {
104
- const file = "{% echo 'asset' | asset_url | script_tag %}";
105
- const offenses = await reportOffenses(
106
- {
107
- 'code.liquid': file,
108
- },
109
- [ParserBlockingScript],
110
- );
111
-
112
- expect(offenses).to.have.length(1);
113
- const { suggest } = offenses[0];
114
- expect(suggest).not.to.exist;
115
- });
116
-
117
- it('should not suggest anything if the script_tag appears in an assign tag', async () => {
118
- const file = "{% assign script = 'asset' | asset_url | script_tag %}";
119
- const offenses = await reportOffenses(
120
- {
121
- 'code.liquid': file,
122
- },
123
- [ParserBlockingScript],
124
- );
125
-
126
- expect(offenses).to.have.length(1);
127
- const { suggest } = offenses[0];
128
- expect(suggest).not.to.exist;
129
- });
130
-
131
- it('should not suggest anything if the script_tag appears in a liquid tag', async () => {
132
- const file = "{% liquid\necho 'asset' | asset_url | script_tag %}";
133
- const offenses = await reportOffenses(
134
- {
135
- 'code.liquid': file,
136
- },
137
- [ParserBlockingScript],
138
- );
139
-
140
- expect(offenses).to.have.length(1);
141
- const { suggest } = offenses[0];
142
- expect(suggest).not.to.exist;
143
- });
144
- });
145
-
146
28
  describe('Case: script tag suggestion', () => {
147
29
  it('should suggest adding both attributes at the end', async () => {
148
30
  const file = `<script src="a.js"></script>`;
@@ -1,8 +1,6 @@
1
- import { NodeTypes } from '@platformos/liquid-html-parser';
2
1
  import { LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';
3
- import { last } from '../../utils';
4
2
  import { hasAttributeValueOf, isAttr, isHtmlAttribute, isValuedHtmlAttribute } from '../utils';
5
- import { liquidFilterSuggestion, scriptTagSuggestion } from './suggestions';
3
+ import { scriptTagSuggestion } from './suggestions';
6
4
 
7
5
  export const ParserBlockingScript: LiquidCheckDefinition = {
8
6
  meta: {
@@ -10,9 +8,9 @@ export const ParserBlockingScript: LiquidCheckDefinition = {
10
8
  aliases: ['ParserBlockingScriptTag'],
11
9
  name: 'Avoid parser blocking scripts',
12
10
  docs: {
13
- description: 'They are bad ok?',
11
+ description: 'Parser-blocking scripts delay page rendering by blocking the HTML parser.',
14
12
  recommended: true,
15
- url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/parser-blocking-javascript',
13
+ url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/parser-blocking-script',
16
14
  },
17
15
  type: SourceCodeType.LiquidHtml,
18
16
  severity: Severity.ERROR,
@@ -22,34 +20,6 @@ export const ParserBlockingScript: LiquidCheckDefinition = {
22
20
 
23
21
  create(context) {
24
22
  return {
25
- // {{ 'asset' | asset_url | script_tag }}
26
- LiquidFilter: async (node, ancestors) => {
27
- if (node.name !== 'script_tag') return;
28
-
29
- const filterString = node.source.slice(node.position.start, node.position.end);
30
- const offset = filterString.indexOf('script_tag');
31
- const parentNode = last(ancestors);
32
- const grandParentNode = last(ancestors, -1);
33
-
34
- context.report({
35
- message:
36
- 'The script_tag filter is parser-blocking. Use a <script> tag with async or defer for better performance',
37
- startIndex: node.position.start + offset,
38
- endIndex: node.position.end,
39
- suggest:
40
- grandParentNode &&
41
- grandParentNode.type === NodeTypes.LiquidVariableOutput &&
42
- parentNode &&
43
- parentNode.type === NodeTypes.LiquidVariable &&
44
- last(parentNode.filters) === node
45
- ? [
46
- liquidFilterSuggestion('defer', node, parentNode, grandParentNode),
47
- liquidFilterSuggestion('async', node, parentNode, grandParentNode),
48
- ]
49
- : undefined,
50
- });
51
- },
52
-
53
23
  // <script src="...">
54
24
  HtmlRawNode: async (node) => {
55
25
  if (node.name !== 'script') {
@@ -1,36 +1,9 @@
1
- import {
2
- HtmlRawNode,
3
- LiquidFilter,
4
- LiquidVariable,
5
- LiquidVariableOutput,
6
- } from '@platformos/liquid-html-parser';
1
+ import { HtmlRawNode } from '@platformos/liquid-html-parser';
7
2
  import { LiquidHtmlSuggestion } from '../../types';
8
- import { last } from '../../utils';
9
3
 
10
4
  const suggestionMessage = (attr: 'defer' | 'async') =>
11
5
  `Use an HTML script tag with the ${attr} attribute instead`;
12
6
 
13
- export const liquidFilterSuggestion = (
14
- attr: 'defer' | 'async',
15
- node: LiquidFilter,
16
- parentNode: LiquidVariable,
17
- grandParentNode: LiquidVariableOutput,
18
- ): LiquidHtmlSuggestion => ({
19
- message: suggestionMessage(attr),
20
- fix(corrector) {
21
- const expression = node.source.slice(
22
- parentNode.expression.position.start,
23
- last(parentNode.filters, -1)?.position.end ?? node.position.start,
24
- );
25
- const url = `{{ ${expression} }}`;
26
- corrector.replace(
27
- grandParentNode.position.start,
28
- grandParentNode.position.end,
29
- `<script src="${url}" ${attr}></script>`,
30
- );
31
- },
32
- });
33
-
34
7
  export const scriptTagSuggestion = (
35
8
  attr: 'defer' | 'async',
36
9
  node: HtmlRawNode,
@@ -25,7 +25,7 @@ export const TranslationKeyExists: LiquidCheckDefinition = {
25
25
  docs: {
26
26
  description: 'Reports missing translation keys',
27
27
  recommended: true,
28
- url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/translation-key-exists',
28
+ url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/translation-key-exists',
29
29
  },
30
30
  type: SourceCodeType.LiquidHtml,
31
31
  severity: Severity.ERROR,
@@ -41,7 +41,7 @@ export const UnclosedHTMLElement: LiquidCheckDefinition = {
41
41
  docs: {
42
42
  description: 'Warns you of unbalanced HTML tags in branching code',
43
43
  recommended: true,
44
- url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/unclosed-html-element',
44
+ url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/unclosed-html-element',
45
45
  },
46
46
  type: SourceCodeType.LiquidHtml,
47
47
  severity: Severity.WARNING,
@@ -272,6 +272,10 @@ function getConditionIdentifierForMarkup(condition: string | LiquidConditionalEx
272
272
  condition.relation,
273
273
  getConditionIdentifierForMarkup(condition.right),
274
274
  ].join(' ');
275
+ case NodeTypes.JsonHashLiteral:
276
+ return '{}';
277
+ case NodeTypes.JsonArrayLiteral:
278
+ return '[]';
275
279
  default: {
276
280
  return assertNever(condition);
277
281
  }