@vwala/tooling-config 1.1.0 → 1.3.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.
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `.agents/skills/` is the only place a skill is stored. Every other agent
4
+ * directory — `.claude/skills/`, `.cursor/skills/`, and the rest — holds
5
+ * symlinks into it.
6
+ *
7
+ * The failure this prevents is silent. `npx skills update` rewrites
8
+ * `.agents/skills/`; a materialised copy under `.claude/skills/` is untouched
9
+ * and keeps being the version Claude actually loads. Nothing errors, no diff
10
+ * looks wrong, and the agent quietly follows guidance that was replaced months
11
+ * ago. A symlink cannot drift, which is why the convention is a symlink rather
12
+ * than a sync step.
13
+ *
14
+ * Biome cannot express this. It parses the syntax of source files, and whether
15
+ * a path is a symlink is a property of the index, not of any file's contents —
16
+ * the same wall `check-naming` hits with folder names.
17
+ *
18
+ * Scope is deliberately narrow: only the `skills/` subtree of each agent
19
+ * directory. `.claude/settings.json`, `.claude/commands/` and `.claude/agents/`
20
+ * are genuinely Claude's own and have no `.agents/` counterpart to mirror.
21
+ *
22
+ * Mirror completeness is deliberately not checked. Agent directories are opt-in
23
+ * per tool, and a repository that only uses Claude should not be made to create
24
+ * a `.cursor/` it will never read.
25
+ */
26
+ import {
27
+ readBlob,
28
+ readIndexEntries,
29
+ resolveSymlinkTarget,
30
+ SYMLINK_MODE,
31
+ } from "../../_scripts/git-index.mjs";
32
+
33
+ const SOURCE_OF_TRUTH = ".agents/skills";
34
+ const AGENT_DIRECTORIES = [
35
+ ".claude",
36
+ ".cursor",
37
+ ".gemini",
38
+ ".opencode",
39
+ ".codex",
40
+ ".windsurf",
41
+ ];
42
+
43
+ const entries = readIndexEntries();
44
+ const violations = [];
45
+
46
+ function isTrackedDirectory(directory) {
47
+ return entries.some((entry) => entry.path.startsWith(`${directory}/`));
48
+ }
49
+
50
+ /**
51
+ * Git stores a symlinked directory as a single index entry and never walks into
52
+ * it, so `.claude/skills/foo` appears once at mode `120000` and
53
+ * `.claude/skills/foo/SKILL.md` does not appear at all. That makes any tracked
54
+ * path more than one segment deep the evidence that someone replaced the
55
+ * symlink with a real directory — and grouping by that first segment reports a
56
+ * copied skill once rather than once per file inside it.
57
+ */
58
+ for (const agentDirectory of AGENT_DIRECTORIES) {
59
+ const skillsRoot = `${agentDirectory}/skills/`;
60
+ const bySkill = new Map();
61
+
62
+ for (const entry of entries) {
63
+ if (!entry.path.startsWith(skillsRoot)) {
64
+ continue;
65
+ }
66
+ const [skill] = entry.path.slice(skillsRoot.length).split("/");
67
+ // `.gitkeep` and friends keep an otherwise symlink-only folder in git.
68
+ if (skill.startsWith(".")) {
69
+ continue;
70
+ }
71
+ const group = bySkill.get(skill) ?? [];
72
+ group.push(entry);
73
+ bySkill.set(skill, group);
74
+ }
75
+
76
+ for (const [skill, group] of bySkill) {
77
+ const skillPath = `${skillsRoot}${skill}`;
78
+ const expected = `${SOURCE_OF_TRUTH}/${skill}`;
79
+ const link = group.find((entry) => entry.path === skillPath);
80
+
81
+ if (group.length > 1 || link === undefined) {
82
+ violations.push(
83
+ `${skillPath}\n Materialised copy of a skill. Replace it with a symlink to ${expected}.`,
84
+ );
85
+ continue;
86
+ }
87
+
88
+ if (link.mode !== SYMLINK_MODE) {
89
+ violations.push(
90
+ `${skillPath}\n Regular file where a symlink to ${expected} belongs.`,
91
+ );
92
+ continue;
93
+ }
94
+
95
+ const target = readBlob({ sha: link.sha });
96
+ const resolved = resolveSymlinkTarget({ linkPath: skillPath, target });
97
+
98
+ if (resolved === null) {
99
+ violations.push(
100
+ `${skillPath}\n Symlink target ${JSON.stringify(target)} is not a usable path inside the repository.`,
101
+ );
102
+ continue;
103
+ }
104
+
105
+ // Requiring the exact path rather than a prefix rejects three things at
106
+ // once: a link into another mirror, a link reaching inside a skill, and a
107
+ // link whose name disagrees with the skill it points at.
108
+ if (resolved !== expected) {
109
+ violations.push(
110
+ `${skillPath}\n Symlink resolves to "${resolved}" but must resolve to "${expected}".`,
111
+ );
112
+ continue;
113
+ }
114
+
115
+ if (!isTrackedDirectory(resolved)) {
116
+ violations.push(
117
+ `${skillPath}\n Symlink target "${resolved}" is not tracked. The skill it points at does not exist.`,
118
+ );
119
+ }
120
+ }
121
+ }
122
+
123
+ // The source of truth has to be real files. A symlink here means the content
124
+ // lives somewhere unversioned, and every mirror points at nothing.
125
+ for (const entry of entries) {
126
+ if (
127
+ entry.path.startsWith(`${SOURCE_OF_TRUTH}/`) &&
128
+ entry.mode === SYMLINK_MODE
129
+ ) {
130
+ violations.push(
131
+ `${entry.path}\n Symlink inside ${SOURCE_OF_TRUTH}/. The source of truth must hold real files.`,
132
+ );
133
+ }
134
+ }
135
+
136
+ if (violations.length > 0) {
137
+ console.error(`\n ✖ ${violations.length} agent-skill violation(s):\n`);
138
+ for (const violation of violations) {
139
+ console.error(` ${violation}\n`);
140
+ }
141
+ process.exit(1);
142
+ }
143
+
144
+ console.log(" ✔ agent skills clean");
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The two halves of the naming convention that Biome's `useFilenamingConvention`
4
+ * rule cannot express.
5
+ *
6
+ * 1. Folders. Biome only ever sees a filename, never the directories above it,
7
+ * so `SomeFolder/invoice.ts` passes the rule untouched.
8
+ * 2. Severity by age. The convention applies to new code and asks that existing
9
+ * files be renamed only when meaningfully touched, so the shared config sets
10
+ * the rule to `warn`. A Biome severity is fixed per glob and cannot depend on
11
+ * git history — this script supplies the other half, failing only on files
12
+ * added since the base ref. Existing offenders are printed as warnings and do
13
+ * not affect the exit code.
14
+ *
15
+ * Filenames are re-checked here rather than left to Biome, because the rule's
16
+ * warning never fails a build; a file added in this branch has to be an error
17
+ * somewhere, and this is that somewhere. Expect a new badly-named file to be
18
+ * reported twice — once by `biome ci` as a warning, once here as an error.
19
+ *
20
+ * Wire this into a repository's own check script and run it from the repository
21
+ * root. Set NAMING_BASE_REF when the default branch is not `origin/main`; when
22
+ * the base ref cannot be resolved at all (a shallow CI clone, a fresh repo with
23
+ * no remote) nothing counts as new and the script degrades to warnings only.
24
+ *
25
+ * See: .agents/skills/vwala-conventions/references/typescript-naming.md
26
+ */
27
+ import { execFileSync } from "node:child_process";
28
+
29
+ const BASE_REF = process.env.NAMING_BASE_REF ?? "origin/main";
30
+ const IGNORED_PREFIXES = [".agents/", ".claude/", ".husky/"];
31
+ const SOURCE_FILE = /\.[cm]?[jt]sx?$/;
32
+ const KEBAB_CASE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
33
+ // Folder names that are a convention in their own right rather than a name:
34
+ // the test and story folders, the `_scripts` prefix this package uses for
35
+ // runnable helpers, anything hidden, and the bracket/paren/@ segments that
36
+ // Next.js and Expo routing give meaning to.
37
+ const RESERVED_FOLDER = /^(__[a-z]+__|_[a-z-]+|\..+|\[.+\]|\(.+\)|@.+|\+.+)$/;
38
+
39
+ const trackedFiles = git(["ls-files"]);
40
+ const untrackedFiles = git(["ls-files", "--others", "--exclude-standard"]);
41
+ const files = [...trackedFiles, ...untrackedFiles].filter(
42
+ (file) => !IGNORED_PREFIXES.some((prefix) => file.startsWith(prefix)),
43
+ );
44
+ const newFiles = new Set([...untrackedFiles, ...addedSinceBaseRef()]);
45
+
46
+ const errors = [];
47
+ const warnings = [];
48
+
49
+ /**
50
+ * A folder is reported once, not once per file inside it, and counts as new
51
+ * only when every file under it is new — a rename of a long-standing folder
52
+ * would otherwise read as an error the moment one file is added to it.
53
+ */
54
+ const folders = new Map();
55
+ for (const file of files) {
56
+ const segments = file.split("/");
57
+ for (const [index, segment] of segments.slice(0, -1).entries()) {
58
+ const folder = segments.slice(0, index + 1).join("/");
59
+ const existing = folders.get(folder);
60
+ folders.set(folder, {
61
+ segment,
62
+ isNew: (existing?.isNew ?? true) && newFiles.has(file),
63
+ });
64
+ }
65
+ }
66
+
67
+ for (const [folder, { segment, isNew }] of folders) {
68
+ if (!KEBAB_CASE.test(segment) && !RESERVED_FOLDER.test(segment)) {
69
+ report({
70
+ isNew,
71
+ violation: `${folder}/\n Folder "${segment}" is not kebab-case.`,
72
+ });
73
+ }
74
+ }
75
+
76
+ for (const file of files) {
77
+ if (!SOURCE_FILE.test(file)) {
78
+ continue;
79
+ }
80
+ // `payment.service.ts` is a name plus two extensions; the convention allows a
81
+ // dot-separated responsibility suffix, so every part has to be kebab-case
82
+ // rather than just the part before the first dot.
83
+ const parts = basename(file).split(".");
84
+ const offending = parts.find((part) => !KEBAB_CASE.test(part));
85
+ if (offending !== undefined) {
86
+ report({
87
+ isNew: newFiles.has(file),
88
+ violation: `${file}\n "${offending}" is not kebab-case. Name the file after its primary export: \`PaymentService\` → \`payment.service.ts\`.`,
89
+ });
90
+ }
91
+ }
92
+
93
+ if (warnings.length > 0) {
94
+ console.warn(
95
+ `\n ! ${warnings.length} naming violation(s) in existing files — rename when you next touch them:\n`,
96
+ );
97
+ for (const warning of warnings) {
98
+ console.warn(` ${warning}\n`);
99
+ }
100
+ }
101
+
102
+ if (errors.length > 0) {
103
+ console.error(`\n ✖ ${errors.length} naming violation(s) in new files:\n`);
104
+ for (const error of errors) {
105
+ console.error(` ${error}\n`);
106
+ }
107
+ process.exit(1);
108
+ }
109
+
110
+ console.log(" ✔ no naming violations in new files");
111
+
112
+ function report({ isNew, violation }) {
113
+ if (isNew) {
114
+ errors.push(violation);
115
+ } else {
116
+ warnings.push(violation);
117
+ }
118
+ }
119
+
120
+ function basename(file) {
121
+ const segments = file.split("/");
122
+ return segments[segments.length - 1];
123
+ }
124
+
125
+ /**
126
+ * Diffs the merge base against the working tree rather than against HEAD, so
127
+ * files added but not yet committed are held to the same standard as the ones
128
+ * already on the branch.
129
+ */
130
+ function addedSinceBaseRef() {
131
+ let mergeBase;
132
+ try {
133
+ mergeBase = execFileSync("git", ["merge-base", BASE_REF, "HEAD"], {
134
+ encoding: "utf8",
135
+ stdio: ["ignore", "pipe", "ignore"],
136
+ }).trim();
137
+ } catch {
138
+ console.warn(
139
+ ` ! Cannot resolve ${BASE_REF} — reporting every violation as a warning.`,
140
+ );
141
+ return [];
142
+ }
143
+ return git(["diff", "--diff-filter=A", "--name-only", mergeBase]);
144
+ }
145
+
146
+ function git(args) {
147
+ return execFileSync("git", args, {
148
+ encoding: "utf8",
149
+ maxBuffer: 1024 * 1024 * 64,
150
+ })
151
+ .split("\n")
152
+ .filter(Boolean);
153
+ }
@@ -49,6 +49,16 @@
49
49
  "formatter": {
50
50
  "enabled": false
51
51
  }
52
+ },
53
+ {
54
+ "includes": ["**/test-support.ts", "**/testSupport.ts"],
55
+ "linter": {
56
+ "rules": {
57
+ "performance": {
58
+ "noReExportAll": "off"
59
+ }
60
+ }
61
+ }
52
62
  }
53
63
  ],
54
64
  "plugins": [
@@ -66,6 +76,7 @@
66
76
  "!**/*.test.tsx"
67
77
  ]
68
78
  },
79
+ "./node_modules/@vwala/tooling-config/src/biome/plugins/use-alias-imports.grit",
69
80
  "./node_modules/@vwala/tooling-config/src/biome/plugins/use-given-when-then-test-names.grit",
70
81
  {
71
82
  "path": "./node_modules/@vwala/tooling-config/src/biome/plugins/use-tests-folder-location.grit",
@@ -75,6 +86,10 @@
75
86
  "!**/__tests__/**",
76
87
  "!**/.agents/**"
77
88
  ]
89
+ },
90
+ {
91
+ "path": "./node_modules/@vwala/tooling-config/src/biome/plugins/use-pnpm-scripts.grit",
92
+ "includes": ["**/package.json"]
78
93
  }
79
94
  ],
80
95
  "linter": {
@@ -102,12 +117,16 @@
102
117
  }
103
118
  },
104
119
  "correctness": {
120
+ "noPrivateImports": "error",
105
121
  "noUndeclaredVariables": "error",
106
122
  "noUnusedFunctionParameters": "error",
107
123
  "noUnusedImports": "error",
108
124
  "noUnusedPrivateClassMembers": "error",
109
125
  "noUnusedVariables": "error"
110
126
  },
127
+ "performance": {
128
+ "noReExportAll": "error"
129
+ },
111
130
  "preset": "recommended",
112
131
  "style": {
113
132
  "noEnum": "error",
@@ -124,7 +143,30 @@
124
143
  }
125
144
  }
126
145
  },
127
- "useBlockStatements": "warn"
146
+ "useBlockStatements": "warn",
147
+ "useExportType": "error",
148
+ "useFilenamingConvention": {
149
+ "level": "warn",
150
+ "options": {
151
+ "filenameCases": ["kebab-case"],
152
+ "requireAscii": true,
153
+ "strictCase": false
154
+ }
155
+ },
156
+ "useNamingConvention": {
157
+ "level": "warn",
158
+ "options": {
159
+ "conventions": [
160
+ {
161
+ "match": ".*",
162
+ "selector": { "kind": "objectLiteralProperty" }
163
+ },
164
+ { "match": ".*", "selector": { "kind": "typeProperty" } }
165
+ ],
166
+ "requireAscii": true,
167
+ "strictCase": false
168
+ }
169
+ }
128
170
  },
129
171
  "suspicious": {
130
172
  "noArrayIndexKey": "warn",
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The halves of the pnpm convention that `use-pnpm-scripts.grit` cannot express.
4
+ *
5
+ * A GritQL plugin sees one file's syntax, so it can police package.json scripts
6
+ * and nothing else. The lockfiles, the `packageManager` field, the invocations
7
+ * in git hooks and CI workflows and Dockerfiles, and the escape hatch itself
8
+ * all live here. Wire this into a repository's own check script and run it from
9
+ * the repository root; it reads the repository through git, so it only sees
10
+ * tracked files.
11
+ *
12
+ * The escape hatch comes first. The convention says a repository that
13
+ * explicitly uses another package manager keeps it, so this is a no-op unless
14
+ * the repository opts in — by naming pnpm in `packageManager`, or by tracking a
15
+ * pnpm-lock.yaml with no other manager declared. An explicit foreign
16
+ * `packageManager` wins outright, so a stray lockfile cannot switch the script
17
+ * on. A repository with no package.json at all is skipped too, because the
18
+ * runner that sequences this also runs in repositories that are not Node ones.
19
+ *
20
+ * npm-shrinkwrap.json and the bun lockfiles are treated as competing lockfiles
21
+ * alongside the package-lock.json and yarn.lock the convention names — same
22
+ * defect, and naming only two would read as a deliberate exemption of the rest.
23
+ *
24
+ * npm is flagged on its install and run verbs rather than on the bare word, so
25
+ * the registry operations npm genuinely owns still pass: `npm publish`,
26
+ * `npm view`, `npm pkg set`, `npm --version`. That is not a courtesy — OIDC
27
+ * trusted publishing needs the npm CLI, and this package's own release workflow
28
+ * runs all four. `npx --no` is allowed for the same reason the shipped
29
+ * commit-msg hook uses it: it resolves the LOCAL binary and refuses to fetch.
30
+ *
31
+ * Markdown is deliberately out of scope. Documentation quotes a third party's
32
+ * install line as a citation, and a stale README is a review problem rather
33
+ * than a build-breaking one, so only files that actually execute are scanned.
34
+ *
35
+ * See: .agents/skills/vwala-conventions/references/prefer-pnpm.md
36
+ */
37
+ import { execFileSync } from "node:child_process";
38
+ import { readFileSync } from "node:fs";
39
+
40
+ const IGNORED_PREFIXES = [".agents/", ".claude/", "node_modules/"];
41
+ const COMPETING_LOCKFILE =
42
+ /(^|\/)(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|bun\.lockb?)$/;
43
+ // Files that run a command. `.husky/_/` is husky's generated internals, which
44
+ // are gitignored and so never reach this list anyway.
45
+ const EXECUTABLE_FILE =
46
+ /(^\.husky\/[^_/][^/]*$|\.(sh|bash|zsh)$|^\.github\/workflows\/[^/]+\.ya?ml$|(^|\/)action\.ya?ml$|(^|\/)Dockerfile[^/]*$|\.dockerfile$)/;
47
+ const COMMENT_LINE = /^\s*(#|\/\/)/;
48
+ // Mirrors the regex in use-pnpm-scripts.grit. JavaScript has lookahead, so the
49
+ // `npx --no` exception is a negative lookahead here rather than the expanded
50
+ // alternation Rust's regex forces on the plugin.
51
+ const NPM_VERBS =
52
+ "install|i|ci|add|run|run-script|exec|x|test|start|update|uninstall|remove|rm|link|rebuild|prune|dedupe|init|create";
53
+ const FORBIDDEN_INVOCATION = new RegExp(
54
+ String.raw`(?:^|[;&|(]|\bRUN\s+|\brun:\s*)\s*` +
55
+ String.raw`(?:npm[ \t]+(?:${NPM_VERBS})\b|yarn(?=[ \t]|$)|npx(?![ \t]+--no)(?=[ \t]|$))`,
56
+ );
57
+
58
+ const files = git(["ls-files"]).filter(
59
+ (file) => !IGNORED_PREFIXES.some((prefix) => file.startsWith(prefix)),
60
+ );
61
+ const packageManager = readRootPackageManager();
62
+ const lockfileTracked = files.includes("pnpm-lock.yaml");
63
+
64
+ if (!isPnpmRepository()) {
65
+ console.log(
66
+ " ✔ pnpm checks skipped — this repository declares another package manager",
67
+ );
68
+ process.exit(0);
69
+ }
70
+
71
+ const violations = [];
72
+
73
+ for (const file of files.filter((file) => COMPETING_LOCKFILE.test(file))) {
74
+ violations.push(
75
+ `${file}\n Competing lockfile beside pnpm-lock.yaml. Delete it and run \`pnpm install\`.`,
76
+ );
77
+ }
78
+
79
+ if (!lockfileTracked) {
80
+ violations.push(
81
+ "pnpm-lock.yaml\n Not committed. Run `pnpm install` and commit the lockfile.",
82
+ );
83
+ }
84
+
85
+ if (!packageManager?.startsWith("pnpm@")) {
86
+ violations.push(
87
+ 'package.json\n Missing `"packageManager": "pnpm@<version>"`. Pin the package manager so every environment installs with the same one.',
88
+ );
89
+ }
90
+
91
+ const executables = files.filter((file) => EXECUTABLE_FILE.test(file));
92
+ if (executables.length > 0) {
93
+ // `git grep` exits 1 when nothing matches, which is the clean case here — so
94
+ // read stdout off the thrown error rather than letting it propagate. The
95
+ // grep is deliberately coarse, because POSIX ERE has no lookahead; the real
96
+ // policy is applied per line below, so it has one source of truth.
97
+ let matches = "";
98
+ try {
99
+ matches = execFileSync(
100
+ "git",
101
+ ["grep", "-nE", "npm|npx|yarn", "--", ...executables],
102
+ { encoding: "utf8", maxBuffer: 1024 * 1024 * 64 },
103
+ );
104
+ } catch (error) {
105
+ if (error.status !== 1) {
106
+ throw error;
107
+ }
108
+ matches = error.stdout ?? "";
109
+ }
110
+
111
+ for (const match of matches.trim().split("\n").filter(Boolean)) {
112
+ // `git grep -n` prints `file:line:content`. The content has to be split
113
+ // off before matching, or the `^` anchor anchors to the filename.
114
+ const parsed = /^([^:]+):(\d+):(.*)$/.exec(match);
115
+ if (!parsed) {
116
+ continue;
117
+ }
118
+ const content = parsed[3];
119
+ if (COMMENT_LINE.test(content) || !FORBIDDEN_INVOCATION.test(content)) {
120
+ continue;
121
+ }
122
+ violations.push(
123
+ `${match}\n Use pnpm — \`pnpm install\`, \`pnpm add\`, \`pnpm run\`, \`pnpm dlx\`. (\`npx --no -- <bin>\` is the exception: local binary, never fetched.)`,
124
+ );
125
+ }
126
+ }
127
+
128
+ if (violations.length > 0) {
129
+ console.error(`\n ✖ ${violations.length} pnpm violation(s):\n`);
130
+ for (const violation of violations) {
131
+ console.error(` ${violation}\n`);
132
+ }
133
+ process.exit(1);
134
+ }
135
+
136
+ console.log(" ✔ pnpm conventions clean");
137
+
138
+ function isPnpmRepository() {
139
+ if (packageManager?.startsWith("pnpm@")) {
140
+ return true;
141
+ }
142
+ if (packageManager) {
143
+ return false;
144
+ }
145
+ return lockfileTracked;
146
+ }
147
+
148
+ /**
149
+ * Reads `packageManager` from the repository root only. Workspace packages must
150
+ * not declare it, so a nested one is neither read nor required.
151
+ */
152
+ function readRootPackageManager() {
153
+ try {
154
+ return JSON.parse(readFileSync("package.json", "utf8")).packageManager;
155
+ } catch {
156
+ return undefined;
157
+ }
158
+ }
159
+
160
+ function git(args) {
161
+ return execFileSync("git", args, {
162
+ encoding: "utf8",
163
+ maxBuffer: 1024 * 1024 * 64,
164
+ })
165
+ .split("\n")
166
+ .filter(Boolean);
167
+ }
@@ -17,8 +17,10 @@
17
17
  * point rather than a leak:
18
18
  * - Storybook apps, whose whole job is rendering real fixtures, and whose
19
19
  * story helpers are not always named `*.stories.tsx`;
20
- * - `testSupport.ts` barrels, which re-export a package's own
21
- * `test-support/` through a published `"./test-support"` export.
20
+ * - `test-support.ts` barrels, which re-export a package's own
21
+ * `test-support/` through a published `"./test-support"` export. The
22
+ * camelCase spelling is still accepted, because the kebab-case filename
23
+ * rule only reaches code written since it shipped.
22
24
  *
23
25
  * See: .agents/skills/vwala-conventions/references/test-style.md
24
26
  */
@@ -29,7 +31,7 @@ const TEST_FILE = /\.test\.[cm]?[jt]sx?$/;
29
31
  // Matches any Storybook app rather than one repository's name for it.
30
32
  const STORY_FILE =
31
33
  /(\.stories\.[jt]sx?$|\/__stories__\/|^apps\/[^/]*storybook[^/]*\/)/;
32
- const TEST_SUPPORT_BARREL = /(^|\/)testSupport\.[cm]?ts$/;
34
+ const TEST_SUPPORT_BARREL = /(^|\/)(test-support|testSupport)\.[cm]?ts$/;
33
35
 
34
36
  const files = execFileSync("git", ["ls-files"], {
35
37
  encoding: "utf8",
@@ -0,0 +1,109 @@
1
+ // Prefer path aliases (@/, ~/, #) over deep relative imports. Imports that
2
+ // traverse two or more parent directories (../../) should use the project's
3
+ // configured alias instead.
4
+ //
5
+ // A single (../) traversal is allowed — it reaches a sibling folder, which is
6
+ // the shape of a test file importing its own folder's test-support, and where
7
+ // an alias adds little clarity. The governing convention asks for an alias on
8
+ // *any* `../` segment; this rule stops one short of that on purpose, so the
9
+ // common sibling import stays quiet.
10
+ //
11
+ // Configure aliases via one of:
12
+ // - Node.js subpath imports: `"imports": { "#src/*": "./src/*" }` in package.json
13
+ // - TypeScript paths: `"paths": { "@/*": ["./src/*"] }` in tsconfig.json
14
+ // and mirror the mapping in every resolver (bundler, test runner).
15
+ //
16
+ // Only static import/export-from declarations are checked. Dynamic import()
17
+ // expressions are skipped — they often compute the path and would produce
18
+ // false positives.
19
+ //
20
+ // GritQL's `$_` matches a single AST node, so `import $_ from $source`
21
+ // covers default, single-named, and single-type imports but NOT multi-
22
+ // specifier `import { A, B }`. Each arity needs its own branch. Regex
23
+ // matching does not work on `JsModuleSource` nodes, so the regex runs
24
+ // against the full statement text (`$node`), which requires `.*` anchors.
25
+ //
26
+ // Known gap: `export { default as X } from "..."` — the aliased-default
27
+ // re-export form does not match any branch. This is rare enough in practice
28
+ // that the gap is acceptable.
29
+ //
30
+ // Known gap: the regex runs against the whole statement and has no `(?s)`
31
+ // flag, so `.*` cannot cross a newline and a multi-line import is never
32
+ // matched — an import Biome's own formatter wrapped because it had several
33
+ // specifiers goes unreported. Closing it means adding `(?s)` to every branch,
34
+ // which also starts flagging deep imports in published `.mjs` scripts; those
35
+ // run under plain Node, which reads neither tsconfig `paths` nor a bundler
36
+ // alias, so they need a package.json `imports` (`#`) entry before the gap can
37
+ // be closed.
38
+ //
39
+ // See: .agents/skills/vwala-conventions/references/alias-imports.md
40
+ or {
41
+ `import $_ from $source` as $node where {
42
+ $node <: r".*\.\./\.\./.*",
43
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
44
+ },
45
+ `import { $a, $b } from $source` as $node where {
46
+ $node <: r".*\.\./\.\./.*",
47
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
48
+ },
49
+ `import { $a, $b, $c } from $source` as $node where {
50
+ $node <: r".*\.\./\.\./.*",
51
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
52
+ },
53
+ `import { $a, $b, $c, $d } from $source` as $node where {
54
+ $node <: r".*\.\./\.\./.*",
55
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
56
+ },
57
+ `import { $a, $b, $c, $d, $e } from $source` as $node where {
58
+ $node <: r".*\.\./\.\./.*",
59
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
60
+ },
61
+ `import type { $a, $b } from $source` as $node where {
62
+ $node <: r".*\.\./\.\./.*",
63
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
64
+ },
65
+ `import type { $a, $b, $c } from $source` as $node where {
66
+ $node <: r".*\.\./\.\./.*",
67
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
68
+ },
69
+ `import type { $a, $b, $c, $d } from $source` as $node where {
70
+ $node <: r".*\.\./\.\./.*",
71
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
72
+ },
73
+ `import type { $a, $b, $c, $d, $e } from $source` as $node where {
74
+ $node <: r".*\.\./\.\./.*",
75
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
76
+ },
77
+ `import * as $_ from $source` as $node where {
78
+ $node <: r".*\.\./\.\./.*",
79
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
80
+ },
81
+ `export { $a } from $source` as $node where {
82
+ $node <: r".*\.\./\.\./.*",
83
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
84
+ },
85
+ `export { $a, $b } from $source` as $node where {
86
+ $node <: r".*\.\./\.\./.*",
87
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
88
+ },
89
+ `export { $a, $b, $c } from $source` as $node where {
90
+ $node <: r".*\.\./\.\./.*",
91
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
92
+ },
93
+ `export type { $a } from $source` as $node where {
94
+ $node <: r".*\.\./\.\./.*",
95
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
96
+ },
97
+ `export type { $a, $b } from $source` as $node where {
98
+ $node <: r".*\.\./\.\./.*",
99
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
100
+ },
101
+ `export type { $a, $b, $c } from $source` as $node where {
102
+ $node <: r".*\.\./\.\./.*",
103
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
104
+ },
105
+ `export * from $source` as $node where {
106
+ $node <: r".*\.\./\.\./.*",
107
+ register_diagnostic(span=$source, message="Use a path alias instead of a deep relative import. Configure aliases via tsconfig `paths` or the package.json `imports` field.", severity="warn")
108
+ }
109
+ }