@intentius/chant 0.22.0 → 0.23.0

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 (47) hide show
  1. package/dist/cli/build-params-cli.d.ts +55 -0
  2. package/dist/cli/build-params-cli.d.ts.map +1 -0
  3. package/dist/cli/commands/build.d.ts.map +1 -1
  4. package/dist/cli/commands/lint.d.ts.map +1 -1
  5. package/dist/cli/handlers/build.d.ts.map +1 -1
  6. package/dist/cli/handlers/run.d.ts +14 -1
  7. package/dist/cli/handlers/run.d.ts.map +1 -1
  8. package/dist/cli/lsp/server.d.ts.map +1 -1
  9. package/dist/components/cli-support.d.ts +33 -2
  10. package/dist/components/cli-support.d.ts.map +1 -1
  11. package/dist/components/discover.d.ts +28 -0
  12. package/dist/components/discover.d.ts.map +1 -1
  13. package/dist/discovery/fold-import.d.ts +38 -8
  14. package/dist/discovery/fold-import.d.ts.map +1 -1
  15. package/dist/discovery/index.d.ts +15 -4
  16. package/dist/discovery/index.d.ts.map +1 -1
  17. package/dist/fold/subset.d.ts +16 -2
  18. package/dist/fold/subset.d.ts.map +1 -1
  19. package/dist/lint/engine.d.ts +11 -1
  20. package/dist/lint/engine.d.ts.map +1 -1
  21. package/dist/lint/rule.d.ts +14 -0
  22. package/dist/lint/rule.d.ts.map +1 -1
  23. package/package.json +1 -1
  24. package/src/cli/build-params-cli.test.ts +139 -0
  25. package/src/cli/build-params-cli.ts +107 -0
  26. package/src/cli/commands/build.ts +16 -36
  27. package/src/cli/commands/lint.test.ts +74 -0
  28. package/src/cli/commands/lint.ts +33 -9
  29. package/src/cli/handlers/build.test.ts +147 -0
  30. package/src/cli/handlers/build.ts +23 -8
  31. package/src/cli/handlers/run.test.ts +160 -5
  32. package/src/cli/handlers/run.ts +46 -8
  33. package/src/cli/lsp/server.ts +7 -2
  34. package/src/components/cli-support.test.ts +221 -3
  35. package/src/components/cli-support.ts +37 -6
  36. package/src/components/discover.test.ts +63 -1
  37. package/src/components/discover.ts +42 -0
  38. package/src/discovery/fold-import.ts +202 -20
  39. package/src/discovery/index.test.ts +131 -0
  40. package/src/discovery/index.ts +38 -8
  41. package/src/discovery/sandbox/fold-boundary.test.ts +254 -0
  42. package/src/fold/subset.test.ts +28 -14
  43. package/src/fold/subset.ts +16 -2
  44. package/src/lint/engine.ts +12 -0
  45. package/src/lint/rule.ts +14 -0
  46. package/src/lint/rules/evl001-non-literal-expression.test.ts +39 -0
  47. package/src/lint/rules/evl001-non-literal-expression.ts +1 -1
@@ -2,6 +2,7 @@ import { describe, test, expect } from "vitest";
2
2
  import * as ts from "typescript";
3
3
  import { evl001NonLiteralExpressionRule } from "./evl001-non-literal-expression";
4
4
  import type { LintContext } from "../rule";
5
+ import type { IntrinsicDef } from "../../lexicon";
5
6
 
6
7
  function createContext(code: string, filePath = "test.ts"): LintContext {
7
8
  const sourceFile = ts.createSourceFile(filePath, code, ts.ScriptTarget.Latest, true);
@@ -155,4 +156,42 @@ describe("EVL001: non-literal-expression", () => {
155
156
  expect(diags).toHaveLength(1);
156
157
  expect(diags[0].ruleId).toBe("EVL001");
157
158
  });
159
+
160
+ /**
161
+ * chant #1106 — `LintContext.intrinsics`, threaded from `runLint`, is what
162
+ * lets this rule answer a registered call-form intrinsic exactly like
163
+ * `fold()` does instead of flagging every call. See ../../fold/subset.ts
164
+ * and ../../fold/subset.test.ts for the shared predicate this rule calls.
165
+ */
166
+ describe("context.intrinsics (#1106)", () => {
167
+ const REF: IntrinsicDef[] = [{ name: "Ref", isTag: false, foldsAsCall: true }];
168
+
169
+ test("flags a call to a registered, opted-in intrinsic when the context carries no registry", () => {
170
+ const ctx = createContext(`new Bucket({ name: Ref(env) });`);
171
+ const diags = evl001NonLiteralExpressionRule.check(ctx);
172
+ expect(diags).toHaveLength(1);
173
+ expect(diags[0].ruleId).toBe("EVL001");
174
+ });
175
+
176
+ test("does not flag that same call once the context carries the registry", () => {
177
+ const ctx: LintContext = { ...createContext(`new Bucket({ name: Ref(env) });`), intrinsics: REF };
178
+ expect(evl001NonLiteralExpressionRule.check(ctx)).toHaveLength(0);
179
+ });
180
+
181
+ test("a registered name WITHOUT the call opt-in still flags, even with the registry present", () => {
182
+ const notOptedIn: IntrinsicDef[] = [{ name: "Reference", isTag: false }];
183
+ const ctx: LintContext = {
184
+ ...createContext(`new Bucket({ name: Reference(env) });`),
185
+ intrinsics: notOptedIn,
186
+ };
187
+ const diags = evl001NonLiteralExpressionRule.check(ctx);
188
+ expect(diags).toHaveLength(1);
189
+ });
190
+
191
+ test("an unregistered call still flags with the registry present", () => {
192
+ const ctx: LintContext = { ...createContext(`new Bucket({ name: makeName() });`), intrinsics: REF };
193
+ const diags = evl001NonLiteralExpressionRule.check(ctx);
194
+ expect(diags).toHaveLength(1);
195
+ });
196
+ });
158
197
  });
@@ -31,7 +31,7 @@ function checkNode(node: ts.Node, context: LintContext, diagnostics: LintDiagnos
31
31
  const firstArg = node.arguments[0];
32
32
  if (ts.isObjectLiteralExpression(firstArg)) {
33
33
  for (const prop of firstArg.properties) {
34
- const violation = checkObjectMember(prop);
34
+ const violation = checkObjectMember(prop, context.intrinsics);
35
35
  if (violation) {
36
36
  const { line, character } = context.sourceFile.getLineAndCharacterOfPosition(
37
37
  violation.node.getStart(context.sourceFile),