@r_masseater/msch 0.58.1 → 0.59.1

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.
@@ -1,4 +1,4 @@
1
- import { n as baseName } from "./app-B22Gq0no.mjs";
1
+ import { n as baseName, o as parent } from "./app-DcgzLzb0.mjs";
2
2
  import { Array, Boolean, Match, Option, Predicate, Record, Schema, String as String$1, pipe } from "effect";
3
3
  import { isTypeNode } from "typescript/ast/is";
4
4
  import { SymbolFlags } from "typescript/sync";
@@ -77,7 +77,7 @@ const childrenOf$1 = (keys, node) => pipe(Option.liftPredicate(node, Predicate.i
77
77
  const descendants = (keys) => (node) => [node, ...pipe(childrenOf$1(keys, node), Array.flatMap(descendants(keys)))];
78
78
  const accessesIn = (scope) => (method) => (node) => pipe(descendants(scope.keys)(node), Array.map(accessOf(scope)(method)), Array.getSomes);
79
79
  // src/features/define-lint-rules/model/array-from-async.ts
80
- const MESSAGE$4 = "Collect an async iterable with Array.fromAsync, passing the mapping as its second argument. Do not push each item from a for await loop.";
80
+ const MESSAGE$5 = "Collect an async iterable with Array.fromAsync, passing the mapping as its second argument. Do not push each item from a for await loop.";
81
81
  const ONE$1 = 1;
82
82
  const DeclarationSchema = Schema.Struct({
83
83
  type: Schema.Literal("VariableDeclaration"),
@@ -111,7 +111,7 @@ const arrayFromAsync = {
111
111
  create: (context) => ({ ForOfStatement: (node) => {
112
112
  if (collectsByHand(node)) context.report({
113
113
  node,
114
- message: MESSAGE$4
114
+ message: MESSAGE$5
115
115
  });
116
116
  } })
117
117
  };
@@ -200,6 +200,77 @@ const ecosystemReaders = {
200
200
  }
201
201
  })
202
202
  };
203
+ // src/features/define-lint-rules/model/typed-rule.ts
204
+ const typedRuleOf = ({ meta, visitorOf }) => withTypeInformation({
205
+ meta,
206
+ create: (context) => pipe(Option.fromNullishOr(context.sourceCode.parserServices), Option.match({
207
+ onNone: () => ({}),
208
+ onSome: (services) => visitorOf(context, services)
209
+ }))
210
+ });
211
+ // src/features/define-lint-rules/model/explicit-import-path.ts
212
+ const MESSAGE_ID$1 = "spellOut";
213
+ const MESSAGE$4 = "`{{specifier}}` does not name a file. Write `{{fixed}}`: Node ESM and TypeScript nodenext resolve neither a missing extension nor a directory index, so spelling out the file works under every resolver.";
214
+ const RELATIVE = /^\.{1,2}(?:\/|$)/u;
215
+ const PARTS = /^(?<path>[^?]*)(?<query>.*)$/su;
216
+ const TRAILING_SEPARATORS = /\/+$/u;
217
+ const DIRECTORY_NAMES = [".", ".."];
218
+ const INDEX = "index.";
219
+ const DEFAULT_QUOTE = "\"";
220
+ const FIRST = 0;
221
+ const partsOf = (specifier) => pipe(String$1.match(PARTS)(specifier), Option.flatMap((matched) => Option.fromNullishOr(matched.groups)), Option.map((groups) => ({
222
+ path: groups["path"] ?? "",
223
+ query: groups["query"] ?? ""
224
+ })));
225
+ const completionOf = (resolved, path) => {
226
+ const file = baseName(resolved);
227
+ const name = baseName(path);
228
+ const index = String$1.startsWith(INDEX)(file);
229
+ if (Array.contains(DIRECTORY_NAMES, name)) return Option.liftPredicate(`/${file}`, () => index);
230
+ if (String$1.startsWith(`${name}.`)(file)) return Option.some(String$1.slice(name.length)(file));
231
+ return Option.liftPredicate(`/${file}`, () => index && baseName(parent(resolved)) === name);
232
+ };
233
+ const resolvedFileOf = (services, source) => pipe(Option.fromNullishOr(services.getSymbolAtLocation(source)), Option.flatMap((symbol) => Array.head(symbol.declarations)), Option.map((declaration) => declaration.getSourceFile().fileName));
234
+ const fixedOf = (services, source) => pipe(partsOf(source.value), Option.filter(({ path }) => RELATIVE.test(path)), Option.flatMap(({ path, query }) => pipe(resolvedFileOf(services, source), Option.flatMap((resolved) => completionOf(resolved, String$1.replace(TRAILING_SEPARATORS, "")(path))), Option.map((completion) => `${String$1.replace(TRAILING_SEPARATORS, "")(path)}${completion}${query}`))));
235
+ const quoteOf = (source) => pipe(Option.fromNullishOr(source.raw), Option.flatMap(String$1.charAt(FIRST)), Option.getOrElse(() => DEFAULT_QUOTE));
236
+ const isStringLiteral = (node) => Predicate.isNotNull(node) && node.type === "Literal" && Predicate.isString(node.value);
237
+ const visitorOf$1 = (context, services) => {
238
+ const check = (source) => {
239
+ if (!isStringLiteral(source)) return;
240
+ const fixed = fixedOf(services, source);
241
+ if (Option.isSome(fixed)) context.report({
242
+ node: source,
243
+ messageId: MESSAGE_ID$1,
244
+ data: {
245
+ specifier: source.value,
246
+ fixed: fixed.value
247
+ },
248
+ fix: (fixer) => fixer.replaceText(source, `${quoteOf(source)}${fixed.value}${quoteOf(source)}`)
249
+ });
250
+ };
251
+ return {
252
+ ImportDeclaration: (node) => {
253
+ check(node.source);
254
+ },
255
+ ExportAllDeclaration: (node) => {
256
+ check(node.source);
257
+ },
258
+ ExportNamedDeclaration: (node) => {
259
+ check(node.source);
260
+ },
261
+ ImportExpression: (node) => {
262
+ check(node.source);
263
+ }
264
+ };
265
+ };
266
+ const explicitImportPath = typedRuleOf({
267
+ meta: {
268
+ type: "suggestion",
269
+ fixable: "code",
270
+ messages: { [MESSAGE_ID$1]: MESSAGE$4 }
271
+ },
272
+ visitorOf: visitorOf$1
273
+ });
203
274
  // src/features/define-lint-rules/model/get-or-insert.ts
204
275
  const MESSAGE$3 = "Use getOrInsert or getOrInsertComputed on the Map or WeakMap, so that reading a key and storing its first value is one call. Do not read the key and then set it by hand.";
205
276
  const ONE = 1;
@@ -689,159 +760,6 @@ const inlineExports = {
689
760
  if (Option.isSome(list) && !pipe(list.value.specifiers, Array.every(isTypeOnlyClass(list.value)))) reportList(context, node, list.value);
690
761
  } })
691
762
  };
692
- // src/features/define-lint-rules/model/intent-rule.ts
693
- const NAMESPACE = "*";
694
- const DEFAULT = "default";
695
- const importedName = (specifier) => {
696
- if (specifier.type === "ImportDefaultSpecifier") return DEFAULT;
697
- if (specifier.type === "ImportNamespaceSpecifier") return NAMESPACE;
698
- if (specifier.imported.type === "Identifier") return specifier.imported.name;
699
- return specifier.imported.value;
700
- };
701
- const isTypeOnly = (node, specifier) => node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type";
702
- const isBannedSpecifier = (node, ban, names) => (specifier) => !(ban.typesAllowed && isTypeOnly(node, specifier)) && Array.contains([NAMESPACE, ...names], importedName(specifier));
703
- const wholeImport = (node, ban) => {
704
- if (ban.typesAllowed && node.importKind === "type") return [];
705
- return [node];
706
- };
707
- const bannedIn = (node) => (ban) => {
708
- if (node.source.value !== ban.module) return [];
709
- return Option.match(ban.names, {
710
- onNone: () => wholeImport(node, ban),
711
- onSome: (names) => pipe(node.specifiers, Array.filter(isBannedSpecifier(node, ban, names)))
712
- });
713
- };
714
- const propertyOf = (node) => {
715
- if (!node.computed && node.property.type === "Identifier") return Option.some(node.property.name);
716
- if (node.property.type === "Literal" && typeof node.property.value === "string") return Option.some(node.property.value);
717
- return Option.none();
718
- };
719
- const isBannedMember = (node) => (ban) => node.object.type === "Identifier" && node.object.name === ban.object && pipe(propertyOf(node), Option.exists((property) => Array.contains(ban.properties, property)));
720
- const reportImports = (context, intent, node) => {
721
- const banned = pipe(intent.imports, Array.flatMap(bannedIn(node)));
722
- for (const found of banned) context.report({
723
- node: found,
724
- message: intent.message
725
- });
726
- };
727
- const ruleOf = (intent) => ({
728
- meta: { type: "problem" },
729
- create: (context) => ({
730
- ImportDeclaration: (node) => {
731
- reportImports(context, intent, node);
732
- },
733
- MemberExpression: (node) => {
734
- if (pipe(intent.members, Array.some(isBannedMember(node)))) context.report({
735
- node,
736
- message: intent.message
737
- });
738
- }
739
- })
740
- });
741
- // src/features/define-lint-rules/model/intents.ts
742
- const RUN_MESSAGE = "Run Effects with run or runner from @r_masseater/workers-tracing/effect, so their spans reach the Workers trace.";
743
- const RUN_FUNCTIONS = [
744
- "runPromise",
745
- "runPromiseExit",
746
- "runFork",
747
- "runCallback",
748
- "runSync",
749
- "runSyncExit",
750
- "runPromiseWith",
751
- "runPromiseExitWith",
752
- "runForkWith",
753
- "runCallbackWith",
754
- "runSyncWith",
755
- "runSyncExitWith"
756
- ];
757
- const INTENTS = {
758
- "ui-state-in-atoms": {
759
- message: "Keep UI state in effect-atom (Atom.make, useAtom, useAtomValue), so that state has one home outside the component tree. Do not use React state hooks or context.",
760
- imports: [{
761
- module: "react",
762
- names: Option.some([
763
- "useState",
764
- "useReducer",
765
- "createContext",
766
- "useContext"
767
- ]),
768
- typesAllowed: false
769
- }],
770
- members: []
771
- },
772
- "no-hand-written-sql": {
773
- message: "Build queries with the Drizzle query builder, so that their columns and types come from the schema. Do not write SQL by hand with sql.",
774
- imports: [{
775
- module: "drizzle-orm",
776
- names: Option.some(["sql"]),
777
- typesAllowed: false
778
- }, {
779
- module: "drizzle-orm/sql",
780
- names: Option.none(),
781
- typesAllowed: false
782
- }],
783
- members: []
784
- },
785
- "traced-elysia": {
786
- message: "Import Elysia from @r_masseater/workers-tracing/elysia, so every handle call is a span.",
787
- imports: [{
788
- module: "elysia",
789
- names: Option.some(["Elysia", "default"]),
790
- typesAllowed: true
791
- }],
792
- members: []
793
- },
794
- "traced-effect-run": {
795
- message: RUN_MESSAGE,
796
- imports: [{
797
- module: "effect/Effect",
798
- names: Option.some(RUN_FUNCTIONS),
799
- typesAllowed: false
800
- }, {
801
- module: "effect/ManagedRuntime",
802
- names: Option.some(["make"]),
803
- typesAllowed: false
804
- }],
805
- members: [{
806
- object: "Effect",
807
- properties: RUN_FUNCTIONS
808
- }, {
809
- object: "ManagedRuntime",
810
- properties: ["make"]
811
- }]
812
- },
813
- "platform-node-by-module": {
814
- message: "Import names from a module path, such as import { layer } from \"@effect/platform-node/NodeServices\". The package root loads every module, the Redis client included, and adds about 250 ms to each start.",
815
- imports: [{
816
- module: "@effect/platform-node",
817
- names: Option.none(),
818
- typesAllowed: true
819
- }],
820
- members: []
821
- },
822
- "typed-calls-not-reflect": {
823
- message: "Read properties and call functions through typed access, or decode untyped values with Schema at the boundary. Do not go around the types with Reflect.",
824
- imports: [],
825
- members: [{
826
- object: "Reflect",
827
- properties: ["get", "apply"]
828
- }]
829
- },
830
- "db-writes-in-writers": {
831
- message: "Write tables only from a *-writer.server.ts module, so that a table update and its revision go into the same batch. Call the writer here instead of writing through db.",
832
- imports: [],
833
- members: [{
834
- object: "db",
835
- properties: [
836
- "insert",
837
- "update",
838
- "delete",
839
- "batch",
840
- "run"
841
- ]
842
- }]
843
- }
844
- };
845
763
  // src/features/define-lint-rules/model/mcp-tool-layer.ts
846
764
  const SOURCE = "/src/";
847
765
  const SEPARATOR$1 = "/";
@@ -1056,25 +974,180 @@ const visitorOf = (context, services) => {
1056
974
  TSMethodSignature: check
1057
975
  };
1058
976
  };
977
+ // src/features/define-lint-rules/model/coded-rules.ts
978
+ const CODED_RULES = {
979
+ "array-from-async": arrayFromAsync,
980
+ "ecosystem-readers": ecosystemReaders,
981
+ "explicit-import-path": explicitImportPath,
982
+ "get-or-insert": getOrInsert,
983
+ "inline-exports": inlineExports,
984
+ "mcp-tool-layer": mcpToolLayer,
985
+ "readonly-parameters": typedRuleOf({
986
+ meta: {
987
+ type: "suggestion",
988
+ messages: { [MESSAGE_ID]: MESSAGE }
989
+ },
990
+ visitorOf
991
+ })
992
+ };
993
+ // src/features/define-lint-rules/model/intent-rule.ts
994
+ const NAMESPACE = "*";
995
+ const DEFAULT = "default";
996
+ const importedName = (specifier) => {
997
+ if (specifier.type === "ImportDefaultSpecifier") return DEFAULT;
998
+ if (specifier.type === "ImportNamespaceSpecifier") return NAMESPACE;
999
+ if (specifier.imported.type === "Identifier") return specifier.imported.name;
1000
+ return specifier.imported.value;
1001
+ };
1002
+ const isTypeOnly = (node, specifier) => node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type";
1003
+ const isBannedSpecifier = (node, ban, names) => (specifier) => !(ban.typesAllowed && isTypeOnly(node, specifier)) && Array.contains([NAMESPACE, ...names], importedName(specifier));
1004
+ const wholeImport = (node, ban) => {
1005
+ if (ban.typesAllowed && node.importKind === "type") return [];
1006
+ return [node];
1007
+ };
1008
+ const bannedIn = (node) => (ban) => {
1009
+ if (node.source.value !== ban.module) return [];
1010
+ return Option.match(ban.names, {
1011
+ onNone: () => wholeImport(node, ban),
1012
+ onSome: (names) => pipe(node.specifiers, Array.filter(isBannedSpecifier(node, ban, names)))
1013
+ });
1014
+ };
1015
+ const propertyOf = (node) => {
1016
+ if (!node.computed && node.property.type === "Identifier") return Option.some(node.property.name);
1017
+ if (node.property.type === "Literal" && typeof node.property.value === "string") return Option.some(node.property.value);
1018
+ return Option.none();
1019
+ };
1020
+ const isBannedMember = (node) => (ban) => node.object.type === "Identifier" && node.object.name === ban.object && pipe(propertyOf(node), Option.exists((property) => Array.contains(ban.properties, property)));
1021
+ const reportImports = (context, intent, node) => {
1022
+ const banned = pipe(intent.imports, Array.flatMap(bannedIn(node)));
1023
+ for (const found of banned) context.report({
1024
+ node: found,
1025
+ message: intent.message
1026
+ });
1027
+ };
1028
+ const ruleOf = (intent) => ({
1029
+ meta: { type: "problem" },
1030
+ create: (context) => ({
1031
+ ImportDeclaration: (node) => {
1032
+ reportImports(context, intent, node);
1033
+ },
1034
+ MemberExpression: (node) => {
1035
+ if (pipe(intent.members, Array.some(isBannedMember(node)))) context.report({
1036
+ node,
1037
+ message: intent.message
1038
+ });
1039
+ }
1040
+ })
1041
+ });
1042
+ // src/features/define-lint-rules/model/intents.ts
1043
+ const RUN_MESSAGE = "Run Effects with run or runner from @r_masseater/workers-tracing/effect, so their spans reach the Workers trace.";
1044
+ const RUN_FUNCTIONS = [
1045
+ "runPromise",
1046
+ "runPromiseExit",
1047
+ "runFork",
1048
+ "runCallback",
1049
+ "runSync",
1050
+ "runSyncExit",
1051
+ "runPromiseWith",
1052
+ "runPromiseExitWith",
1053
+ "runForkWith",
1054
+ "runCallbackWith",
1055
+ "runSyncWith",
1056
+ "runSyncExitWith"
1057
+ ];
1058
+ const INTENTS = {
1059
+ "ui-state-in-atoms": {
1060
+ message: "Keep UI state in effect-atom (Atom.make, useAtom, useAtomValue), so that state has one home outside the component tree. Do not use React state hooks or context.",
1061
+ imports: [{
1062
+ module: "react",
1063
+ names: Option.some([
1064
+ "useState",
1065
+ "useReducer",
1066
+ "createContext",
1067
+ "useContext"
1068
+ ]),
1069
+ typesAllowed: false
1070
+ }],
1071
+ members: []
1072
+ },
1073
+ "no-hand-written-sql": {
1074
+ message: "Build queries with the Drizzle query builder, so that their columns and types come from the schema. Do not write SQL by hand with sql.",
1075
+ imports: [{
1076
+ module: "drizzle-orm",
1077
+ names: Option.some(["sql"]),
1078
+ typesAllowed: false
1079
+ }, {
1080
+ module: "drizzle-orm/sql",
1081
+ names: Option.none(),
1082
+ typesAllowed: false
1083
+ }],
1084
+ members: []
1085
+ },
1086
+ "traced-elysia": {
1087
+ message: "Import Elysia from @r_masseater/workers-tracing/elysia, so every handle call is a span.",
1088
+ imports: [{
1089
+ module: "elysia",
1090
+ names: Option.some(["Elysia", "default"]),
1091
+ typesAllowed: true
1092
+ }],
1093
+ members: []
1094
+ },
1095
+ "traced-effect-run": {
1096
+ message: RUN_MESSAGE,
1097
+ imports: [{
1098
+ module: "effect/Effect",
1099
+ names: Option.some(RUN_FUNCTIONS),
1100
+ typesAllowed: false
1101
+ }, {
1102
+ module: "effect/ManagedRuntime",
1103
+ names: Option.some(["make"]),
1104
+ typesAllowed: false
1105
+ }],
1106
+ members: [{
1107
+ object: "Effect",
1108
+ properties: RUN_FUNCTIONS
1109
+ }, {
1110
+ object: "ManagedRuntime",
1111
+ properties: ["make"]
1112
+ }]
1113
+ },
1114
+ "platform-node-by-module": {
1115
+ message: "Import names from a module path, such as import { layer } from \"@effect/platform-node/NodeServices\". The package root loads every module, the Redis client included, and adds about 250 ms to each start.",
1116
+ imports: [{
1117
+ module: "@effect/platform-node",
1118
+ names: Option.none(),
1119
+ typesAllowed: true
1120
+ }],
1121
+ members: []
1122
+ },
1123
+ "typed-calls-not-reflect": {
1124
+ message: "Read properties and call functions through typed access, or decode untyped values with Schema at the boundary. Do not go around the types with Reflect.",
1125
+ imports: [],
1126
+ members: [{
1127
+ object: "Reflect",
1128
+ properties: ["get", "apply"]
1129
+ }]
1130
+ },
1131
+ "db-writes-in-writers": {
1132
+ message: "Write tables only from a *-writer.server.ts module, so that a table update and its revision go into the same batch. Call the writer here instead of writing through db.",
1133
+ imports: [],
1134
+ members: [{
1135
+ object: "db",
1136
+ properties: [
1137
+ "insert",
1138
+ "update",
1139
+ "delete",
1140
+ "batch",
1141
+ "run"
1142
+ ]
1143
+ }]
1144
+ }
1145
+ };
1059
1146
  // src/features/define-lint-rules/model/plugin.ts
1060
1147
  const mschLintPlugin = {
1061
1148
  meta: { name: "msch-lint" },
1062
1149
  rules: {
1063
- "array-from-async": arrayFromAsync,
1064
- "ecosystem-readers": ecosystemReaders,
1065
- "get-or-insert": getOrInsert,
1066
- "inline-exports": inlineExports,
1067
- "mcp-tool-layer": mcpToolLayer,
1068
- "readonly-parameters": withTypeInformation({
1069
- meta: {
1070
- type: "suggestion",
1071
- messages: { [MESSAGE_ID]: MESSAGE }
1072
- },
1073
- create: (context) => pipe(Option.fromNullishOr(context.sourceCode.parserServices), Option.match({
1074
- onNone: () => ({}),
1075
- onSome: (services) => visitorOf(context, services)
1076
- }))
1077
- }),
1150
+ ...CODED_RULES,
1078
1151
  ...pipe(INTENTS, Record.map(ruleOf))
1079
1152
  }
1080
1153
  };