@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.
- package/dist/cli/build-params-cli.d.ts +55 -0
- package/dist/cli/build-params-cli.d.ts.map +1 -0
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/lint.d.ts.map +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/run.d.ts +14 -1
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/lsp/server.d.ts.map +1 -1
- package/dist/components/cli-support.d.ts +33 -2
- package/dist/components/cli-support.d.ts.map +1 -1
- package/dist/components/discover.d.ts +28 -0
- package/dist/components/discover.d.ts.map +1 -1
- package/dist/discovery/fold-import.d.ts +38 -8
- package/dist/discovery/fold-import.d.ts.map +1 -1
- package/dist/discovery/index.d.ts +15 -4
- package/dist/discovery/index.d.ts.map +1 -1
- package/dist/fold/subset.d.ts +16 -2
- package/dist/fold/subset.d.ts.map +1 -1
- package/dist/lint/engine.d.ts +11 -1
- package/dist/lint/engine.d.ts.map +1 -1
- package/dist/lint/rule.d.ts +14 -0
- package/dist/lint/rule.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/build-params-cli.test.ts +139 -0
- package/src/cli/build-params-cli.ts +107 -0
- package/src/cli/commands/build.ts +16 -36
- package/src/cli/commands/lint.test.ts +74 -0
- package/src/cli/commands/lint.ts +33 -9
- package/src/cli/handlers/build.test.ts +147 -0
- package/src/cli/handlers/build.ts +23 -8
- package/src/cli/handlers/run.test.ts +160 -5
- package/src/cli/handlers/run.ts +46 -8
- package/src/cli/lsp/server.ts +7 -2
- package/src/components/cli-support.test.ts +221 -3
- package/src/components/cli-support.ts +37 -6
- package/src/components/discover.test.ts +63 -1
- package/src/components/discover.ts +42 -0
- package/src/discovery/fold-import.ts +202 -20
- package/src/discovery/index.test.ts +131 -0
- package/src/discovery/index.ts +38 -8
- package/src/discovery/sandbox/fold-boundary.test.ts +254 -0
- package/src/fold/subset.test.ts +28 -14
- package/src/fold/subset.ts +16 -2
- package/src/lint/engine.ts +12 -0
- package/src/lint/rule.ts +14 -0
- package/src/lint/rules/evl001-non-literal-expression.test.ts +39 -0
- 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),
|