@intentius/chant 0.18.26 → 0.18.28
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/commands/lint.d.ts.map +1 -1
- package/dist/cli/handlers/components.d.ts +0 -16
- package/dist/cli/handlers/components.d.ts.map +1 -1
- package/dist/cli/handlers/graph.d.ts +3 -1
- package/dist/cli/handlers/graph.d.ts.map +1 -1
- package/dist/cli/main.d.ts +10 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/components/cli-support.d.ts +4 -0
- package/dist/components/cli-support.d.ts.map +1 -1
- package/dist/graph-dot.d.ts.map +1 -1
- package/dist/graph-ir.d.ts +5 -0
- package/dist/graph-ir.d.ts.map +1 -1
- package/dist/graph-mermaid.d.ts.map +1 -1
- package/dist/lexicon.d.ts +36 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/status.d.ts +12 -0
- package/dist/lifecycle/status.d.ts.map +1 -1
- package/dist/lint/config.d.ts +12 -0
- package/dist/lint/config.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/cli/commands/lint.test.ts +89 -0
- package/src/cli/commands/lint.ts +58 -18
- package/src/cli/handlers/components.ts +65 -2
- package/src/cli/handlers/graph.test.ts +79 -0
- package/src/cli/handlers/graph.ts +65 -1
- package/src/cli/main.test.ts +49 -1
- package/src/cli/main.ts +44 -3
- package/src/components/cli-support.ts +12 -1
- package/src/graph-dot.ts +6 -5
- package/src/graph-ir.ts +5 -0
- package/src/graph-mermaid.ts +8 -6
- package/src/lexicon.ts +35 -0
- package/src/lifecycle/status.test.ts +32 -0
- package/src/lifecycle/status.ts +27 -0
- package/src/lint/config.test.ts +29 -1
- package/src/lint/config.ts +23 -0
package/src/lint/config.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, test, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { loadConfig, DEFAULT_CONFIG } from "./config";
|
|
2
|
+
import { loadConfig, DEFAULT_CONFIG, findProjectRoot } from "./config";
|
|
3
3
|
import { writeFileSync, mkdirSync, rmSync } from "fs";
|
|
4
4
|
import { join } from "path";
|
|
5
5
|
|
|
@@ -684,3 +684,31 @@ describe("loadConfig", () => {
|
|
|
684
684
|
expect(config.rules?.["noisy-rule"]).toBe("off");
|
|
685
685
|
});
|
|
686
686
|
});
|
|
687
|
+
|
|
688
|
+
describe("findProjectRoot", () => {
|
|
689
|
+
test("returns the directory holding chant.config.json", () => {
|
|
690
|
+
writeFileSync(join(TEST_DIR, "chant.config.json"), "{}");
|
|
691
|
+
expect(findProjectRoot(TEST_DIR)).toBe(TEST_DIR);
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
test("walks up from a subpath to the config-bearing root", () => {
|
|
695
|
+
writeFileSync(join(TEST_DIR, "chant.config.json"), "{}");
|
|
696
|
+
const sub = join(TEST_DIR, "src", "lib");
|
|
697
|
+
mkdirSync(sub, { recursive: true });
|
|
698
|
+
expect(findProjectRoot(sub)).toBe(TEST_DIR);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
test("also recognizes chant.config.ts as a project root", () => {
|
|
702
|
+
writeFileSync(join(TEST_DIR, "chant.config.ts"), "export default {};");
|
|
703
|
+
const sub = join(TEST_DIR, "src");
|
|
704
|
+
mkdirSync(sub, { recursive: true });
|
|
705
|
+
expect(findProjectRoot(sub)).toBe(TEST_DIR);
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
test("falls back to the start dir when no config is found", () => {
|
|
709
|
+
const sub = join(TEST_DIR, "nowhere");
|
|
710
|
+
mkdirSync(sub, { recursive: true });
|
|
711
|
+
// No chant.config anywhere under TEST_DIR — returns the (resolved) start dir.
|
|
712
|
+
expect(findProjectRoot(sub)).toBe(sub);
|
|
713
|
+
});
|
|
714
|
+
});
|
package/src/lint/config.ts
CHANGED
|
@@ -323,6 +323,29 @@ function loadConfigFile(configPath: string, visited: Set<string> = new Set()): L
|
|
|
323
323
|
return mergedConfig;
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
/**
|
|
327
|
+
* Walk up from `startDir` to the nearest ancestor holding a chant project
|
|
328
|
+
* config (`chant.config.ts` or `chant.config.json`). Returns that directory, or
|
|
329
|
+
* `startDir` unchanged when none is found before the filesystem root.
|
|
330
|
+
*
|
|
331
|
+
* Linting a subpath (`chant graph src --format ir`, `chant lint src/lib`) must
|
|
332
|
+
* still see the project-root config: its `lint.overrides` globs are written
|
|
333
|
+
* project-root-relative (`src/lib/**`), and a rule set scoped only to the lint
|
|
334
|
+
* arg would silently drop them. Config discovery therefore anchors on the
|
|
335
|
+
* project root, not the path being linted.
|
|
336
|
+
*/
|
|
337
|
+
export function findProjectRoot(startDir: string): string {
|
|
338
|
+
let dir = resolve(startDir);
|
|
339
|
+
for (;;) {
|
|
340
|
+
if (existsSync(join(dir, "chant.config.ts")) || existsSync(join(dir, "chant.config.json"))) {
|
|
341
|
+
return dir;
|
|
342
|
+
}
|
|
343
|
+
const parent = dirname(dir);
|
|
344
|
+
if (parent === dir) return resolve(startDir);
|
|
345
|
+
dir = parent;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
326
349
|
/**
|
|
327
350
|
* Load lint configuration from a directory.
|
|
328
351
|
*
|