@platformos/platformos-check-common 0.0.19 → 0.0.20

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 (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/checks/index.js +4 -0
  3. package/dist/checks/index.js.map +1 -1
  4. package/dist/checks/missing-content-for-layout/index.d.ts +2 -0
  5. package/dist/checks/missing-content-for-layout/index.js +89 -0
  6. package/dist/checks/missing-content-for-layout/index.js.map +1 -0
  7. package/dist/checks/reserved-variable-name/index.d.ts +2 -0
  8. package/dist/checks/reserved-variable-name/index.js +82 -0
  9. package/dist/checks/reserved-variable-name/index.js.map +1 -0
  10. package/dist/checks/unused-assign/index.js +4 -0
  11. package/dist/checks/unused-assign/index.js.map +1 -1
  12. package/dist/checks/utils.d.ts +7 -0
  13. package/dist/checks/utils.js +8 -0
  14. package/dist/checks/utils.js.map +1 -1
  15. package/dist/find-root.js +15 -2
  16. package/dist/find-root.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +3 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/liquid-doc/utils.d.ts +1 -1
  21. package/dist/to-source-code.d.ts +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/dist/types.d.ts +10 -0
  24. package/dist/types.js.map +1 -1
  25. package/package.json +2 -2
  26. package/src/checks/index.ts +4 -0
  27. package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.spec.ts +23 -0
  28. package/src/checks/missing-content-for-layout/index.spec.ts +84 -0
  29. package/src/checks/missing-content-for-layout/index.ts +94 -0
  30. package/src/checks/missing-page/index.spec.ts +94 -0
  31. package/src/checks/reserved-variable-name/index.spec.ts +142 -0
  32. package/src/checks/reserved-variable-name/index.ts +85 -0
  33. package/src/checks/unused-assign/index.spec.ts +13 -0
  34. package/src/checks/unused-assign/index.ts +4 -1
  35. package/src/checks/utils.ts +11 -0
  36. package/src/find-root.ts +17 -2
  37. package/src/index.ts +2 -0
  38. package/src/types.ts +19 -0
@@ -9,6 +9,7 @@ import {
9
9
  AttrUnquoted,
10
10
  LiquidHtmlNode,
11
11
  LiquidBranch,
12
+ LiquidLiteralValues,
12
13
  LiquidTagFor,
13
14
  LiquidTagTablerow,
14
15
  LiquidTag,
@@ -16,6 +17,16 @@ import {
16
17
  } from '@platformos/liquid-html-parser';
17
18
  import { LiquidHtmlNodeOfType as NodeOfType } from '../types';
18
19
 
20
+ /**
21
+ * Names that Liquid resolves as built-in literals before looking up variables
22
+ * (Liquid::Expression::LITERALS in the backend, `LiquidLiteralValues` in the
23
+ * parser grammar). Assigning to them succeeds silently, but reading them
24
+ * always returns the literal, never the assigned value.
25
+ */
26
+ export const RESERVED_VARIABLE_NAMES: ReadonlySet<string> = new Set(
27
+ Object.keys(LiquidLiteralValues),
28
+ );
29
+
19
30
  type ElementType<T> = T extends (infer E)[] ? E : never;
20
31
 
21
32
  export type ValuedHtmlAttribute = AttrSingleQuoted | AttrDoubleQuoted | AttrUnquoted;
package/src/find-root.ts CHANGED
@@ -3,13 +3,28 @@ import * as path from './path';
3
3
 
4
4
  type FileExists = (uri: string) => Promise<boolean>;
5
5
 
6
+ function isInsideApp(dir: UriString): boolean {
7
+ let current = dir;
8
+ while (true) {
9
+ const parent = path.dirname(current);
10
+ if (parent === current) return false;
11
+ if (path.basename(parent) === 'app') return true;
12
+ current = parent;
13
+ }
14
+ }
15
+
6
16
  async function isRoot(dir: UriString, fileExists: FileExists) {
7
17
  return or(
8
18
  fileExists(path.join(dir, '.pos')),
9
19
  fileExists(path.join(dir, '.platformos-check.yml')),
10
20
  fileExists(path.join(dir, 'app')),
11
- // modules/ is a root indicator only when not inside app/ (app/modules/ is a valid subdirectory)
12
- and(fileExists(path.join(dir, 'modules')), Promise.resolve(path.basename(dir) !== 'app')),
21
+ // modules/ is a root indicator only when not inside an app/ subtree.
22
+ // app/modules/ is a valid subdirectory, and app/views/partials/modules/ is a
23
+ // legitimate partial organization that should not be mistaken for a project root.
24
+ and(
25
+ fileExists(path.join(dir, 'modules')),
26
+ Promise.resolve(path.basename(dir) !== 'app' && !isInsideApp(dir)),
27
+ ),
13
28
  );
14
29
  }
15
30
 
package/src/index.ts CHANGED
@@ -60,11 +60,13 @@ export {
60
60
  isFormConfiguration,
61
61
  isKnownGraphQLFile,
62
62
  isKnownLiquidFile,
63
+ isKnownYAMLFile,
63
64
  isLayout,
64
65
  isMigration,
65
66
  isPage,
66
67
  isPartial,
67
68
  isSms,
69
+ isSupportedSourceFile,
68
70
  PlatformOSFileType,
69
71
  } from '@platformos/platformos-common';
70
72
  export * from './frontmatter';
package/src/types.ts CHANGED
@@ -315,6 +315,22 @@ export type Translations = {
315
315
  * target: 'file:///app/views/partials/child.liquid'
316
316
  * }
317
317
  */
318
+ /**
319
+ * The semantic Liquid construct that created a {@link Reference} edge.
320
+ *
321
+ * Optional/additive: older producers may omit it. Lets consumers distinguish a
322
+ * `{% render %}` edge from an `{% include %}` / `{% function %}` / `{% graphql %}`
323
+ * / `{% background %}` / asset / layout-association edge without re-parsing.
324
+ */
325
+ export type ReferenceKind =
326
+ | 'render'
327
+ | 'include'
328
+ | 'function'
329
+ | 'background'
330
+ | 'graphql'
331
+ | 'asset'
332
+ | 'layout';
333
+
318
334
  export type Reference = {
319
335
  source: Location;
320
336
  target: Location;
@@ -322,6 +338,9 @@ export type Reference = {
322
338
  type:
323
339
  | 'direct' // explicit dependency, e.g. {% render 'partial' %}
324
340
  | 'indirect'; // indirect dependency
341
+
342
+ /** Which Liquid construct produced this edge. Optional for backwards compatibility. */
343
+ kind?: ReferenceKind;
325
344
  };
326
345
 
327
346
  export type Range = [start: number, end: number]; // represents a range in the source code