@r_masseater/msch 0.53.1 → 0.57.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.
Files changed (70) hide show
  1. package/README.md +18 -18
  2. package/dist/app-B22Gq0no.mjs +2120 -0
  3. package/dist/app-B22Gq0no.mjs.map +1 -0
  4. package/dist/cargo-inputs.d.mts +1 -1
  5. package/dist/cargo-inputs.mjs +4 -9
  6. package/dist/cargo-inputs.mjs.map +1 -1
  7. package/dist/changed.mjs +90 -19
  8. package/dist/changed.mjs.map +1 -1
  9. package/dist/{check-upstream-exits-DYxWDyHC.mjs → check-upstream-exits-DsBS7bui.mjs} +2 -2
  10. package/dist/check-upstream-exits-DsBS7bui.mjs.map +1 -0
  11. package/dist/cli.mjs +469 -385
  12. package/dist/cli.mjs.map +1 -1
  13. package/dist/config.d.mts +1 -1
  14. package/dist/config.mjs +3 -3
  15. package/dist/config.mjs.map +1 -1
  16. package/dist/credential-broker-D8sFyowJ.mjs +105 -0
  17. package/dist/credential-broker-D8sFyowJ.mjs.map +1 -0
  18. package/dist/decision-rules.d.mts +1 -1
  19. package/dist/decision-rules.mjs +1 -1
  20. package/dist/{define-lint-preset-CecEvjVf.mjs → define-lint-preset-DeLIlDuA.mjs} +8 -643
  21. package/dist/define-lint-preset-DeLIlDuA.mjs.map +1 -0
  22. package/dist/{dependencies-DCJv7YcW.mjs → dependencies-CbvZost8.mjs} +11 -7
  23. package/dist/dependencies-CbvZost8.mjs.map +1 -0
  24. package/dist/exits.mjs +4 -5
  25. package/dist/exits.mjs.map +1 -1
  26. package/dist/{index-B2X8WhBt.d.mts → index-Cwnhs7VE.d.mts} +5 -51
  27. package/dist/library.d.mts +18 -0
  28. package/dist/library.mjs +28 -0
  29. package/dist/library.mjs.map +1 -0
  30. package/dist/lint-rules.mjs +353 -110
  31. package/dist/lint-rules.mjs.map +1 -1
  32. package/dist/lint.d.mts +2 -2
  33. package/dist/lint.mjs +1 -1
  34. package/dist/locked-inputs-DMSoGCa-.mjs +20 -0
  35. package/dist/locked-inputs-DMSoGCa-.mjs.map +1 -0
  36. package/dist/locked-inputs.d.mts +2 -3
  37. package/dist/locked-inputs.mjs +1 -20
  38. package/dist/oxlint.mjs +29 -14
  39. package/dist/oxlint.mjs.map +1 -1
  40. package/dist/{package-LeBO9czg.mjs → package-DZbqpZfs.mjs} +6 -6
  41. package/dist/package-DZbqpZfs.mjs.map +1 -0
  42. package/dist/{problem-CzOlOb5f.mjs → problem-Q4Zyi4PR.mjs} +10 -6
  43. package/dist/problem-Q4Zyi4PR.mjs.map +1 -0
  44. package/dist/{project-C4uzq7_4.mjs → project-CIY_lNiT.mjs} +36 -14
  45. package/dist/project-CIY_lNiT.mjs.map +1 -0
  46. package/dist/publish.mjs +629 -305
  47. package/dist/publish.mjs.map +1 -1
  48. package/dist/runtime-LT40e_l3.mjs +28 -0
  49. package/dist/runtime-LT40e_l3.mjs.map +1 -0
  50. package/dist/{syntax-3AJkpCcs.mjs → syntax-BNRNY74H.mjs} +13 -4
  51. package/dist/syntax-BNRNY74H.mjs.map +1 -0
  52. package/dist/wake.d.mts +1 -0
  53. package/dist/wake.mjs +25 -0
  54. package/dist/wake.mjs.map +1 -0
  55. package/dist/workspace-settings.mjs +5 -5
  56. package/dist/workspace-settings.mjs.map +1 -1
  57. package/package.json +48 -41
  58. package/skills/{publishing → msch-publishing}/SKILL.md +10 -2
  59. package/skills/{repository-config → msch-repository-config}/SKILL.md +5 -2
  60. package/skills/{workspace-settings → msch-workspace-settings}/SKILL.md +4 -3
  61. package/dist/check-upstream-exits-DYxWDyHC.mjs.map +0 -1
  62. package/dist/define-lint-preset-CecEvjVf.mjs.map +0 -1
  63. package/dist/dependencies-DCJv7YcW.mjs.map +0 -1
  64. package/dist/locked-inputs.mjs.map +0 -1
  65. package/dist/package-LeBO9czg.mjs.map +0 -1
  66. package/dist/problem-CzOlOb5f.mjs.map +0 -1
  67. package/dist/project-C4uzq7_4.mjs.map +0 -1
  68. package/dist/runtime-DFsdNYI0.mjs +0 -29
  69. package/dist/runtime-DFsdNYI0.mjs.map +0 -1
  70. package/dist/syntax-3AJkpCcs.mjs.map +0 -1
@@ -1,4 +1,120 @@
1
- import { Array, Boolean, Option, Predicate, Record, Schema, String, pipe } from "effect";
1
+ import { n as baseName } from "./app-B22Gq0no.mjs";
2
+ import { Array, Boolean, Match, Option, Predicate, Record, Schema, String as String$1, pipe } from "effect";
3
+ import { isTypeNode } from "typescript/ast/is";
4
+ import { SymbolFlags } from "typescript/sync";
5
+ import { withTypeInformation } from "@r_masseater/oxlint-typed-rules";
6
+ // src/features/define-lint-rules/model/get-or-insert-ast.ts
7
+ const START$3 = 0;
8
+ const END$3 = 1;
9
+ const KEY = 0;
10
+ const VALUE = 1;
11
+ const ONE$2 = 1;
12
+ const RangeSchema$1 = Schema.Tuple([Schema.Finite, Schema.Finite]);
13
+ const RangedSchema$1 = Schema.Struct({ range: RangeSchema$1 });
14
+ const decodeRanged = Schema.decodeUnknownOption(RangedSchema$1);
15
+ const IdentifierSchema$1 = Schema.Struct({
16
+ type: Schema.Literal("Identifier"),
17
+ name: Schema.String
18
+ });
19
+ const MemberSchema = Schema.Struct({
20
+ type: Schema.Literal("MemberExpression"),
21
+ computed: Schema.Literal(false),
22
+ object: RangedSchema$1,
23
+ property: IdentifierSchema$1
24
+ });
25
+ const MemberCallSchema = Schema.Struct({
26
+ type: Schema.Literal("CallExpression"),
27
+ callee: MemberSchema,
28
+ arguments: Schema.Array(RangedSchema$1)
29
+ });
30
+ const decodeMemberCall = Schema.decodeUnknownOption(MemberCallSchema);
31
+ const decodeCall = Schema.decodeUnknownOption(Schema.Struct({
32
+ type: Schema.Literal("CallExpression"),
33
+ callee: RangedSchema$1,
34
+ arguments: Schema.Array(Schema.Unknown)
35
+ }));
36
+ const decodeBlock = Schema.decodeUnknownOption(Schema.Struct({
37
+ type: Schema.Literal("BlockStatement"),
38
+ body: Schema.Array(Schema.Unknown)
39
+ }));
40
+ const decodeExpressionStatement = Schema.decodeUnknownOption(Schema.Struct({
41
+ type: Schema.Literal("ExpressionStatement"),
42
+ expression: Schema.Unknown
43
+ }));
44
+ const decodeReturn = Schema.decodeUnknownOption(Schema.Struct({
45
+ type: Schema.Literal("ReturnStatement"),
46
+ argument: RangedSchema$1
47
+ }));
48
+ const decodeTyped = Schema.decodeUnknownOption(Schema.Struct({ type: Schema.String }));
49
+ const textOf$1 = (scope) => (node) => String$1.slice(node.range[START$3], node.range[END$3])(scope.text);
50
+ const textOfNode = (scope) => (node) => pipe(decodeRanged(node), Option.map(textOf$1(scope)));
51
+ const accessOf = (scope) => (method) => (node) => pipe(decodeMemberCall(node), Option.filter((call) => call.callee.property.name === method), Option.flatMap((call) => pipe(Array.get(call.arguments, KEY), Option.map((key) => ({
52
+ map: textOf$1(scope)(call.callee.object),
53
+ key: textOf$1(scope)(key),
54
+ value: pipe(Array.get(call.arguments, VALUE), Option.map(textOf$1(scope)))
55
+ })))));
56
+ const sameEntry = (left) => (right) => left.map === right.map && left.key === right.key;
57
+ const calleeMatches = (scope) => (pattern) => (node) => pipe(decodeCall(node), Option.filter((call) => pattern.test(textOf$1(scope)(call.callee))), Option.map((call) => call.arguments));
58
+ const expressionOf = (statement) => pipe(decodeExpressionStatement(statement), Option.map((found) => found.expression));
59
+ const returnedText = (scope) => (statement) => pipe(decodeReturn(statement), Option.map((found) => textOf$1(scope)(found.argument)));
60
+ const bodyOf = (node) => pipe(decodeBlock(node), Option.map((block) => block.body));
61
+ const onlyStatement = (statement) => Option.match(bodyOf(statement), {
62
+ onNone: () => Option.some(statement),
63
+ onSome: (body) => Option.flatMap(Option.liftPredicate(body, (all) => all.length === ONE$2), Array.head)
64
+ });
65
+ const typeOf = (node) => pipe(decodeTyped(node), Option.match({
66
+ onNone: () => "",
67
+ onSome: (found) => found.type
68
+ }));
69
+ const parentOf = (node) => pipe(Option.liftPredicate(node, Predicate.hasProperty("parent")), Option.flatMap((found) => Option.fromNullishOr(found.parent)));
70
+ const childrenOf$1 = (keys, node) => pipe(Option.liftPredicate(node, Predicate.isObject), Option.match({
71
+ onNone: () => [],
72
+ onSome: (found) => pipe(keys[typeOf(found)] ?? [], Array.flatMap((key) => pipe(Option.liftPredicate(found, Predicate.hasProperty(key)), Option.match({
73
+ onNone: () => [],
74
+ onSome: (owner) => Array.ensure(owner[key])
75
+ }))), Array.filter(Predicate.isObject))
76
+ }));
77
+ const descendants = (keys) => (node) => [node, ...pipe(childrenOf$1(keys, node), Array.flatMap(descendants(keys)))];
78
+ const accessesIn = (scope) => (method) => (node) => pipe(descendants(scope.keys)(node), Array.map(accessOf(scope)(method)), Array.getSomes);
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.";
81
+ const ONE$1 = 1;
82
+ const DeclarationSchema = Schema.Struct({
83
+ type: Schema.Literal("VariableDeclaration"),
84
+ declarations: Schema.Array(Schema.Unknown)
85
+ });
86
+ const decodeLoop = Schema.decodeUnknownOption(Schema.Struct({
87
+ type: Schema.Literal("ForOfStatement"),
88
+ await: Schema.Literal(true),
89
+ left: DeclarationSchema,
90
+ body: Schema.Unknown
91
+ }));
92
+ const PushNameSchema = Schema.Struct({
93
+ type: Schema.Literal("Identifier"),
94
+ name: Schema.Literal("push")
95
+ });
96
+ const PushCalleeSchema = Schema.Struct({
97
+ type: Schema.Literal("MemberExpression"),
98
+ computed: Schema.Literal(false),
99
+ property: PushNameSchema
100
+ });
101
+ const ArgumentSchema = Schema.Struct({ type: Schema.String });
102
+ const decodePush = Schema.decodeUnknownOption(Schema.Struct({
103
+ type: Schema.Literal("CallExpression"),
104
+ callee: PushCalleeSchema,
105
+ arguments: Schema.Array(ArgumentSchema)
106
+ }));
107
+ const pushesOne = (statement) => pipe(expressionOf(statement), Option.flatMap(decodePush), Option.exists((call) => call.arguments.length === ONE$1 && !pipe(call.arguments, Array.some((argument) => argument.type === "SpreadElement"))));
108
+ const collectsByHand = (node) => pipe(decodeLoop(node), Option.filter((loop) => loop.left.declarations.length === ONE$1), Option.flatMap((loop) => onlyStatement(loop.body)), Option.exists(pushesOne));
109
+ const arrayFromAsync = {
110
+ meta: { type: "suggestion" },
111
+ create: (context) => ({ ForOfStatement: (node) => {
112
+ if (collectsByHand(node)) context.report({
113
+ node,
114
+ message: MESSAGE$4
115
+ });
116
+ } })
117
+ };
2
118
  // src/features/define-lint-rules/model/ecosystem-readers.ts
3
119
  const ECOSYSTEM_FILES = [
4
120
  {
@@ -54,8 +170,6 @@ const PARSER_CALLS = {
54
170
  typescript: Option.none(),
55
171
  yaml: Option.none()
56
172
  };
57
- const SEPARATOR$1 = "/";
58
- const baseNameOf = (text) => pipe(String.split(text, SEPARATOR$1), Array.last, Option.getOrElse(() => text));
59
173
  const importedModules = (statements) => pipe(statements, Array.filter((statement) => statement.type === "ImportDeclaration"), Array.map((declaration) => declaration.source.value));
60
174
  const parserIn = (context) => (format) => {
61
175
  const imported = importedModules(context.sourceCode.ast.body);
@@ -64,7 +178,7 @@ const parserIn = (context) => (format) => {
64
178
  return pipe(Record.get(PARSER_CALLS, format), Option.flatten, Option.flatMap((pattern) => Option.fromNullishOr(pattern.exec(context.sourceCode.text))), Option.map(([call]) => call));
65
179
  };
66
180
  const messageFor = (context) => (text) => {
67
- const name = baseNameOf(text);
181
+ const name = baseName(text);
68
182
  return pipe(ECOSYSTEM_FILES, Array.findFirst((entry) => entry.name.test(name)), Option.flatMap(({ format, reader }) => pipe(parserIn(context)(format), Option.map((parser) => `${name} has an official reader: ${reader}. Read it with that instead of parsing it with ${parser}, so that the file means what its own tool says it means.`))));
69
183
  };
70
184
  const ecosystemReaders = {
@@ -86,81 +200,8 @@ const ecosystemReaders = {
86
200
  }
87
201
  })
88
202
  };
89
- // src/features/define-lint-rules/model/get-or-insert-ast.ts
90
- const START$3 = 0;
91
- const END$3 = 1;
92
- const KEY = 0;
93
- const VALUE = 1;
94
- const ONE$1 = 1;
95
- const RangeSchema$1 = Schema.Tuple([Schema.Finite, Schema.Finite]);
96
- const RangedSchema$1 = Schema.Struct({ range: RangeSchema$1 });
97
- const decodeRanged = Schema.decodeUnknownOption(RangedSchema$1);
98
- const IdentifierSchema$1 = Schema.Struct({
99
- type: Schema.Literal("Identifier"),
100
- name: Schema.String
101
- });
102
- const MemberSchema = Schema.Struct({
103
- type: Schema.Literal("MemberExpression"),
104
- computed: Schema.Literal(false),
105
- object: RangedSchema$1,
106
- property: IdentifierSchema$1
107
- });
108
- const MemberCallSchema = Schema.Struct({
109
- type: Schema.Literal("CallExpression"),
110
- callee: MemberSchema,
111
- arguments: Schema.Array(RangedSchema$1)
112
- });
113
- const decodeMemberCall = Schema.decodeUnknownOption(MemberCallSchema);
114
- const decodeCall = Schema.decodeUnknownOption(Schema.Struct({
115
- type: Schema.Literal("CallExpression"),
116
- callee: RangedSchema$1,
117
- arguments: Schema.Array(Schema.Unknown)
118
- }));
119
- const decodeBlock = Schema.decodeUnknownOption(Schema.Struct({
120
- type: Schema.Literal("BlockStatement"),
121
- body: Schema.Array(Schema.Unknown)
122
- }));
123
- const decodeExpressionStatement = Schema.decodeUnknownOption(Schema.Struct({
124
- type: Schema.Literal("ExpressionStatement"),
125
- expression: Schema.Unknown
126
- }));
127
- const decodeReturn = Schema.decodeUnknownOption(Schema.Struct({
128
- type: Schema.Literal("ReturnStatement"),
129
- argument: RangedSchema$1
130
- }));
131
- const decodeTyped = Schema.decodeUnknownOption(Schema.Struct({ type: Schema.String }));
132
- const textOf$1 = (scope) => (node) => String.slice(node.range[START$3], node.range[END$3])(scope.text);
133
- const textOfNode = (scope) => (node) => pipe(decodeRanged(node), Option.map(textOf$1(scope)));
134
- const accessOf = (scope) => (method) => (node) => pipe(decodeMemberCall(node), Option.filter((call) => call.callee.property.name === method), Option.flatMap((call) => pipe(Array.get(call.arguments, KEY), Option.map((key) => ({
135
- map: textOf$1(scope)(call.callee.object),
136
- key: textOf$1(scope)(key),
137
- value: pipe(Array.get(call.arguments, VALUE), Option.map(textOf$1(scope)))
138
- })))));
139
- const sameEntry = (left) => (right) => left.map === right.map && left.key === right.key;
140
- const calleeMatches = (scope) => (pattern) => (node) => pipe(decodeCall(node), Option.filter((call) => pattern.test(textOf$1(scope)(call.callee))), Option.map((call) => call.arguments));
141
- const expressionOf = (statement) => pipe(decodeExpressionStatement(statement), Option.map((found) => found.expression));
142
- const returnedText = (scope) => (statement) => pipe(decodeReturn(statement), Option.map((found) => textOf$1(scope)(found.argument)));
143
- const bodyOf = (node) => pipe(decodeBlock(node), Option.map((block) => block.body));
144
- const onlyStatement = (statement) => Option.match(bodyOf(statement), {
145
- onNone: () => Option.some(statement),
146
- onSome: (body) => Option.flatMap(Option.liftPredicate(body, (all) => all.length === ONE$1), Array.head)
147
- });
148
- const typeOf = (node) => pipe(decodeTyped(node), Option.match({
149
- onNone: () => "",
150
- onSome: (found) => found.type
151
- }));
152
- const parentOf = (node) => pipe(Option.liftPredicate(node, Predicate.hasProperty("parent")), Option.flatMap((found) => Option.fromNullishOr(found.parent)));
153
- const childrenOf$1 = (keys, node) => pipe(Option.liftPredicate(node, Predicate.isObject), Option.match({
154
- onNone: () => [],
155
- onSome: (found) => pipe(keys[typeOf(found)] ?? [], Array.flatMap((key) => pipe(Option.liftPredicate(found, Predicate.hasProperty(key)), Option.match({
156
- onNone: () => [],
157
- onSome: (owner) => Array.ensure(owner[key])
158
- }))), Array.filter(Predicate.isObject))
159
- }));
160
- const descendants = (keys) => (node) => [node, ...pipe(childrenOf$1(keys, node), Array.flatMap(descendants(keys)))];
161
- const accessesIn = (scope) => (method) => (node) => pipe(descendants(scope.keys)(node), Array.map(accessOf(scope)(method)), Array.getSomes);
162
203
  // src/features/define-lint-rules/model/get-or-insert.ts
163
- const MESSAGE$2 = "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.";
204
+ 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.";
164
205
  const ONE = 1;
165
206
  const TWO = 2;
166
207
  const OPTION_FROM = /^(?:Option\.)?from(?:NullishOr|UndefinedOr|Nullable)$/u;
@@ -269,17 +310,17 @@ const getOrInsert = {
269
310
  IfStatement: (node) => {
270
311
  if (isHasGuard(scope, node)) context.report({
271
312
  node,
272
- message: MESSAGE$2
313
+ message: MESSAGE$3
273
314
  });
274
315
  },
275
316
  BlockStatement: (node) => {
276
317
  for (const index of fallbackIndices(scope, node.body)) for (const statement of Option.toArray(Array.get(node.body, index))) context.report({
277
318
  node: statement,
278
- message: MESSAGE$2
319
+ message: MESSAGE$3
279
320
  });
280
321
  if (isMemoized(scope, node)) context.report({
281
322
  node,
282
- message: MESSAGE$2
323
+ message: MESSAGE$3
283
324
  });
284
325
  }
285
326
  };
@@ -334,15 +375,15 @@ const START$2 = 0;
334
375
  const END$2 = 1;
335
376
  const NEXT = 1;
336
377
  const NEWLINE$1 = "\n";
337
- const textOf = (source) => (range) => pipe(source.text, String.slice(range[START$2], range[END$2]));
338
- const lineStartOf = (source, offset) => pipe(source.text, String.slice(START$2, offset), String.lastIndexOf(NEWLINE$1), Option.match({
378
+ const textOf = (source) => (range) => pipe(source.text, String$1.slice(range[START$2], range[END$2]));
379
+ const lineStartOf = (source, offset) => pipe(source.text, String$1.slice(START$2, offset), String$1.lastIndexOf(NEWLINE$1), Option.match({
339
380
  onNone: () => START$2,
340
381
  onSome: (index) => index + NEXT
341
382
  }));
342
383
  const indentOf = (source) => (offset) => textOf(source)([lineStartOf(source, offset), offset]);
343
384
  const lineRangeOf = (source) => (range) => {
344
- const indented = String.isEmpty(String.trim(indentOf(source)(range[START$2])));
345
- const endsLine = pipe(source.text, String.charAt(range[END$2]), Option.contains(NEWLINE$1));
385
+ const indented = String$1.isEmpty(String$1.trim(indentOf(source)(range[START$2])));
386
+ const endsLine = pipe(source.text, String$1.charAt(range[END$2]), Option.contains(NEWLINE$1));
346
387
  return [Boolean.match(indented, {
347
388
  onFalse: () => range[START$2],
348
389
  onTrue: () => lineStartOf(source, range[START$2])
@@ -351,7 +392,7 @@ const lineRangeOf = (source) => (range) => {
351
392
  onTrue: () => range[END$2] + NEXT
352
393
  })];
353
394
  };
354
- const commentsBefore = (source) => (start) => pipe(source.comments, Array.findLast((comment) => comment[END$2] <= start), Option.filter((comment) => String.isEmpty(String.trim(textOf(source)([comment[END$2], start])))), Option.match({
395
+ const commentsBefore = (source) => (start) => pipe(source.comments, Array.findLast((comment) => comment[END$2] <= start), Option.filter((comment) => String$1.isEmpty(String$1.trim(textOf(source)([comment[END$2], start])))), Option.match({
355
396
  onNone: () => [],
356
397
  onSome: (comment) => [...commentsBefore(source)(comment[START$2]), comment]
357
398
  }));
@@ -421,11 +462,11 @@ const replacementOf = (source, list, resolved) => {
421
462
  const removedOf = (source, reexports) => pipe(statementsOf(reexports), Array.filter((statement) => pipe(statement.bindings, Array.every((binding) => pipe(reexports, Array.some((entry) => entry.statement === statement && entry.binding === binding)) && !pipe(source.usedOutside, Array.contains(binding.local))))));
422
463
  const prefixOf = (source, comments) => (statement) => {
423
464
  const start = statement.range[START$1];
424
- if (String.isEmpty(comments) || pipe(leadingTextOf(source)(start), String.includes(comments))) return EXPORT;
465
+ if (String$1.isEmpty(comments) || pipe(leadingTextOf(source)(start), String$1.includes(comments))) return EXPORT;
425
466
  return `${comments}${NEWLINE}${indentOf(source)(start)}${EXPORT}`;
426
467
  };
427
468
  const listEditOf = (source, list, text) => {
428
- if (!String.isEmpty(text)) return {
469
+ if (!String$1.isEmpty(text)) return {
429
470
  range: list.range,
430
471
  text
431
472
  };
@@ -611,28 +652,28 @@ const exportListOf = (node) => pipe(decodeList(node), Option.filter((list) => Ar
611
652
  body: pipe(list.parent.body, Array.map(statementOf), Array.getSomes)
612
653
  })));
613
654
  // src/features/define-lint-rules/model/inline-exports.ts
614
- const MESSAGE$1 = "export は宣言に付ける(export const・export function など)。ファイルの末尾で export { … } にまとめない。";
655
+ const MESSAGE$2 = "export は宣言に付ける(export const・export function など)。ファイルの末尾で export { … } にまとめない。";
615
656
  const START = 0;
616
657
  const END = 1;
617
658
  const outside = (list) => (range) => range[START] < list[START] || range[END] > list[END];
618
659
  const usedOutside = (context, list) => pipe(context.sourceCode.scopeManager.scopes, Array.flatMap((scope) => scope.variables), Array.filter((variable) => pipe(variable.references, Array.some((reference) => outside(list.range)(reference.identifier.range)))), Array.map((variable) => variable.name));
619
- const sourceOf = (context, list) => ({
660
+ const sourceOf$1 = (context, list) => ({
620
661
  text: context.sourceCode.text,
621
662
  comments: pipe(context.sourceCode.getAllComments(), Array.map((comment) => comment.range)),
622
663
  usedOutside: usedOutside(context, list)
623
664
  });
624
665
  const reportList = (context, node, list) => {
625
- pipe(editsOf(sourceOf(context, list))(list), Option.match({
666
+ pipe(editsOf(sourceOf$1(context, list))(list), Option.match({
626
667
  onNone: () => {
627
668
  context.report({
628
669
  node,
629
- message: MESSAGE$1
670
+ message: MESSAGE$2
630
671
  });
631
672
  },
632
673
  onSome: (edits) => {
633
674
  context.report({
634
675
  node,
635
- message: MESSAGE$1,
676
+ message: MESSAGE$2,
636
677
  fix: (fixer) => pipe(edits, Array.map((edit) => fixer.replaceTextRange([edit.range[START], edit.range[END]], edit.text)))
637
678
  });
638
679
  }
@@ -803,35 +844,237 @@ const INTENTS = {
803
844
  };
804
845
  // src/features/define-lint-rules/model/mcp-tool-layer.ts
805
846
  const SOURCE = "/src/";
806
- const SEPARATOR = "/";
847
+ const SEPARATOR$1 = "/";
807
848
  const WINDOWS_SEPARATOR = "\\";
808
849
  const TOOL_LAYERS = ["features", "shared"];
809
850
  const TEST_FILE = /\.test(?:\.support)?\.[cm]?[jt]sx?$/u;
810
851
  const METHOD = "registerTool";
811
- const MESSAGE = "Register an MCP tool in the features slice of the operation it performs. A tool is one operation, so app/ only composes the slices' register functions and entities/ only holds the data they share.";
812
- const layerIn = (path) => pipe(String.lastIndexOf(SOURCE)(path), Option.flatMap((index) => pipe(String.slice(index + 5)(path), String.split(SEPARATOR), Array.head)));
813
- const layerOf = (filename) => layerIn(String.replaceAll(WINDOWS_SEPARATOR, SEPARATOR)(filename));
852
+ const MESSAGE$1 = "Register an MCP tool in the features slice of the operation it performs. A tool is one operation, so app/ only composes the slices' register functions and entities/ only holds the data they share.";
853
+ const layerIn = (path) => pipe(String$1.lastIndexOf(SOURCE)(path), Option.flatMap((index) => pipe(String$1.slice(index + 5)(path), String$1.split(SEPARATOR$1), Array.head)));
854
+ const layerOf = (filename) => layerIn(String$1.replaceAll(WINDOWS_SEPARATOR, SEPARATOR$1)(filename));
814
855
  const outsideToolLayers = (filename) => !TEST_FILE.test(filename) && Option.exists(layerOf(filename), (layer) => !Array.contains(TOOL_LAYERS, layer));
856
+ const mcpToolLayer = {
857
+ meta: { type: "problem" },
858
+ create: (context) => {
859
+ if (!outsideToolLayers(context.filename)) return {};
860
+ return { CallExpression: (node) => {
861
+ const { callee } = node;
862
+ if (callee.type === "MemberExpression" && callee.property.type === "Identifier" && callee.property.name === METHOD) context.report({
863
+ node: callee.property,
864
+ message: MESSAGE$1
865
+ });
866
+ } };
867
+ }
868
+ };
869
+ // src/features/define-lint-rules/model/declared-outside.ts
870
+ const origins = /* @__PURE__ */ new WeakMap();
871
+ const readonlyForms = /* @__PURE__ */ new WeakMap();
872
+ const fileOrigin = (project, handle) => pipe(Option.fromNullishOr(project.program.getSourceFileMetadataByPath(handle.path)), Option.flatMap(({ isDefaultLibrary, isFromExternalLibrary }) => {
873
+ if (isDefaultLibrary) return Option.some("builtin");
874
+ if (isFromExternalLibrary) return Option.some("package");
875
+ return Option.none();
876
+ }));
877
+ const declarationOrigin = (project) => (handle) => pipe(fileOrigin(project, handle), Option.orElse(() => pipe(Option.fromNullishOr(handle.resolve(project)), Option.filter((node) => node.getSourceFile().isDeclarationFile), Option.as("package"))), Option.getOrElse(() => "own"));
878
+ const originOf = (project) => (symbol) => origins.getOrInsertComputed(symbol, () => {
879
+ const found = pipe(symbol.declarations, Array.map(declarationOrigin(project)));
880
+ if (Array.contains(found, "builtin")) return "builtin";
881
+ if (Array.contains(found, "package")) return "package";
882
+ return "own";
883
+ });
884
+ const builtinNamed = (project) => (name) => pipe(Option.fromNullishOr(project.checker.resolveName(name, SymbolFlags.Type)), Option.filter((symbol) => originOf(project)(symbol) === "builtin"), Option.as(name));
885
+ const readonlyFormOf = (project) => (name) => readonlyForms.getOrInsertComputed(project, () => /* @__PURE__ */ new Map()).getOrInsertComputed(name, () => pipe([`Readonly${name}`, `${name}ReadOnly`], Array.findFirst(builtinNamed(project))));
886
+ const MUTABLE_ARRAY = "Array";
887
+ const PRIVATE_NAME = "__#";
888
+ const SYMBOL_NAME = "__@";
889
+ const here = (mutability) => Option.some({
890
+ path: [],
891
+ mutability
892
+ });
893
+ const under = (segment) => (part) => ({
894
+ ...part,
895
+ path: [segment, ...part.path]
896
+ });
897
+ const firstPart = (search, types) => pipe(types, Array.findFirst(search.partOf));
898
+ const formOf = (project) => (name) => pipe(readonlyFormOf(project)(name), Option.flatMap((readonlyName) => here({
899
+ kind: "form",
900
+ name,
901
+ readonlyName
902
+ })));
903
+ const isOpaqueAlias = (project, type) => pipe(Option.fromNullishOr(type.getAliasSymbol()), Option.exists((alias) => {
904
+ const origin = originOf(project)(alias);
905
+ return origin === "package" || origin === "builtin" && Array.isReadonlyArrayEmpty(type.getAliasTypeArguments());
906
+ }));
907
+ const isNamed = (type) => type.isClassOrInterface() || type.isTypeReference() && type.getTarget().isClassOrInterface();
908
+ const declaredOutside = (project, type) => pipe(Option.fromNullishOr(type.getSymbol()), Option.flatMap((symbol) => {
909
+ const origin = originOf(project)(symbol);
910
+ if (origin === "package") return Option.some(Option.none());
911
+ if (origin === "own" || !isNamed(type)) return Option.none();
912
+ return Option.some(formOf(project)(symbol.name));
913
+ }));
914
+ const isOutside = (project, type) => isOpaqueAlias(project, type) || type.isObjectType() && Option.exists(declaredOutside(project, type), Option.isNone);
915
+ const sourceOf = (type) => {
916
+ if (!type.isMappedType()) return Option.none();
917
+ const template = type.getTemplateType();
918
+ if (!template.isIndexedAccessType()) return Option.none();
919
+ return Option.some(template.getObjectType());
920
+ };
921
+ const takenFromOutside = (project) => (type) => {
922
+ if (isOutside(project, type)) return pipe(type.getProperties(), Array.map((property) => property.name));
923
+ if (type.isUnionType() || type.isIntersectionType()) return pipe(type.getTypes(), Array.flatMap(takenFromOutside(project)));
924
+ return pipe(sourceOf(type), Option.map(takenFromOutside(project)), Option.getOrElse(() => []));
925
+ };
926
+ const elementsPart = (search, type) => {
927
+ if (!type.isTypeReference()) return Option.none();
928
+ return pipe(firstPart(search, search.project.checker.getTypeArguments(type)), Option.map(under("[]")));
929
+ };
930
+ const arrayPart = (search, type) => {
931
+ if (pipe(Option.fromNullishOr(type.getSymbol()), Option.exists((symbol) => symbol.name === MUTABLE_ARRAY))) return here({ kind: "array" });
932
+ return elementsPart(search, type);
933
+ };
934
+ const tuplePart = (search, type) => {
935
+ if (type.isTupleType() && !type.getTarget().readonly) return here({ kind: "tuple" });
936
+ return elementsPart(search, type);
937
+ };
938
+ const named = (prefix) => (property) => pipe(String(property.escapedName), String$1.startsWith(prefix));
939
+ const isWritable = (checker) => (property) => !checker.isReadonlySymbol(property) && !named(PRIVATE_NAME)(property);
940
+ const isStringNamed = (property) => !named(PRIVATE_NAME)(property) && !named(SYMBOL_NAME)(property);
941
+ const declaredIn = (project, origin) => (property) => originOf(project)(property) === origin;
942
+ const inheritedForm = (project) => (property) => pipe(Option.fromNullishOr(property.getParent()), Option.flatMap((owner) => formOf(project)(owner.name)));
943
+ const propertyTypesPart = (search, properties) => {
944
+ const judged = pipe(properties, Array.filter(isStringNamed));
945
+ return pipe(Array.zip(judged, search.project.checker.getTypeOfSymbol(judged)), Array.findFirst(([property, type]) => pipe(search.partOf(type), Option.map(under(property.name)))));
946
+ };
947
+ const indexPart = (search, type) => pipe(type.getIndexInfos(), Array.findFirst((info) => {
948
+ if (!info.isReadonly) return here({ kind: "index" });
949
+ return pipe(search.partOf(info.valueType), Option.map(under("[]")));
950
+ }));
951
+ const membersPart = (search, type) => {
952
+ const { project } = search;
953
+ const properties = type.getProperties();
954
+ const taken = pipe(sourceOf(type), Option.map(takenFromOutside(project)), Option.getOrElse(() => []));
955
+ const own = pipe(properties, Array.filter((property) => declaredIn(project, "own")(property) && !Array.contains(taken, property.name)));
956
+ return pipe(own, Array.findFirst(isWritable(project.checker)), Option.map((property) => ({
957
+ path: [property.name],
958
+ mutability: { kind: "property" }
959
+ })), Option.orElse(() => pipe(properties, Array.filter(declaredIn(project, "builtin")), Array.findFirst(inheritedForm(project)))), Option.orElse(() => propertyTypesPart(search, own)), Option.orElse(() => indexPart(search, type)));
960
+ };
961
+ const isFunction = (type) => Array.isReadonlyArrayNonEmpty(type.getCallSignatures()) && Array.isReadonlyArrayEmpty(type.getProperties());
962
+ const objectPart = (search, type) => {
963
+ if (isFunction(type)) return Option.none();
964
+ if (search.project.checker.isArrayType(type)) return arrayPart(search, type);
965
+ if (type.isTupleType()) return tuplePart(search, type);
966
+ return pipe(declaredOutside(search.project, type), Option.getOrElse(() => membersPart(search, type)));
967
+ };
968
+ const typePart = (search, type) => {
969
+ if (isOpaqueAlias(search.project, type)) return Option.none();
970
+ if (type.isUnionType() || type.isIntersectionType()) return firstPart(search, type.getTypes());
971
+ if (type.isConditionalType()) return firstPart(search, [type.getTrueType(), type.getFalseType()]);
972
+ if (!type.isObjectType()) return Option.none();
973
+ return objectPart(search, type);
974
+ };
975
+ const writablePartOf = (project) => (type) => {
976
+ const seen = /* @__PURE__ */ new Set();
977
+ const partOf = (inner) => {
978
+ if (seen.has(inner)) return Option.none();
979
+ seen.add(inner);
980
+ return typePart({
981
+ project,
982
+ partOf
983
+ }, inner);
984
+ };
985
+ return partOf(type);
986
+ };
987
+ // src/features/define-lint-rules/model/readonly-parameters.ts
988
+ const MESSAGE = "A function must not be able to change its arguments, but {{part}}. Declare the parameter with a read-only type. Types declared by a package or by the language are exempt unless the language has a read-only form of them.";
989
+ const MESSAGE_ID = "shouldBeReadonly";
990
+ const WHOLE = "the type";
991
+ const SEPARATOR = ".";
992
+ const TAGGABLE = [
993
+ "string",
994
+ "number",
995
+ "bigint"
996
+ ];
997
+ const isBrandObject = (type) => type.isObjectType() && Array.isReadonlyArrayEmpty(type.getCallSignatures()) && Array.isReadonlyArrayEmpty(type.getConstructSignatures());
998
+ const isTaggable = (type) => type.isLiteralType() || type.isTemplateLiteralType() || type.isIntrinsicType() && Array.contains(TAGGABLE, type.intrinsicName);
999
+ const isBrandedLiteral = (type) => {
1000
+ if (!type.isIntersectionType()) return false;
1001
+ const parts = type.getTypes();
1002
+ const objects = pipe(parts, Array.filter(isBrandObject));
1003
+ const primitives = pipe(parts, Array.filter(isTaggable));
1004
+ return Array.isReadonlyArrayNonEmpty(objects) && Array.isReadonlyArrayNonEmpty(primitives) && objects.length + primitives.length === parts.length;
1005
+ };
1006
+ const isBrandedLiteralLike = (type) => {
1007
+ if (type.isUnionType()) return pipe(type.getTypes(), Array.every(isBrandedLiteral));
1008
+ return isBrandedLiteral(type);
1009
+ };
1010
+ const outermost = (node) => pipe(Option.fromNullishOr(node.parent), Option.filter((parent) => parent.getStart() === node.getStart() && parent.end === node.end), Option.match({
1011
+ onNone: () => node,
1012
+ onSome: outermost
1013
+ }));
1014
+ const unwrapped = (parameter) => {
1015
+ if (parameter.type === "TSParameterProperty") return parameter.parameter;
1016
+ return parameter;
1017
+ };
1018
+ const annotationOf = (parameter) => {
1019
+ if (parameter.type === "AssignmentPattern") return Option.fromNullishOr(parameter.left.typeAnnotation);
1020
+ return Option.fromNullishOr(parameter.typeAnnotation);
1021
+ };
1022
+ const annotatedType = (services, parameter) => pipe(annotationOf(parameter), Option.map((annotation) => outermost(services.esTreeNodeToTSNodeMap.get(annotation.typeAnnotation))), Option.filter(isTypeNode), Option.map((node) => services.program.native.checker.getTypeFromTypeNode(node)));
1023
+ const subjectOf = (path) => {
1024
+ if (Array.isReadonlyArrayEmpty(path)) return WHOLE;
1025
+ return `\`${pipe(Array.join(path, SEPARATOR), String$1.replaceAll(`${SEPARATOR}[]`, "[]"))}\``;
1026
+ };
1027
+ const predicateOf = Match.type().pipe(Match.discriminatorsExhaustive("kind")({
1028
+ array: () => "is a mutable array",
1029
+ tuple: () => "is a mutable tuple",
1030
+ property: () => "is writable",
1031
+ index: () => "has a writable index signature",
1032
+ form: ({ name, readonlyName }) => `is a \`${name}\`, which has the read-only form \`${readonlyName}\``
1033
+ }));
1034
+ const describe = ({ path, mutability }) => `${subjectOf(path)} ${predicateOf(mutability)}`;
1035
+ const visitorOf = (context, services) => {
1036
+ const partOf = writablePartOf(services.program.native);
1037
+ const check = ({ params }) => {
1038
+ for (const parameter of pipe(params, Array.map(unwrapped))) {
1039
+ const part = pipe(annotatedType(services, parameter), Option.filter((type) => !isBrandedLiteralLike(type)), Option.flatMap(partOf));
1040
+ if (Option.isSome(part)) context.report({
1041
+ node: parameter,
1042
+ messageId: MESSAGE_ID,
1043
+ data: { part: describe(part.value) }
1044
+ });
1045
+ }
1046
+ };
1047
+ return {
1048
+ ArrowFunctionExpression: check,
1049
+ FunctionDeclaration: check,
1050
+ FunctionExpression: check,
1051
+ TSCallSignatureDeclaration: check,
1052
+ TSConstructSignatureDeclaration: check,
1053
+ TSDeclareFunction: check,
1054
+ TSEmptyBodyFunctionExpression: check,
1055
+ TSFunctionType: check,
1056
+ TSMethodSignature: check
1057
+ };
1058
+ };
815
1059
  // src/features/define-lint-rules/model/plugin.ts
816
1060
  const mschLintPlugin = {
817
1061
  meta: { name: "msch-lint" },
818
1062
  rules: {
1063
+ "array-from-async": arrayFromAsync,
819
1064
  "ecosystem-readers": ecosystemReaders,
820
1065
  "get-or-insert": getOrInsert,
821
1066
  "inline-exports": inlineExports,
822
- "mcp-tool-layer": {
823
- meta: { type: "problem" },
824
- create: (context) => {
825
- if (!outsideToolLayers(context.filename)) return {};
826
- return { CallExpression: (node) => {
827
- const { callee } = node;
828
- if (callee.type === "MemberExpression" && callee.property.type === "Identifier" && callee.property.name === METHOD) context.report({
829
- node: callee.property,
830
- message: MESSAGE
831
- });
832
- } };
833
- }
834
- },
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
+ }),
835
1078
  ...pipe(INTENTS, Record.map(ruleOf))
836
1079
  }
837
1080
  };