@r_masseater/msch 0.8.0 → 0.10.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.mjs CHANGED
@@ -1,11 +1,20 @@
1
1
  #!/usr/bin/env node
2
- import { $ as isTypeAliasDeclaration, A as getTextOfJSDocComment, B as isInterfaceDeclaration, C as API, D as getJSDocTags, E as SyntaxKind, F as isElementAccessExpression, G as isObjectLiteralExpression, H as isModuleDeclaration, I as isEnumDeclaration, J as isSatisfiesExpression, K as isPropertyAccessExpression, L as isExportDeclaration, M as isBinaryExpression, N as isCallExpression, O as getLeadingCommentRanges, P as isClassDeclaration, Q as isStringLiteral, R as isIdentifier, S as uniqueByReference, T as InternalSymbolName, U as isNewExpression, V as isModuleBlock, W as isNumericLiteral, X as isSourceFile, Y as isSignatureDeclaration, Z as isSpreadElement, _ as lineOf, a as problemAt, at as isVariableStatement, b as resolvedSymbol, c as childrenOf$1, d as declarationsOf, et as isTypeLiteralNode, f as descendantsOf, g as isTypeDeclaration, h as isGenericDeclaration, i as formatProblem, it as isVariableDeclarationList, j as isArrayLiteralExpression, k as getNameOfDeclaration, l as columnOf, m as isExternalDeclaration, n as ProblemList, nt as isUnionTypeNode, o as sortProblems, p as importedModulesOf, q as isPropertyAssignment, rt as isVariableDeclaration, s as NODE_MODULES_SEGMENT, tt as isTypeReferenceNode, u as contains, v as propertyNamesOf, w as IndexKind, x as symbolAt, y as referencedSymbols, z as isImportDeclaration } from "./cli-contract-BvrxbrIy.mjs";
2
+ import { $ as isTypeAliasDeclaration, A as getTextOfJSDocComment, B as isInterfaceDeclaration, C as API, D as getJSDocTags, E as SyntaxKind, F as isElementAccessExpression, G as isObjectLiteralExpression, H as isModuleDeclaration, I as isEnumDeclaration, J as isSatisfiesExpression, K as isPropertyAccessExpression, L as isExportDeclaration, M as isBinaryExpression, N as isCallExpression, O as getLeadingCommentRanges, P as isClassDeclaration, Q as isStringLiteral, R as isIdentifier, S as uniqueByReference, T as InternalSymbolName, U as isNewExpression, V as isModuleBlock, W as isNumericLiteral, X as isSourceFile, Y as isSignatureDeclaration, Z as isSpreadElement, _ as lineOf, a as problemAt, at as isVariableStatement, b as resolvedSymbol, c as childrenOf$2, d as declarationsOf, et as isTypeLiteralNode, f as descendantsOf, g as isTypeDeclaration, h as isGenericDeclaration, i as formatProblem, it as isVariableDeclarationList, j as isArrayLiteralExpression, k as getNameOfDeclaration, l as columnOf, m as isExternalDeclaration, n as ProblemList, nt as isUnionTypeNode, o as sortProblems, p as importedModulesOf, q as isPropertyAssignment, rt as isVariableDeclaration, s as NODE_MODULES_SEGMENT, tt as isTypeReferenceNode, u as contains, v as propertyNamesOf, w as IndexKind, x as symbolAt, y as referencedSymbols, z as isImportDeclaration } from "./cli-contract-ChzTJ0Na.mjs";
3
3
  import { a as workspaceDependencies, c as nodeServicesLayer, i as readManifest, n as NODE_MODULES, o as RepositoryFiles, r as dependencyEntries, s as nodeRepositoryFiles, t as MANIFEST_FILE } from "./dependencies-x3j9tLcR.mjs";
4
- import { _ as publishedWorkspaces, c as programOf, d as childrenOf$2, i as hasVerifyTask, m as workspaceDirectories, n as VERIFY_TASK, r as definesTask, v as publicEntriesOf } from "./workspace-tasks-CRL-gm__.mjs";
5
- import { Array, Cause, Effect, FileSystem, Function, HashMap, HashSet, Layer, Number as Number$1, Option, Order, Path, Record, Result, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
4
+ import { _ as publishedWorkspaces, c as programOf, d as childrenOf$3, i as hasVerifyTask, m as workspaceDirectories, n as VERIFY_TASK, r as definesTask, v as publicEntriesOf } from "./workspace-tasks-CRL-gm__.mjs";
5
+ import { t as COMMENT_DIRECTIVES } from "./comment-directives-DApQXgQf.mjs";
6
+ import { Array, Cause, Effect, FileSystem, Function, HashMap, HashSet, Layer, Number as Number$1, Option, Order, Path, Predicate, Record, Result, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
6
7
  import { ChildProcess } from "effect/process";
7
8
  import { parse, resolveConfigFromFile } from "vite-plus";
8
- import { LineCounter, isMap, isScalar, parseAllDocuments, parseDocument } from "yaml";
9
+ import { LineCounter, Parser, isMap, isScalar, parseAllDocuments, parseDocument } from "yaml";
10
+ import path from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ import treeSitter from "@vscode/tree-sitter-wasm";
13
+ import { isComment, isTag, isText } from "domhandler";
14
+ import { DomUtils, parseDocument as parseDocument$1 } from "htmlparser2";
15
+ import { DockerfileParser } from "dockerfile-ast";
16
+ import { parse as parse$2 } from "sql-parser-cst";
17
+ import { parseTOML } from "toml-eslint-parser";
9
18
  import { runMain } from "@effect/platform-node-shared/NodeRuntime";
10
19
  import { FetchHttpClient } from "effect/http";
11
20
  import { Otlp, OtlpSerialization } from "effect/observability";
@@ -158,7 +167,7 @@ const scanned = (owners, problems) => ({
158
167
  owners,
159
168
  problems
160
169
  });
161
- const ownerOf = (project) => (annotated) => {
170
+ const ownerOf$1 = (project) => (annotated) => {
162
171
  const { node, conceptId } = annotated;
163
172
  if (!isModuleConst(node)) return scanned([], [annotationProblem(`@${OWNER_TAG} registers an owner only on a module-scope const.`)(node)]);
164
173
  if (conceptId === "") return scanned([], [annotationProblem(`@${OWNER_TAG} needs a concept id.`)(node)]);
@@ -192,7 +201,7 @@ const conflictProblems = (owners) => pipe(owners, Array.flatMap((owner, index) =
192
201
  return [...pipe(Array.take(sameConcept, FIRST_OWNER_COUNT), Array.map(() => ownerProblem(`The concept ${owner.conceptId} already has an owner.`)(owner))), ...pipe(Array.take(sameSet, FIRST_OWNER_COUNT), Array.map((other) => ownerProblem(`The values ${formatValues(owner.values)} are already owned by ${other.conceptId}.`)(owner)))];
193
202
  }));
194
203
  const ownersIn = (project) => {
195
- const results = pipe(project.sourceFiles, Array.flatMap((sourceFile) => pipe(annotatedIn(sourceFile), Array.map((annotated) => ownerOf(project)(annotated)))));
204
+ const results = pipe(project.sourceFiles, Array.flatMap((sourceFile) => pipe(annotatedIn(sourceFile), Array.map((annotated) => ownerOf$1(project)(annotated)))));
196
205
  return scanned(pipe(results, Array.flatMap((result) => result.owners)), pipe(results, Array.flatMap((result) => result.problems)));
197
206
  };
198
207
  const combineOwnerScans = (scans) => {
@@ -458,7 +467,7 @@ const derivationScopeOf = (node) => {
458
467
  };
459
468
  const sourcesOf = (checker) => (node) => pipe(referencedSymbols(checker)(derivationScopeOf(node)), Array.filter((symbol) => Option.isSome(namedValuesOf(checker)(symbol))));
460
469
  const sitesUnder = (checker) => (node) => {
461
- const nested = pipe(childrenOf$1(node), Array.flatMap((child) => sitesUnder(checker)(child)));
470
+ const nested = pipe(childrenOf$2(node), Array.flatMap((child) => sitesUnder(checker)(child)));
462
471
  if (Array.isReadonlyArrayNonEmpty(nested)) return nested;
463
472
  return siteValuesOf(checker)(node).pipe(Option.map((values) => ({
464
473
  node,
@@ -790,54 +799,6 @@ const checkRepository = Effect.fn("checkRepository")(function* checkRepository(r
790
799
  ...duplicateProblems(relative)(unowned)
791
800
  ]);
792
801
  }, Effect.scoped);
793
- // src/text-position.ts
794
- const START$3 = 0;
795
- const FIRST_COLUMN$1 = 1;
796
- const positionOf = (source) => (index) => {
797
- const before = pipe(source, String$1.slice(START$3, index), String$1.split("\n"));
798
- return {
799
- line: before.length,
800
- column: pipe(Array.last(before), Option.match({
801
- onNone: () => FIRST_COLUMN$1,
802
- onSome: (last) => last.length + FIRST_COLUMN$1
803
- }))
804
- };
805
- };
806
- // src/hidden-unicode.ts
807
- const HIDDEN = /[\u00AD\u180E\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]|[\u{E0000}-\u{E007F}]/gu;
808
- const NUL = "\0";
809
- const START$2 = 0;
810
- const HEX = 16;
811
- const CODE_POINT_WIDTH = 4;
812
- const READ_CONCURRENCY$5 = 64;
813
- const RULE$5 = "hidden-unicode";
814
- const hexOf = (character) => pipe(String$1.codePointAt(START$2)(character), Option.getOrElse(() => START$2), (code) => code.toString(HEX), String$1.toUpperCase, String$1.padStart(CODE_POINT_WIDTH, "0"));
815
- const problemOf = (file, source) => (found) => {
816
- const hex = hexOf(found[START$2]);
817
- return {
818
- file,
819
- ...positionOf(source)(found.index ?? START$2),
820
- rule: RULE$5,
821
- message: `U+${hex} is invisible in editors and reviews and can change what the text means. Remove it, or write it as the escape \\u${hex}.`
822
- };
823
- };
824
- const problemsIn$2 = (file, source) => {
825
- if (String$1.includes(NUL)(source)) return [];
826
- return pipe(Array.fromIterable(String$1.matchAll(HIDDEN)(source)), Array.map(problemOf(file, source)));
827
- };
828
- /** @internal */
829
- const checkHiddenUnicode = Effect.fn("checkHiddenUnicode")(function* checkHiddenUnicode(root) {
830
- const files = yield* RepositoryFiles;
831
- const names = yield* files.listedFiles(root);
832
- const found = yield* Effect.forEach(names, (name) => {
833
- const file = files.join(root, name);
834
- return files.readFile(file).pipe(Effect.map(Option.match({
835
- onNone: () => [],
836
- onSome: (source) => problemsIn$2(file, source)
837
- })));
838
- }, { concurrency: READ_CONCURRENCY$5 });
839
- return Array.flatten(found);
840
- });
841
802
  // src/import-graph.ts
842
803
  const RELATIVE = /^\.\.?(?:\/|$)/u;
843
804
  const SUBPATH_IMPORT = "#";
@@ -952,7 +913,7 @@ const InstalledManifest = Schema.Struct({
952
913
  peerDependencies: DependencyMap,
953
914
  peerDependenciesMeta: PeerMeta
954
915
  });
955
- const decodeManifest = Schema.decodeOption(Schema.fromJsonString(InstalledManifest));
916
+ const decodeManifest$1 = Schema.decodeOption(Schema.fromJsonString(InstalledManifest));
956
917
  const keysOf$1 = (map) => pipe(Option.fromUndefinedOr(map), Option.map(Record.keys), Option.getOrElse(() => []));
957
918
  const isOptionalPeer = (manifest, name) => pipe(Option.fromUndefinedOr(manifest.peerDependenciesMeta), Option.flatMap(Record.get(name)), Option.exists((meta) => meta.optional === true));
958
919
  const installedNames = (manifest) => [
@@ -960,10 +921,10 @@ const installedNames = (manifest) => [
960
921
  ...keysOf$1(manifest.optionalDependencies),
961
922
  ...pipe(keysOf$1(manifest.peerDependencies), Array.filter((name) => !isOptionalPeer(manifest, name)))
962
923
  ];
963
- const childrenOf = Effect.fn("childrenOf")(function* childrenOf(directory) {
924
+ const childrenOf$1 = Effect.fn("childrenOf")(function* childrenOf(directory) {
964
925
  const files = yield* RepositoryFiles;
965
926
  const text = yield* files.readFile(files.join(directory, MANIFEST_FILE));
966
- return pipe(text, Option.flatMap(decodeManifest), Option.map(installedNames), Option.getOrElse(() => []), Array.map((child) => [directory, child]));
927
+ return pipe(text, Option.flatMap(decodeManifest$1), Option.map(installedNames), Option.getOrElse(() => []), Array.map((child) => [directory, child]));
967
928
  });
968
929
  const resolveFrom = (from, name) => Effect.gen(function* resolvePackage() {
969
930
  const files = yield* RepositoryFiles;
@@ -989,7 +950,7 @@ const closureOf = (provided, collect) => Array.match(collect.pending, {
989
950
  ...collect,
990
951
  pending: rest
991
952
  });
992
- return childrenOf(resolved.value).pipe(Effect.flatMap((children) => closureOf(provided, {
953
+ return childrenOf$1(resolved.value).pipe(Effect.flatMap((children) => closureOf(provided, {
993
954
  pending: [...rest, ...children],
994
955
  seen: HashSet.add(collect.seen, resolved.value)
995
956
  })));
@@ -1015,6 +976,19 @@ const installedSize = (directory) => {
1015
976
  if (String$1.includes(`/node_modules/`)(directory)) return directorySize(directory);
1016
977
  return Effect.succeed(EMPTY);
1017
978
  };
979
+ // src/text-position.ts
980
+ const START$5 = 0;
981
+ const FIRST_COLUMN$2 = 1;
982
+ const positionOf = (source) => (index) => {
983
+ const before = pipe(source, String$1.slice(START$5, index), String$1.split("\n"));
984
+ return {
985
+ line: before.length,
986
+ column: pipe(Array.last(before), Option.match({
987
+ onNone: () => FIRST_COLUMN$2,
988
+ onSome: (last) => last.length + FIRST_COLUMN$2
989
+ }))
990
+ };
991
+ };
1018
992
  // src/install-size.ts
1019
993
  const INSTALL_SIZE = "install-size";
1020
994
  const STACK_DEPENDENCY = "stack-dependency";
@@ -1025,11 +999,11 @@ const LISTED_LARGEST = 5;
1025
999
  const SIZE_CONCURRENCY = 32;
1026
1000
  const MEGABYTE = 1e6;
1027
1001
  const MEGABYTE_DIGITS = 1;
1028
- const START$1 = 0;
1002
+ const START$4 = 0;
1029
1003
  const SINGLE_ENTRY = 1;
1030
1004
  const megabytes = (bytes) => `${(bytes / MEGABYTE).toFixed(MEGABYTE_DIGITS)} MB`;
1031
1005
  const usageHint = (dependency, entryCount) => {
1032
- if (!(entryCount > SINGLE_ENTRY && dependency.entries.length > START$1 && dependency.entries.length < entryCount)) return "";
1006
+ if (!(entryCount > SINGLE_ENTRY && dependency.entries.length > START$4 && dependency.entries.length < entryCount)) return "";
1033
1007
  return ` (imported only from ${Array.join(dependency.entries, ", ")})`;
1034
1008
  };
1035
1009
  const listed = ({ largest, entryCount }) => pipe(largest, Array.map((dependency) => `${dependency.name} ${megabytes(dependency.size)}${usageHint(dependency, entryCount)}`), Array.join(", "));
@@ -1038,7 +1012,7 @@ const budgetProblem = Effect.fn("budgetProblem")(function* budgetProblem(overrun
1038
1012
  const { workspace, total } = overrun;
1039
1013
  const config = yield* files.readFile(workspace.configFile);
1040
1014
  const source = Option.getOrElse(config, () => "");
1041
- const index = Option.getOrElse(String$1.indexOf(BUDGET_KEY)(source), () => START$1);
1015
+ const index = Option.getOrElse(String$1.indexOf(BUDGET_KEY)(source), () => START$4);
1042
1016
  return {
1043
1017
  file: workspace.configFile,
1044
1018
  ...positionOf(source)(index),
@@ -1055,7 +1029,7 @@ const measure = Effect.fn("measure")(function* measure({ workspace, provided },
1055
1029
  const everything = pipe(closures, Array.flatMap(([, packages]) => Array.fromIterable(packages)), HashSet.fromIterable);
1056
1030
  const measured = yield* Effect.forEach(everything, (found) => installedSize(found).pipe(Effect.map((size) => [found, size])), { concurrency: SIZE_CONCURRENCY });
1057
1031
  const sizes = HashMap.fromIterable(measured);
1058
- const sizeOf = (packages) => Number$1.sumAll(pipe(Array.fromIterable(packages), Array.map((found) => Option.getOrElse(HashMap.get(sizes, found), () => START$1))));
1032
+ const sizeOf = (packages) => Number$1.sumAll(pipe(Array.fromIterable(packages), Array.map((found) => Option.getOrElse(HashMap.get(sizes, found), () => START$4))));
1059
1033
  return {
1060
1034
  closures,
1061
1035
  sizeOf,
@@ -1088,11 +1062,11 @@ const sizeProblems = Effect.fn("sizeProblems")(function* sizeProblems(published,
1088
1062
  })];
1089
1063
  });
1090
1064
  const stackProblems = (file, source, dependencies) => {
1091
- const section = Option.getOrElse(String$1.indexOf(DEPENDENCIES_KEY)(source), () => START$1);
1065
+ const section = Option.getOrElse(String$1.indexOf(DEPENDENCIES_KEY)(source), () => START$4);
1092
1066
  const rest = String$1.slice(section)(source);
1093
1067
  return pipe(Record.toEntries(dependencies), Array.filter(([, specifier]) => specifier === STACK_CATALOG), Array.map(([name]) => ({
1094
1068
  file,
1095
- ...positionOf(source)(section + Option.getOrElse(String$1.indexOf(`"${name}"`)(rest), () => START$1)),
1069
+ ...positionOf(source)(section + Option.getOrElse(String$1.indexOf(`"${name}"`)(rest), () => START$4)),
1096
1070
  rule: STACK_DEPENDENCY,
1097
1071
  message: `${name} comes from the stack catalog, so every project that installs this package already has it. Move it to peerDependencies and keep it in devDependencies, so the installing project shares one copy.`
1098
1072
  })));
@@ -1137,72 +1111,6 @@ const checkPublishedPackages = Effect.fn("checkPublishedPackages")(function* che
1137
1111
  const found = yield* pipe(workspaces, Effect.forEach(workspaceProblems));
1138
1112
  return Array.flatten(found);
1139
1113
  });
1140
- // src/nested-docs.ts
1141
- const RULE$4 = "nested-docs";
1142
- const CONFIG_FILE$3 = "vite.config.ts";
1143
- const SEPARATOR$2 = "/";
1144
- const FIRST$3 = 1;
1145
- const READ_CONCURRENCY$4 = 64;
1146
- const AGENT_DOCS = /^(?:AGENTS|CLAUDE)(?:\.[^/]+)?\.md$/iu;
1147
- const WORKSPACE_AGENT_DOC = "AGENTS.md";
1148
- const README$1 = /^README(?:\.[^/]+)?$/iu;
1149
- const RootConfig = Schema.Struct({ msch: Schema.Struct({ workspaceAgentsMd: Schema.Literal(true) }) });
1150
- const taggedError$2 = Schema.TaggedError;
1151
- var RootConfigUnreadable = class extends taggedError$2()("RootConfigUnreadable", { file: Schema.String }) {};
1152
- const isNested = (name) => String$1.includes(SEPARATOR$2)(name);
1153
- const problemFor$1 = (file, message) => ({
1154
- file,
1155
- line: FIRST$3,
1156
- column: FIRST$3,
1157
- rule: RULE$4,
1158
- message
1159
- });
1160
- const AGENT_DOCS_MESSAGE = "belongs only at the repository root. Move what agents need into the root AGENTS.md and delete this file.";
1161
- const WORKSPACE_AGENT_DOCS_MESSAGE = "belongs only at the repository root or as AGENTS.md directly in a workspace, the directory that holds its package.json. Move what agents need there and delete this file.";
1162
- const README_MESSAGE = "is allowed below the root only in a workspace, the directory that holds its package.json. Move it into the workspace it describes.";
1163
- const agentDocProblem = ({ file, base, directory }, allowed) => {
1164
- if (!allowed.workspaceAgentDocs) return Option.some(problemFor$1(file, `${base} ${AGENT_DOCS_MESSAGE}`));
1165
- if (base === WORKSPACE_AGENT_DOC && HashSet.has(allowed.workspaces, directory)) return Option.none();
1166
- return Option.some(problemFor$1(file, `${base} ${WORKSPACE_AGENT_DOCS_MESSAGE}`));
1167
- };
1168
- const readmeProblem = ({ file, base, directory }, allowed) => {
1169
- if (!README$1.test(base) || HashSet.has(allowed.workspaces, directory)) return Option.none();
1170
- return Option.some(problemFor$1(file, `${base} ${README_MESSAGE}`));
1171
- };
1172
- const problemIn$2 = Effect.fn("problemIn")(function* problemIn(root, allowed, name) {
1173
- const files = yield* RepositoryFiles;
1174
- const file = files.join(root, name);
1175
- const doc = {
1176
- file,
1177
- base: files.basename(name),
1178
- directory: files.dirname(file)
1179
- };
1180
- if (AGENT_DOCS.test(doc.base)) return agentDocProblem(doc, allowed);
1181
- return readmeProblem(doc, allowed);
1182
- });
1183
- const allowsWorkspaceAgentDocs = Effect.fn("allowsWorkspaceAgentDocs")(function* allowsWorkspaceAgentDocs(root) {
1184
- const files = yield* RepositoryFiles;
1185
- const file = files.join(root, CONFIG_FILE$3);
1186
- if (!(yield* files.exists(file))) return false;
1187
- const config = yield* Effect.tryPromise({
1188
- try: () => resolveConfigFromFile(file),
1189
- catch: () => RootConfigUnreadable.make({ file })
1190
- }).pipe(Effect.option);
1191
- return pipe(config, Option.flatMap(Schema.decodeUnknownOption(RootConfig)), Option.isSome);
1192
- });
1193
- /** @internal */
1194
- const checkNestedDocs = Effect.fn("checkNestedDocs")(function* checkNestedDocs(root) {
1195
- const files = yield* RepositoryFiles;
1196
- const names = yield* files.listedFiles(root);
1197
- const nested = pipe(names, Array.filter(isNested));
1198
- const workspaceAgentDocs = yield* allowsWorkspaceAgentDocs(root);
1199
- const allowed = {
1200
- workspaces: pipe(nested, Array.filter((name) => files.basename(name) === MANIFEST_FILE), Array.map((name) => files.dirname(files.join(root, name))), HashSet.fromIterable),
1201
- workspaceAgentDocs
1202
- };
1203
- const found = yield* Effect.forEach(nested, (name) => problemIn$2(root, allowed, name), { concurrency: READ_CONCURRENCY$4 });
1204
- return Array.getSomes(found);
1205
- });
1206
1114
  // src/override-findings.ts
1207
1115
  const describeVersions = (versions) => Option.getOrElse(Option.liftPredicate(Array.join(versions, ","), (joined) => joined !== ""), () => "-");
1208
1116
  const describeChanges = (report) => {
@@ -1394,8 +1302,8 @@ const RESOLUTION_FILES = [
1394
1302
  ];
1395
1303
  const RESOLUTION_CONCURRENCY = 4;
1396
1304
  const SUCCEEDED = 0;
1397
- const taggedError$1 = Schema.TaggedError;
1398
- var OverrideResolutionFailed = class extends taggedError$1()("OverrideResolutionFailed", {
1305
+ const taggedError$4 = Schema.TaggedError;
1306
+ var OverrideResolutionFailed = class extends taggedError$4()("OverrideResolutionFailed", {
1399
1307
  override: Schema.String,
1400
1308
  output: Schema.String
1401
1309
  }) {};
@@ -1497,73 +1405,173 @@ const checkOverrides = Effect.fn("checkOverrides")(function* checkOverrides(root
1497
1405
  if (Option.isNone(manifest) || !Array.isReadonlyArrayNonEmpty(keys)) return [];
1498
1406
  return yield* problemsFor(root, manifest.value, keys);
1499
1407
  });
1500
- // src/python.ts
1501
- const PYTHON_FILE = /(?:\.(?:py|pyi|pyw|pyx|ipynb)|(?:^|\/)(?:pyproject\.toml|uv\.lock|uv\.toml|poetry\.lock|Pipfile|Pipfile\.lock|setup\.cfg|tox\.ini|pytest\.ini|\.python-version|requirements[^/]*\.txt))$/u;
1502
- const SCANNED_FILE = /(?:\.(?:[cm]?[jt]sx?|jsonc?|toml|ya?ml|sh|bash|zsh|fish|rs|cs|go|mk)|(?:^|\/)(?:Dockerfile[^/]*|Makefile|justfile|\.tool-versions|[^./][^./]*))$/u;
1503
- const LOCKFILE = /(?:^|\/)(?:[^/]*\.lock|[^/]*-lock\.(?:json|ya?ml))$/u;
1504
- const TOOL_VERSIONS = /(?:^|\/)(?:\.?mise(?:\.[^/]+)?\.toml|\.tool-versions)$/u;
1505
- const COMMAND_PATTERNS = [
1506
- /(?<![\w./@-])python[\d.]*[ \t]+(?:[-"'$./]|\S+\.py\b)/gu,
1507
- /(?<![\w./@-])pip3?[ \t]+(?:install|uninstall|download|freeze|wheel|compile|sync)\b/gu,
1508
- /(?<![\w./@-])pipx[ \t]+(?:run|install|inject|upgrade)\b/gu,
1509
- /(?<![\w./@-])uvx[ \t]+[^\s=:,;)|&]/gu,
1510
- /(?<![\w./@-])uv[ \t]+(?:run|sync|lock|pip|tool|venv|add|remove|python|export|build|publish|init|tree|cache|self)\b/gu,
1511
- /(?<![\w./@-])poetry[ \t]+(?:run|install|add|lock|build|publish|shell|export)\b/gu,
1512
- /(?:\bcommand["']?\s*[:=]\s*|(?:\bspawn\w*|\bexec\w*|\bexeca|Command::new|ChildProcess\.make|\$)\(\s*)["'`](?:python[\d.]*|pip3?|pipx|uvx?|poetry)["'`]/gu,
1513
- /\buses:\s*["']?(?:actions\/setup-python|astral-sh\/setup-uv|astral-sh\/ruff-action|pypa\/[\w.-]+|snok\/install-poetry|abatilo\/actions-poetry|conda-incubator\/setup-miniconda|mamba-org\/setup-micromamba|pdm-project\/setup-pdm)\b/gu
1514
- ];
1515
- const TOOL_PATTERNS = [/^[ \t]*["']?(?:python|uv|pipx|poetry|ruff|pdm|hatch|pipx:[^"'\s=]+)["']?[ \t]*(?:=|[ \t]+\S)/gmu];
1516
- const READ_CONCURRENCY$3 = 64;
1517
- const FIRST_LINE = 1;
1518
- const FIRST_COLUMN = 1;
1519
- const WHOLE_MATCH = 0;
1520
- const FILE_RULE = "python-file";
1521
- const COMMAND_RULE = "python-command";
1522
- const fileProblem = ({ file }) => ({
1408
+ // src/colocated-tests.ts
1409
+ const RULE$7 = "colocated-test";
1410
+ const FIRST$4 = 1;
1411
+ const READ_CONCURRENCY$7 = 64;
1412
+ const ROOT_SUBPATH = ".";
1413
+ const NAME_GROUP = "name";
1414
+ const SPECIFIER_GROUP = "specifier";
1415
+ const SCRIPT = /\.[cm]?[jt]sx?$/u;
1416
+ const TEST_FILE = /\.test\.[cm]?[jt]sx?$/u;
1417
+ const MANIFEST_NAME = /package\.json$/u;
1418
+ const SEPARATE_TEST_DIRECTORY = /(?:^|\/)(?:__tests__|__mocks__|tests?|specs?)\//u;
1419
+ const RELATIVE_REFERENCE = /["'`]\.\/(?<name>[^/"'`]+)/gu;
1420
+ const DIRNAME_REFERENCE = /import\.meta\.dirname\s*,\s*["'](?<name>[^/"']+)["']/gu;
1421
+ const MODULE_SPECIFIER = /(?:\bfrom\s+|\bimport\s*\(\s*|\bimport\s+|\bvi\.mock\(\s*)["'](?<specifier>[^"'.#][^"']*)["']/gu;
1422
+ const EXCLUDED = [":(exclude,attr:linguist-vendored)", ":(exclude,attr:linguist-generated)"];
1423
+ const DIRECTORY_MESSAGE = "sits in a separate test directory. Put each test next to the module it tests, and test-only helpers next to the tests as <name>.test.support.ts.";
1424
+ const SIBLING_MESSAGE = "refers to nothing in its own directory. Move the test next to the module it tests and import that module, or a helper beside it, with ./<name>.";
1425
+ const Manifest = Schema.Struct({
1426
+ name: Schema.optional(Schema.String),
1427
+ exports: Schema.optional(Schema.Unknown)
1428
+ });
1429
+ const decodeManifest = Schema.decodeUnknownOption(Schema.fromJsonString(Manifest));
1430
+ const byLength = Order.mapInput(Order.Number, (directory) => directory.length);
1431
+ const problemFor$2 = (test, message) => ({
1432
+ file: test.file,
1433
+ line: FIRST$4,
1434
+ column: FIRST$4,
1435
+ rule: RULE$7,
1436
+ message: `${test.base} ${message}`
1437
+ });
1438
+ const groupsOf = (source, pattern, group) => pipe(Array.fromIterable(String$1.matchAll(pattern)(source)), Array.map((match) => pipe(Option.fromUndefinedOr(match.groups), Option.flatMap((groups) => Option.fromUndefinedOr(groups[group])))), Array.getSomes);
1439
+ const namesSibling = (source) => pipe([...groupsOf(source, RELATIVE_REFERENCE, NAME_GROUP), ...groupsOf(source, DIRNAME_REFERENCE, NAME_GROUP)], Array.some((name) => !TEST_FILE.test(name)));
1440
+ const ownerOf = (packages, name) => {
1441
+ const owners = pipe(packages, Array.filter((directory) => String$1.startsWith(directory)(name)));
1442
+ return Array.last(Array.sort(owners, byLength));
1443
+ };
1444
+ const specifiersBeside = ({ join, dirname, directory }) => (manifest) => pipe(Option.fromUndefinedOr(manifest.name), Option.map((name) => pipe(publicEntriesOf({
1445
+ manifest,
1446
+ join,
1447
+ packEntries: []
1448
+ }), Array.filter(({ source }) => dirname(source) === directory), Array.map(({ label }) => String$1.replace(ROOT_SUBPATH, name)(label)))), Option.getOrElse(() => []));
1449
+ const ownSpecifiers = Effect.fn("ownSpecifiers")(function* ownSpecifiers(context, test) {
1450
+ const files = yield* RepositoryFiles;
1451
+ const owner = ownerOf(context.packages, test.name);
1452
+ if (Option.isNone(owner)) return [];
1453
+ const text = yield* files.readFile(files.join(context.root, owner.value, MANIFEST_FILE));
1454
+ const join = (target) => files.join(context.root, owner.value, target);
1455
+ return pipe(text, Option.flatMap(decodeManifest), Option.map(specifiersBeside({
1456
+ join,
1457
+ dirname: files.dirname,
1458
+ directory: test.directory
1459
+ })), Option.getOrElse(() => []));
1460
+ });
1461
+ const refersToOwnDirectory = Effect.fn("refersToOwnDirectory")(function* refersToOwnDirectory(context, test, source) {
1462
+ if (namesSibling(source)) return true;
1463
+ const specifiers = groupsOf(source, MODULE_SPECIFIER, SPECIFIER_GROUP);
1464
+ if (Array.isReadonlyArrayEmpty(specifiers)) return false;
1465
+ const own = yield* ownSpecifiers(context, test);
1466
+ return pipe(specifiers, Array.some((specifier) => pipe(own, Array.contains(specifier))));
1467
+ });
1468
+ const refersIn = Effect.fn("refersIn")(function* refersIn(context, test) {
1469
+ const source = yield* (yield* RepositoryFiles).readFile(test.file);
1470
+ if (Option.isNone(source)) return true;
1471
+ return yield* refersToOwnDirectory(context, test, source.value);
1472
+ });
1473
+ const problemIn$3 = Effect.fn("problemIn")(function* problemIn(context, test) {
1474
+ if (SEPARATE_TEST_DIRECTORY.test(test.name)) return Option.some(problemFor$2(test, DIRECTORY_MESSAGE));
1475
+ if (!TEST_FILE.test(test.name)) return Option.none();
1476
+ if (yield* refersIn(context, test)) return Option.none();
1477
+ return Option.some(problemFor$2(test, SIBLING_MESSAGE));
1478
+ });
1479
+ /** @internal */
1480
+ const checkColocatedTests = Effect.fn("checkColocatedTests")(function* checkColocatedTests(root) {
1481
+ const files = yield* RepositoryFiles;
1482
+ const listed = yield* files.matchingFiles(root, EXCLUDED);
1483
+ const names = pipe(listed, Array.filter(String$1.isNonEmpty));
1484
+ const context = {
1485
+ root,
1486
+ packages: pipe(names, Array.filter((name) => files.basename(name) === MANIFEST_FILE), Array.map(String$1.replace(MANIFEST_NAME, "")))
1487
+ };
1488
+ const tests = pipe(names, Array.filter((name) => SCRIPT.test(name)), Array.map((name) => {
1489
+ const file = files.join(root, name);
1490
+ return {
1491
+ name,
1492
+ base: files.basename(name),
1493
+ file,
1494
+ directory: files.dirname(file)
1495
+ };
1496
+ }));
1497
+ const found = yield* Effect.forEach(tests, (test) => problemIn$3(context, test), { concurrency: READ_CONCURRENCY$7 });
1498
+ return Array.getSomes(found);
1499
+ });
1500
+ // src/nested-docs.ts
1501
+ const RULE$6 = "nested-docs";
1502
+ const CONFIG_FILE$4 = "vite.config.ts";
1503
+ const SEPARATOR$2 = "/";
1504
+ const FIRST$3 = 1;
1505
+ const READ_CONCURRENCY$6 = 64;
1506
+ const AGENT_DOCS = /^(?:AGENTS|CLAUDE)(?:\.[^/]+)?\.md$/iu;
1507
+ const WORKSPACE_AGENT_DOC = "AGENTS.md";
1508
+ const README$1 = /^README(?:\.[^/]+)?$/iu;
1509
+ const RootConfig$1 = Schema.Struct({ msch: Schema.Struct({ workspaceAgentsMd: Schema.Literal(true) }) });
1510
+ const taggedError$3 = Schema.TaggedError;
1511
+ var RootConfigUnreadable = class extends taggedError$3()("RootConfigUnreadable", { file: Schema.String }) {};
1512
+ const isNested = (name) => String$1.includes(SEPARATOR$2)(name);
1513
+ const problemFor$1 = (file, message) => ({
1523
1514
  file,
1524
- line: FIRST_LINE,
1525
- column: FIRST_COLUMN,
1526
- rule: FILE_RULE,
1527
- message: "Python is not used in this repository. Replace this file with TypeScript or Rust."
1515
+ line: FIRST$3,
1516
+ column: FIRST$3,
1517
+ rule: RULE$6,
1518
+ message
1528
1519
  });
1529
- const patternsFor = (name) => {
1530
- if (TOOL_VERSIONS.test(name)) return [...COMMAND_PATTERNS, ...TOOL_PATTERNS];
1531
- return COMMAND_PATTERNS;
1520
+ const AGENT_DOCS_MESSAGE = "belongs only at the repository root. Move what agents need into the root AGENTS.md and delete this file.";
1521
+ const WORKSPACE_AGENT_DOCS_MESSAGE = "belongs only at the repository root or as AGENTS.md directly in a workspace, the directory that holds its package.json. Move what agents need there and delete this file.";
1522
+ const README_MESSAGE = "is allowed below the root only in a workspace, the directory that holds its package.json. Move it into the workspace it describes.";
1523
+ const agentDocProblem = ({ file, base, directory }, allowed) => {
1524
+ if (!allowed.workspaceAgentDocs) return Option.some(problemFor$1(file, `${base} ${AGENT_DOCS_MESSAGE}`));
1525
+ if (base === WORKSPACE_AGENT_DOC && HashSet.has(allowed.workspaces, directory)) return Option.none();
1526
+ return Option.some(problemFor$1(file, `${base} ${WORKSPACE_AGENT_DOCS_MESSAGE}`));
1532
1527
  };
1533
- const commandProblem = ({ file }, source) => (found) => ({
1534
- file,
1535
- ...positionOf(source)(found.index ?? WHOLE_MATCH),
1536
- rule: COMMAND_RULE,
1537
- message: `Python is not used in this repository. Remove \`${String$1.trim(found[WHOLE_MATCH])}\` and do the work in TypeScript or Rust.`
1528
+ const readmeProblem = ({ file, base, directory }, allowed) => {
1529
+ if (!README$1.test(base) || HashSet.has(allowed.workspaces, directory)) return Option.none();
1530
+ return Option.some(problemFor$1(file, `${base} ${README_MESSAGE}`));
1531
+ };
1532
+ const problemIn$2 = Effect.fn("problemIn")(function* problemIn(root, allowed, name) {
1533
+ const files = yield* RepositoryFiles;
1534
+ const file = files.join(root, name);
1535
+ const doc = {
1536
+ file,
1537
+ base: files.basename(name),
1538
+ directory: files.dirname(file)
1539
+ };
1540
+ if (AGENT_DOCS.test(doc.base)) return agentDocProblem(doc, allowed);
1541
+ return readmeProblem(doc, allowed);
1542
+ });
1543
+ const allowsWorkspaceAgentDocs = Effect.fn("allowsWorkspaceAgentDocs")(function* allowsWorkspaceAgentDocs(root) {
1544
+ const files = yield* RepositoryFiles;
1545
+ const file = files.join(root, CONFIG_FILE$4);
1546
+ if (!(yield* files.exists(file))) return false;
1547
+ const config = yield* Effect.tryPromise({
1548
+ try: () => resolveConfigFromFile(file),
1549
+ catch: () => RootConfigUnreadable.make({ file })
1550
+ }).pipe(Effect.option);
1551
+ return pipe(config, Option.flatMap(Schema.decodeUnknownOption(RootConfig$1)), Option.isSome);
1538
1552
  });
1539
- const commandProblems = (entry, source) => pipe(patternsFor(entry.name), Array.flatMap((pattern) => Array.fromIterable(String$1.matchAll(pattern)(source))), Array.map(commandProblem(entry, source)));
1540
- const isPython = ({ name }) => PYTHON_FILE.test(name);
1541
- const isScanned = (entry) => !isPython(entry) && SCANNED_FILE.test(entry.name) && !LOCKFILE.test(entry.name);
1542
1553
  /** @internal */
1543
- const checkPython = Effect.fn("checkPython")(function* checkPython(root) {
1554
+ const checkNestedDocs = Effect.fn("checkNestedDocs")(function* checkNestedDocs(root) {
1544
1555
  const files = yield* RepositoryFiles;
1545
1556
  const names = yield* files.listedFiles(root);
1546
- const listed = pipe(names, Array.map((name) => ({
1547
- name,
1548
- file: files.join(root, name)
1549
- })));
1550
- const problemsIn = (entry) => files.readFile(entry.file).pipe(Effect.map(Option.match({
1551
- onNone: () => [],
1552
- onSome: (source) => commandProblems(entry, source)
1553
- })));
1554
- const scanned = yield* Effect.forEach(pipe(listed, Array.filter(isScanned)), problemsIn, { concurrency: READ_CONCURRENCY$3 });
1555
- const present = yield* Effect.filter(pipe(listed, Array.filter(isPython)), ({ file }) => files.exists(file));
1556
- return [...pipe(present, Array.map(fileProblem)), ...Array.flatten(scanned)];
1557
+ const nested = pipe(names, Array.filter(isNested));
1558
+ const workspaceAgentDocs = yield* allowsWorkspaceAgentDocs(root);
1559
+ const allowed = {
1560
+ workspaces: pipe(nested, Array.filter((name) => files.basename(name) === MANIFEST_FILE), Array.map((name) => files.dirname(files.join(root, name))), HashSet.fromIterable),
1561
+ workspaceAgentDocs
1562
+ };
1563
+ const found = yield* Effect.forEach(nested, (name) => problemIn$2(root, allowed, name), { concurrency: READ_CONCURRENCY$6 });
1564
+ return Array.getSomes(found);
1557
1565
  });
1558
1566
  // src/root-readme.ts
1559
- const RULE$3 = "root-readme";
1567
+ const RULE$5 = "root-readme";
1560
1568
  const SEPARATOR$1 = "/";
1561
1569
  const ALTERNATIVE = "|";
1562
1570
  const SCOPE = /^@[^/]+\//u;
1563
1571
  const README = /^README(?:\.[^/]+)?$/iu;
1564
1572
  const SPECIAL = /[$()*+.?[\\\]^{|}]/gu;
1565
- const READ_CONCURRENCY$2 = 16;
1566
- const START = 0;
1573
+ const READ_CONCURRENCY$5 = 16;
1574
+ const START$3 = 0;
1567
1575
  const NamedManifest = Schema.fromJsonString(Schema.Struct({ name: Schema.optional(Schema.String) }));
1568
1576
  const patternOf = (names) => {
1569
1577
  const alternatives = pipe(names, Array.map(String$1.replaceAll(SPECIAL, String.raw`\$&`)));
@@ -1588,13 +1596,13 @@ const workspaceIn = Effect.fn("workspaceIn")(function* workspaceIn(root, name) {
1588
1596
  };
1589
1597
  });
1590
1598
  const messageFor = (directory) => `names the workspace ${directory}. The root README describes the repository as a whole. Write what belongs to the workspace in ${directory}/README.md.`;
1591
- const problemsIn$1 = (file, source) => ({ directory, pattern }) => {
1599
+ const problemsIn$2 = (file, source) => ({ directory, pattern }) => {
1592
1600
  const message = messageFor(directory);
1593
1601
  const at = positionOf(source);
1594
1602
  return pipe(Array.fromIterable(String$1.matchAll(pattern)(source)), Array.map((found) => ({
1595
1603
  file,
1596
- ...at(found.index ?? START),
1597
- rule: RULE$3,
1604
+ ...at(found.index ?? START$3),
1605
+ rule: RULE$5,
1598
1606
  message
1599
1607
  })));
1600
1608
  };
@@ -1602,7 +1610,7 @@ const problemsInReadme = Effect.fn("problemsInReadme")(function* problemsInReadm
1602
1610
  const text = yield* (yield* RepositoryFiles).readFile(file);
1603
1611
  return pipe(text, Option.match({
1604
1612
  onNone: () => [],
1605
- onSome: (source) => pipe(workspaces, Array.flatMap(problemsIn$1(file, source)))
1613
+ onSome: (source) => pipe(workspaces, Array.flatMap(problemsIn$2(file, source)))
1606
1614
  }));
1607
1615
  });
1608
1616
  /** @internal */
@@ -1611,8 +1619,445 @@ const checkRootReadme = Effect.fn("checkRootReadme")(function* checkRootReadme(r
1611
1619
  const names = yield* files.listedFiles(root);
1612
1620
  const readmes = pipe(names, Array.filter((name) => README.test(name)));
1613
1621
  const manifests = pipe(names, Array.filter((name) => String$1.includes(SEPARATOR$1)(name) && files.basename(name) === "package.json"));
1614
- const workspaces = yield* Effect.forEach(manifests, (name) => workspaceIn(root, name), { concurrency: READ_CONCURRENCY$2 });
1615
- const found = yield* Effect.forEach(readmes, (name) => problemsInReadme(files.join(root, name), workspaces), { concurrency: READ_CONCURRENCY$2 });
1622
+ const workspaces = yield* Effect.forEach(manifests, (name) => workspaceIn(root, name), { concurrency: READ_CONCURRENCY$5 });
1623
+ const found = yield* Effect.forEach(readmes, (name) => problemsInReadme(files.join(root, name), workspaces), { concurrency: READ_CONCURRENCY$5 });
1624
+ return Array.flatten(found);
1625
+ });
1626
+ // src/placement-checks.ts
1627
+ /** @internal */
1628
+ const checkPlacement = Effect.fn("checkPlacement")(function* checkPlacement(root) {
1629
+ const found = yield* Effect.all([
1630
+ checkNestedDocs(root),
1631
+ checkRootReadme(root),
1632
+ checkColocatedTests(root)
1633
+ ], { concurrency: "unbounded" });
1634
+ return Array.flatten(found);
1635
+ });
1636
+ // src/found-comment.ts
1637
+ const taggedError$2 = Schema.TaggedError;
1638
+ var CommentsUnreadable = class extends taggedError$2()("CommentsUnreadable", {
1639
+ reader: Schema.String,
1640
+ message: Schema.String
1641
+ }) {};
1642
+ const unreadable = (reader) => (cause) => CommentsUnreadable.make({
1643
+ reader,
1644
+ message: String(cause)
1645
+ });
1646
+ const trimmed = ({ index, text }) => ({
1647
+ index,
1648
+ text: String$1.trimEnd(text)
1649
+ });
1650
+ // src/config-comments.ts
1651
+ const NEXT$2 = 1;
1652
+ const isRecord = (value) => typeof value === "object" && value !== null;
1653
+ const childrenOf = (value) => {
1654
+ if (Array.isArray(value)) return value;
1655
+ if (isRecord(value)) return Record.values(value);
1656
+ return [];
1657
+ };
1658
+ const collect = (isItem) => (value) => {
1659
+ if (isItem(value)) return [value];
1660
+ return pipe(childrenOf(value), Array.flatMap(collect(isItem)));
1661
+ };
1662
+ const isYamlComment = (value) => isRecord(value) && value["type"] === "comment" && typeof value["offset"] === "number" && typeof value["source"] === "string";
1663
+ const yamlComments = (source) => Effect.try({
1664
+ try: () => pipe(Array.fromIterable(new Parser().parse(source)), Array.flatMap(collect(isYamlComment)), Array.map((token) => trimmed({
1665
+ index: token.offset,
1666
+ text: token.source
1667
+ }))),
1668
+ catch: unreadable("yaml")
1669
+ });
1670
+ const tomlComments = (source) => Effect.try({
1671
+ try: () => pipe(parseTOML(source).comments, Array.map(({ range: [start, end] }) => trimmed({
1672
+ index: start,
1673
+ text: String$1.slice(start, end)(source)
1674
+ }))),
1675
+ catch: unreadable("toml")
1676
+ });
1677
+ const isSqlComment = (value) => isRecord(value) && (value["type"] === "line_comment" || value["type"] === "block_comment") && typeof value["text"] === "string" && Array.isArray(value["range"]);
1678
+ const sqlComments = (source) => Effect.try({
1679
+ try: () => {
1680
+ const program = parse$2(source, {
1681
+ dialect: "sqlite",
1682
+ includeComments: true,
1683
+ includeRange: true,
1684
+ paramTypes: []
1685
+ });
1686
+ return pipe(collect(isSqlComment)(program), Array.map(({ range: [start], text }) => trimmed({
1687
+ index: start,
1688
+ text
1689
+ })));
1690
+ },
1691
+ catch: unreadable("sql")
1692
+ });
1693
+ const offsetAt = (lines) => ({ line, character }) => character + pipe(lines, Array.take(line), Array.map((text) => text.length + NEXT$2), Number$1.sumAll);
1694
+ const dockerfileComments = (source) => Effect.try({
1695
+ try: () => {
1696
+ const lines = String$1.split(source, "\n");
1697
+ return pipe(DockerfileParser.parse(source).getComments(), Array.map((comment) => trimmed({
1698
+ index: offsetAt(lines)(comment.getRange().start),
1699
+ text: comment.toString()
1700
+ })));
1701
+ },
1702
+ catch: unreadable("dockerfile")
1703
+ });
1704
+ // src/comment-readers.ts
1705
+ const GRAMMARS = [
1706
+ "bash",
1707
+ "c-sharp",
1708
+ "cpp",
1709
+ "css",
1710
+ "go",
1711
+ "java",
1712
+ "javascript",
1713
+ "php",
1714
+ "powershell",
1715
+ "ruby",
1716
+ "rust",
1717
+ "tsx",
1718
+ "typescript"
1719
+ ];
1720
+ const COMMENT_NODES = [
1721
+ "comment",
1722
+ "line_comment",
1723
+ "block_comment",
1724
+ "multiline_comment"
1725
+ ];
1726
+ const START$2 = 0;
1727
+ const NEXT$1 = 1;
1728
+ const NONE$1 = [];
1729
+ const grammarFile = (grammar) => fileURLToPath(import.meta.resolve(`@vscode/tree-sitter-wasm/wasm/tree-sitter-${grammar}.wasm`));
1730
+ const loadGrammar = (grammar) => Effect.tryPromise({
1731
+ try: () => treeSitter.Language.load(grammarFile(grammar)),
1732
+ catch: unreadable(grammar)
1733
+ }).pipe(Effect.map((language) => [grammar, language]));
1734
+ const loadGrammars = Effect.fn("loadGrammars")(function* loadGrammars() {
1735
+ yield* Effect.tryPromise({
1736
+ try: () => treeSitter.Parser.init(),
1737
+ catch: unreadable("javascript")
1738
+ });
1739
+ const loaded = yield* pipe(GRAMMARS, Effect.forEach((grammar) => loadGrammar(grammar)));
1740
+ const languages = Record.fromEntries(loaded);
1741
+ const grammars = (grammar) => Record.get(languages, grammar);
1742
+ return grammars;
1743
+ });
1744
+ const commentNodesIn = (language, source) => {
1745
+ const parser = new treeSitter.Parser();
1746
+ parser.setLanguage(language);
1747
+ const tree = parser.parse(source);
1748
+ parser.delete();
1749
+ if (tree === null) return NONE$1;
1750
+ const found = pipe(tree.rootNode.descendantsOfType(COMMENT_NODES), Array.flatMap((node) => Option.toArray(Option.fromNullishOr(node))), Array.map((node) => trimmed({
1751
+ index: node.startIndex,
1752
+ text: node.text
1753
+ })));
1754
+ tree.delete();
1755
+ return found;
1756
+ };
1757
+ const syntaxComments = (grammars, grammar) => (source) => Option.match(grammars(grammar), {
1758
+ onNone: () => Effect.fail(unreadable(grammar)("the grammar is not loaded")),
1759
+ onSome: (language) => Effect.try({
1760
+ try: () => commentNodesIn(language, source),
1761
+ catch: unreadable(grammar)
1762
+ })
1763
+ });
1764
+ const SCRIPT_TYPE = /^(?:|module|text\/javascript|application\/javascript)$/iu;
1765
+ const SHADER_TYPE = /shader|glsl/iu;
1766
+ const scriptGrammar = (attribs) => {
1767
+ const type = String$1.trim(Option.getOrElse(Record.get(attribs, "type"), () => ""));
1768
+ if (Record.get(attribs, "lang").pipe(Option.contains("ts"))) return Option.some("typescript");
1769
+ if (SHADER_TYPE.test(type)) return Option.some("cpp");
1770
+ return Option.liftPredicate("javascript", () => SCRIPT_TYPE.test(type));
1771
+ };
1772
+ const embeddedGrammar = ({ name, attribs }) => {
1773
+ if (name === "style") return Option.some("css");
1774
+ if (name === "script") return scriptGrammar(attribs);
1775
+ return Option.none();
1776
+ };
1777
+ const shifted = (offset) => ({ index, text }) => ({
1778
+ index: index + offset,
1779
+ text
1780
+ });
1781
+ const markupComment = (source) => (node) => {
1782
+ if (!isComment(node) || node.startIndex === null || node.endIndex === null) return NONE$1;
1783
+ return [{
1784
+ index: node.startIndex,
1785
+ text: String$1.slice(node.startIndex, node.endIndex + NEXT$1)(source)
1786
+ }];
1787
+ };
1788
+ const textComments = (grammars, grammar) => (text) => {
1789
+ const shift = shifted(text.startIndex ?? START$2);
1790
+ return syntaxComments(grammars, grammar)(text.data).pipe(Effect.map(Array.map(shift)));
1791
+ };
1792
+ const embeddedComments = (grammars) => (node) => {
1793
+ if (!isTag(node)) return Effect.succeed(NONE$1);
1794
+ const texts = pipe(node.children, Array.filter(isText));
1795
+ return Option.match(embeddedGrammar(node), {
1796
+ onNone: () => Effect.succeed(NONE$1),
1797
+ onSome: (grammar) => pipe(texts, Effect.forEach(textComments(grammars, grammar)), Effect.map(Array.flatten))
1798
+ });
1799
+ };
1800
+ const markupComments = (grammars, markup) => (source) => Effect.gen(function* readMarkup() {
1801
+ const document = parseDocument$1(source, {
1802
+ xmlMode: markup === "xml",
1803
+ withStartIndices: true,
1804
+ withEndIndices: true
1805
+ });
1806
+ const nodes = DomUtils.filter(() => true, document.children, true);
1807
+ const own = pipe(nodes, Array.flatMap(markupComment(source)));
1808
+ if (markup === "xml") return own;
1809
+ const embedded = yield* pipe(nodes, Effect.forEach(embeddedComments(grammars)));
1810
+ return [...own, ...Array.flatten(embedded)];
1811
+ });
1812
+ const isGrammar = (reader) => pipe(GRAMMARS, Array.contains(reader));
1813
+ const commentsWith = (grammars) => (reader, source) => {
1814
+ if (isGrammar(reader)) return syntaxComments(grammars, reader)(source);
1815
+ return {
1816
+ html: markupComments(grammars, "html"),
1817
+ xml: markupComments(grammars, "xml"),
1818
+ yaml: yamlComments,
1819
+ toml: tomlComments,
1820
+ sql: sqlComments,
1821
+ dockerfile: dockerfileComments
1822
+ }[reader](source);
1823
+ };
1824
+ // src/comments.ts
1825
+ const RULE$4 = "comment";
1826
+ const CONFIG_FILE$3 = "vite.config.ts";
1827
+ const VENDORED_PATHSPEC = ":(attr:linguist-vendored)";
1828
+ const READ_CONCURRENCY$4 = 64;
1829
+ const START$1 = 0;
1830
+ const FIRST_LINE$1 = 1;
1831
+ const FIRST_COLUMN$1 = 1;
1832
+ const READERS = [
1833
+ [/\.(?:[cm]?jsx?)$/u, "javascript"],
1834
+ [/\.(?:[cm]?ts)$/u, "typescript"],
1835
+ [/\.tsx$/u, "tsx"],
1836
+ [/\.rs$/u, "rust"],
1837
+ [/\.(?:cs|csx)$/u, "c-sharp"],
1838
+ [/\.(?:sh|bash|zsh|ksh)$/u, "bash"],
1839
+ [/(?:^|\/)\.(?:vite-hooks|husky|githooks)\/[^./][^/]*$/u, "bash"],
1840
+ [/\.(?:ps1|psm1|psd1)$/u, "powershell"],
1841
+ [/\.go$/u, "go"],
1842
+ [/\.(?:java|kt|kts)$/u, "java"],
1843
+ [/\.(?:rb|rake)$/u, "ruby"],
1844
+ [/\.php$/u, "php"],
1845
+ [/\.(?:c|h|cc|cpp|cxx|hpp|hh|m|mm|glsl|frag|vert|comp|wgsl|hlsl|metal)$/u, "cpp"],
1846
+ [/\.(?:css|pcss)$/u, "css"],
1847
+ [/\.(?:html?|vue|svelte|astro)$/u, "html"],
1848
+ [/\.(?:xml|xaml|plist|resx|props|targets|[a-z]+proj|manifest|nuspec)$/u, "xml"],
1849
+ [/\.ya?ml$/u, "yaml"],
1850
+ [/\.toml$/u, "toml"],
1851
+ [/\.sql$/u, "sql"],
1852
+ [/(?:^|\/)(?:Dockerfile|Containerfile)(?:\.[^/]+)?$|\.dockerfile$/u, "dockerfile"]
1853
+ ];
1854
+ const SHEBANG_READERS = [
1855
+ [/^#!.*\b(?:ba|z|k|da)?sh\b/u, "bash"],
1856
+ [/^#!.*\b(?:node|bun|deno|tsx)\b/u, "javascript"],
1857
+ [/^#!.*\bpwsh\b/u, "powershell"]
1858
+ ];
1859
+ const SHEBANG = "#!";
1860
+ const PIN = /@(?:[0-9a-f]{40}|sha256:[0-9a-f]{64})\s*$/u;
1861
+ const VERSION = /^\s?v?\d[\w.+-]*$/u;
1862
+ const DELIMITERS = /^(?:\/\/|\/\*|<!--|<#|#|--)|(?:\*\/|-->|#>)$/gu;
1863
+ const MESSAGE = "Comments are not written in this repository. Say it with names and types in the code, put the reason in the commit message, and delete the comment.";
1864
+ const Patterns = Schema.Array(Schema.String);
1865
+ const CommentSettings = Schema.Struct({ allow: Patterns });
1866
+ const MschSettings = Schema.Struct({ comments: Schema.optional(CommentSettings) });
1867
+ const LintSettings = Schema.Struct({ ignorePatterns: Schema.optional(Patterns) });
1868
+ const RootConfig = Schema.Struct({
1869
+ msch: Schema.optional(MschSettings),
1870
+ lint: Schema.optional(LintSettings)
1871
+ });
1872
+ const NO_SETTINGS = {
1873
+ allow: [],
1874
+ ignorePatterns: []
1875
+ };
1876
+ const NONE = [];
1877
+ const taggedError$1 = Schema.TaggedError;
1878
+ var CommentConfigUnreadable = class extends taggedError$1()("CommentConfigUnreadable", { file: Schema.String }) {};
1879
+ const shebangReader = (source) => {
1880
+ if (!String$1.startsWith(SHEBANG)(source)) return Option.none();
1881
+ return pipe(SHEBANG_READERS, Array.findFirst(([pattern]) => pattern.test(source)));
1882
+ };
1883
+ const readerOf = (name, source) => pipe(READERS, Array.findFirst(([pattern]) => pattern.test(name)), Option.orElse(() => shebangReader(source)), Option.map(([, reader]) => reader));
1884
+ const valueOf = (text) => String$1.replaceAll(DELIMITERS, "")(text);
1885
+ const lineBefore = (source, index) => {
1886
+ const lines = pipe(source, String$1.slice(START$1, index), String$1.split("\n"));
1887
+ return Option.getOrElse(Array.last(lines), () => "");
1888
+ };
1889
+ const isPinVersion = (source, { index, text }) => PIN.test(lineBefore(source, index)) && VERSION.test(valueOf(text));
1890
+ const isShebang = ({ index, text }) => index === START$1 && String$1.startsWith(SHEBANG)(text);
1891
+ const isAllowed = (source, directives) => (comment) => isShebang(comment) || directives.test(valueOf(comment.text)) || isPinVersion(source, comment);
1892
+ const problemOf$1 = (file, source) => ({ index }) => ({
1893
+ file,
1894
+ ...positionOf(source)(index),
1895
+ rule: RULE$4,
1896
+ message: MESSAGE
1897
+ });
1898
+ const unreadableProblem = (file, message) => ({
1899
+ file,
1900
+ line: FIRST_LINE$1,
1901
+ column: FIRST_COLUMN$1,
1902
+ rule: RULE$4,
1903
+ message: `msch could not read the comments in this file: ${message}`
1904
+ });
1905
+ const settingsOf = ({ msch, lint }) => ({
1906
+ allow: pipe(Option.fromUndefinedOr(msch), Option.flatMap(({ comments }) => Option.fromUndefinedOr(comments)), Option.match({
1907
+ onNone: () => NO_SETTINGS.allow,
1908
+ onSome: ({ allow }) => allow
1909
+ })),
1910
+ ignorePatterns: pipe(Option.fromUndefinedOr(lint), Option.flatMap(({ ignorePatterns }) => Option.fromUndefinedOr(ignorePatterns)), Option.getOrElse(() => NO_SETTINGS.ignorePatterns))
1911
+ });
1912
+ const rootSettings = Effect.fn("rootSettings")(function* rootSettings(root) {
1913
+ const files = yield* RepositoryFiles;
1914
+ const file = files.join(root, CONFIG_FILE$3);
1915
+ if (!(yield* files.exists(file))) return NO_SETTINGS;
1916
+ const config = yield* Effect.tryPromise({
1917
+ try: () => resolveConfigFromFile(file),
1918
+ catch: () => CommentConfigUnreadable.make({ file })
1919
+ }).pipe(Effect.option);
1920
+ return pipe(config, Option.flatMap(Schema.decodeUnknownOption(RootConfig)), Option.match({
1921
+ onNone: () => NO_SETTINGS,
1922
+ onSome: settingsOf
1923
+ }));
1924
+ });
1925
+ const directivePattern = (directives) => new RegExp(String.raw`^\s?(?:${Array.join(directives, "|")})`, "u");
1926
+ const isIgnored = (patterns) => (name) => pipe(patterns, Array.some((pattern) => path.matchesGlob(name, pattern)));
1927
+ const scannedFiles = Effect.fn("scannedFiles")(function* scannedFiles(root, settings) {
1928
+ const files = yield* RepositoryFiles;
1929
+ const listed = yield* files.listedFiles(root);
1930
+ const generated = yield* files.generatedFiles(root);
1931
+ const vendored = yield* files.matchingFiles(root, [VENDORED_PATHSPEC]);
1932
+ const skipped = HashSet.fromIterable([...generated, ...pipe(vendored, Array.map((name) => files.join(root, name)))]);
1933
+ return pipe(listed, Array.filter((name) => !isIgnored(settings.ignorePatterns)(name)), Array.map((name) => ({
1934
+ name,
1935
+ file: files.join(root, name)
1936
+ })), Array.filter(({ file }) => !HashSet.has(skipped, file)));
1937
+ });
1938
+ /** @internal */
1939
+ const checkComments = Effect.fn("checkComments")(function* checkComments(root) {
1940
+ const files = yield* RepositoryFiles;
1941
+ const settings = yield* rootSettings(root);
1942
+ const scanned = yield* scannedFiles(root, settings);
1943
+ const directives = directivePattern([...COMMENT_DIRECTIVES, ...settings.allow]);
1944
+ const grammars = yield* loadGrammars();
1945
+ const comments = commentsWith(grammars);
1946
+ const problemsIn = ({ name, file }, source) => {
1947
+ const kept = Predicate.not(isAllowed(source, directives));
1948
+ const toProblem = problemOf$1(file, source);
1949
+ return Option.match(readerOf(name, source), {
1950
+ onNone: () => Effect.succeed(NONE),
1951
+ onSome: (reader) => comments(reader, source).pipe(Effect.map(Array.filter(kept)), Effect.map(Array.map(toProblem)), Effect.catchTag("CommentsUnreadable", ({ message }) => Effect.succeed([unreadableProblem(file, message)])))
1952
+ });
1953
+ };
1954
+ const found = yield* Effect.forEach(scanned, (entry) => files.readFile(entry.file).pipe(Effect.flatMap(Option.match({
1955
+ onNone: () => Effect.succeed(NONE),
1956
+ onSome: (source) => problemsIn(entry, source)
1957
+ }))), { concurrency: READ_CONCURRENCY$4 });
1958
+ return Array.flatten(found);
1959
+ });
1960
+ // src/hidden-unicode.ts
1961
+ const HIDDEN = /[\u00AD\u180E\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]|[\u{E0000}-\u{E007F}]/gu;
1962
+ const NUL = "\0";
1963
+ const START = 0;
1964
+ const HEX = 16;
1965
+ const CODE_POINT_WIDTH = 4;
1966
+ const READ_CONCURRENCY$3 = 64;
1967
+ const RULE$3 = "hidden-unicode";
1968
+ const hexOf = (character) => pipe(String$1.codePointAt(START)(character), Option.getOrElse(() => START), (code) => code.toString(HEX), String$1.toUpperCase, String$1.padStart(CODE_POINT_WIDTH, "0"));
1969
+ const problemOf = (file, source) => (found) => {
1970
+ const hex = hexOf(found[START]);
1971
+ return {
1972
+ file,
1973
+ ...positionOf(source)(found.index ?? START),
1974
+ rule: RULE$3,
1975
+ message: `U+${hex} is invisible in editors and reviews and can change what the text means. Remove it, or write it as the escape \\u${hex}.`
1976
+ };
1977
+ };
1978
+ const problemsIn$1 = (file, source) => {
1979
+ if (String$1.includes(NUL)(source)) return [];
1980
+ return pipe(Array.fromIterable(String$1.matchAll(HIDDEN)(source)), Array.map(problemOf(file, source)));
1981
+ };
1982
+ /** @internal */
1983
+ const checkHiddenUnicode = Effect.fn("checkHiddenUnicode")(function* checkHiddenUnicode(root) {
1984
+ const files = yield* RepositoryFiles;
1985
+ const names = yield* files.listedFiles(root);
1986
+ const found = yield* Effect.forEach(names, (name) => {
1987
+ const file = files.join(root, name);
1988
+ return files.readFile(file).pipe(Effect.map(Option.match({
1989
+ onNone: () => [],
1990
+ onSome: (source) => problemsIn$1(file, source)
1991
+ })));
1992
+ }, { concurrency: READ_CONCURRENCY$3 });
1993
+ return Array.flatten(found);
1994
+ });
1995
+ // src/python.ts
1996
+ const PYTHON_FILE = /(?:\.(?:py|pyi|pyw|pyx|ipynb)|(?:^|\/)(?:pyproject\.toml|uv\.lock|uv\.toml|poetry\.lock|Pipfile|Pipfile\.lock|setup\.cfg|tox\.ini|pytest\.ini|\.python-version|requirements[^/]*\.txt))$/u;
1997
+ const SCANNED_FILE = /(?:\.(?:[cm]?[jt]sx?|jsonc?|toml|ya?ml|sh|bash|zsh|fish|rs|cs|go|mk)|(?:^|\/)(?:Dockerfile[^/]*|Makefile|justfile|\.tool-versions|[^./][^./]*))$/u;
1998
+ const LOCKFILE = /(?:^|\/)(?:[^/]*\.lock|[^/]*-lock\.(?:json|ya?ml))$/u;
1999
+ const TOOL_VERSIONS = /(?:^|\/)(?:\.?mise(?:\.[^/]+)?\.toml|\.tool-versions)$/u;
2000
+ const COMMAND_PATTERNS = [
2001
+ /(?<![\w./@-])python[\d.]*[ \t]+(?:[-"'$./]|\S+\.py\b)/gu,
2002
+ /(?<![\w./@-])pip3?[ \t]+(?:install|uninstall|download|freeze|wheel|compile|sync)\b/gu,
2003
+ /(?<![\w./@-])pipx[ \t]+(?:run|install|inject|upgrade)\b/gu,
2004
+ /(?<![\w./@-])uvx[ \t]+[^\s=:,;)|&]/gu,
2005
+ /(?<![\w./@-])uv[ \t]+(?:run|sync|lock|pip|tool|venv|add|remove|python|export|build|publish|init|tree|cache|self)\b/gu,
2006
+ /(?<![\w./@-])poetry[ \t]+(?:run|install|add|lock|build|publish|shell|export)\b/gu,
2007
+ /(?:\bcommand["']?\s*[:=]\s*|(?:\bspawn\w*|\bexec\w*|\bexeca|Command::new|ChildProcess\.make|\$)\(\s*)["'`](?:python[\d.]*|pip3?|pipx|uvx?|poetry)["'`]/gu,
2008
+ /\buses:\s*["']?(?:actions\/setup-python|astral-sh\/setup-uv|astral-sh\/ruff-action|pypa\/[\w.-]+|snok\/install-poetry|abatilo\/actions-poetry|conda-incubator\/setup-miniconda|mamba-org\/setup-micromamba|pdm-project\/setup-pdm)\b/gu
2009
+ ];
2010
+ const TOOL_PATTERNS = [/^[ \t]*["']?(?:python|uv|pipx|poetry|ruff|pdm|hatch|pipx:[^"'\s=]+)["']?[ \t]*(?:=|[ \t]+\S)/gmu];
2011
+ const READ_CONCURRENCY$2 = 64;
2012
+ const FIRST_LINE = 1;
2013
+ const FIRST_COLUMN = 1;
2014
+ const WHOLE_MATCH = 0;
2015
+ const FILE_RULE = "python-file";
2016
+ const COMMAND_RULE = "python-command";
2017
+ const fileProblem = ({ file }) => ({
2018
+ file,
2019
+ line: FIRST_LINE,
2020
+ column: FIRST_COLUMN,
2021
+ rule: FILE_RULE,
2022
+ message: "Python is not used in this repository. Replace this file with TypeScript or Rust."
2023
+ });
2024
+ const patternsFor = (name) => {
2025
+ if (TOOL_VERSIONS.test(name)) return [...COMMAND_PATTERNS, ...TOOL_PATTERNS];
2026
+ return COMMAND_PATTERNS;
2027
+ };
2028
+ const commandProblem = ({ file }, source) => (found) => ({
2029
+ file,
2030
+ ...positionOf(source)(found.index ?? WHOLE_MATCH),
2031
+ rule: COMMAND_RULE,
2032
+ message: `Python is not used in this repository. Remove \`${String$1.trim(found[WHOLE_MATCH])}\` and do the work in TypeScript or Rust.`
2033
+ });
2034
+ const commandProblems = (entry, source) => pipe(patternsFor(entry.name), Array.flatMap((pattern) => Array.fromIterable(String$1.matchAll(pattern)(source))), Array.map(commandProblem(entry, source)));
2035
+ const isPython = ({ name }) => PYTHON_FILE.test(name);
2036
+ const isScanned = (entry) => !isPython(entry) && SCANNED_FILE.test(entry.name) && !LOCKFILE.test(entry.name);
2037
+ /** @internal */
2038
+ const checkPython = Effect.fn("checkPython")(function* checkPython(root) {
2039
+ const files = yield* RepositoryFiles;
2040
+ const names = yield* files.listedFiles(root);
2041
+ const listed = pipe(names, Array.map((name) => ({
2042
+ name,
2043
+ file: files.join(root, name)
2044
+ })));
2045
+ const problemsIn = (entry) => files.readFile(entry.file).pipe(Effect.map(Option.match({
2046
+ onNone: () => [],
2047
+ onSome: (source) => commandProblems(entry, source)
2048
+ })));
2049
+ const scanned = yield* Effect.forEach(pipe(listed, Array.filter(isScanned)), problemsIn, { concurrency: READ_CONCURRENCY$2 });
2050
+ const present = yield* Effect.filter(pipe(listed, Array.filter(isPython)), ({ file }) => files.exists(file));
2051
+ return [...pipe(present, Array.map(fileProblem)), ...Array.flatten(scanned)];
2052
+ });
2053
+ // src/tracked-text.ts
2054
+ /** @internal */
2055
+ const checkTrackedText = Effect.fn("checkTrackedText")(function* checkTrackedText(root) {
2056
+ const found = yield* Effect.all([
2057
+ checkHiddenUnicode(root),
2058
+ checkPython(root),
2059
+ checkComments(root)
2060
+ ], { concurrency: "unbounded" });
1616
2061
  return Array.flatten(found);
1617
2062
  });
1618
2063
  // src/crates.ts
@@ -1725,7 +2170,7 @@ const stringsIn = (node) => {
1725
2170
  return [...pipe(decodeStringNode(node), Option.map((found) => ({
1726
2171
  text: textOf(found),
1727
2172
  start: found.start
1728
- })), Option.toArray), ...pipe(childrenOf$2(node), Array.flatMap(stringsIn))];
2173
+ })), Option.toArray), ...pipe(childrenOf$3(node), Array.flatMap(stringsIn))];
1729
2174
  };
1730
2175
  const isBoundary = (character, allowed) => character === "" || !allowed.test(character);
1731
2176
  const mentions = (directory) => (text) => {
@@ -1769,10 +2214,8 @@ const checkAll = Effect.fn("checkAll")(function* checkAll(root) {
1769
2214
  const found = yield* Effect.all([
1770
2215
  checkRepository(root),
1771
2216
  checkOverrides(root),
1772
- checkHiddenUnicode(root),
1773
- checkPython(root),
1774
- checkNestedDocs(root),
1775
- checkRootReadme(root),
2217
+ checkTrackedText(root),
2218
+ checkPlacement(root),
1776
2219
  checkPublishedPackages(root),
1777
2220
  checkWorkspaces(root)
1778
2221
  ], { concurrency: "unbounded" });