@r_masseater/msch 0.110.0 → 0.111.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.
@@ -78,7 +78,7 @@ const childrenOf = (keys, node) => pipe(Option.liftPredicate(node, Predicate.isO
78
78
  const descendants = (keys) => (node) => [node, ...pipe(childrenOf(keys, node), Array.flatMap(descendants(keys)))];
79
79
  const accessesIn = (scope) => (method) => (node) => pipe(descendants(scope.keys)(node), Array.map(accessOf(scope)(method)), Array.getSomes);
80
80
  // src/features/define-lint-rules/model/array-from-async.ts
81
- const MESSAGE$7 = "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 MESSAGE$8 = "Collect an async iterable with Array.fromAsync, passing the mapping as its second argument. Do not push each item from a for await loop.";
82
82
  const ONE$1 = 1;
83
83
  const DeclarationSchema = Schema.Struct({
84
84
  type: Schema.Literal("VariableDeclaration"),
@@ -112,7 +112,7 @@ const arrayFromAsync = {
112
112
  create: (context) => ({ ForOfStatement: (node) => {
113
113
  if (collectsByHand(node)) context.report({
114
114
  node,
115
- message: MESSAGE$7
115
+ message: MESSAGE$8
116
116
  });
117
117
  } })
118
118
  };
@@ -201,79 +201,8 @@ const ecosystemReaders = {
201
201
  }
202
202
  })
203
203
  };
204
- // src/features/define-lint-rules/model/typed-rule.ts
205
- const typedRuleOf = ({ meta, visitorOf }) => withTypeInformation({
206
- meta,
207
- create: (context) => pipe(Option.fromNullishOr(context.sourceCode.parserServices), Option.match({
208
- onNone: () => ({}),
209
- onSome: (services) => visitorOf(context, services)
210
- }))
211
- });
212
- // src/features/define-lint-rules/model/explicit-import-path.ts
213
- const MESSAGE_ID$1 = "spellOut";
214
- const MESSAGE$6 = "`{{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.";
215
- const RELATIVE = /^\.{1,2}(?:\/|$)/u;
216
- const PARTS = /^(?<path>[^?]*)(?<query>.*)$/su;
217
- const TRAILING_SEPARATORS = /\/+$/u;
218
- const DIRECTORY_NAMES = [".", ".."];
219
- const INDEX = "index.";
220
- const DEFAULT_QUOTE = "\"";
221
- const FIRST = 0;
222
- const partsOf = (specifier) => pipe(String$1.match(PARTS)(specifier), Option.flatMap((matched) => Option.fromNullishOr(matched.groups)), Option.map((groups) => ({
223
- path: groups["path"] ?? "",
224
- query: groups["query"] ?? ""
225
- })));
226
- const completionOf = (resolved, path) => {
227
- const file = baseName(resolved);
228
- const name = baseName(path);
229
- const index = String$1.startsWith(INDEX)(file);
230
- if (Array.contains(DIRECTORY_NAMES, name)) return Option.liftPredicate(`/${file}`, () => index);
231
- if (String$1.startsWith(`${name}.`)(file)) return Option.some(String$1.slice(name.length)(file));
232
- return Option.liftPredicate(`/${file}`, () => index && baseName(parent(resolved)) === name);
233
- };
234
- const resolvedFileOf = (services, source) => pipe(Option.fromNullishOr(services.getSymbolAtLocation(source)), Option.flatMap((symbol) => Array.head(symbol.declarations)), Option.map((declaration) => declaration.getSourceFile().fileName));
235
- 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}`))));
236
- const quoteOf = (source) => pipe(Option.fromNullishOr(source.raw), Option.flatMap(String$1.charAt(FIRST)), Option.getOrElse(() => DEFAULT_QUOTE));
237
- const isStringLiteral$1 = (node) => Predicate.isNotNull(node) && node.type === "Literal" && Predicate.isString(node.value);
238
- const visitorOf$1 = (context, services) => {
239
- const check = (source) => {
240
- if (!isStringLiteral$1(source)) return;
241
- const fixed = fixedOf(services, source);
242
- if (Option.isSome(fixed)) context.report({
243
- node: source,
244
- messageId: MESSAGE_ID$1,
245
- data: {
246
- specifier: source.value,
247
- fixed: fixed.value
248
- },
249
- fix: (fixer) => fixer.replaceText(source, `${quoteOf(source)}${fixed.value}${quoteOf(source)}`)
250
- });
251
- };
252
- return {
253
- ImportDeclaration: (node) => {
254
- check(node.source);
255
- },
256
- ExportAllDeclaration: (node) => {
257
- check(node.source);
258
- },
259
- ExportNamedDeclaration: (node) => {
260
- check(node.source);
261
- },
262
- ImportExpression: (node) => {
263
- check(node.source);
264
- }
265
- };
266
- };
267
- const explicitImportPath = typedRuleOf({
268
- meta: {
269
- type: "suggestion",
270
- fixable: "code",
271
- messages: { [MESSAGE_ID$1]: MESSAGE$6 }
272
- },
273
- visitorOf: visitorOf$1
274
- });
275
204
  // src/features/define-lint-rules/model/get-or-insert.ts
276
- const MESSAGE$5 = "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
+ const MESSAGE$7 = "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.";
277
206
  const ONE = 1;
278
207
  const TWO = 2;
279
208
  const OPTION_FROM = /^(?:Option\.)?from(?:NullishOr|UndefinedOr|Nullable)$/u;
@@ -382,22 +311,113 @@ const getOrInsert = {
382
311
  IfStatement: (node) => {
383
312
  if (isHasGuard(scope, node)) context.report({
384
313
  node,
385
- message: MESSAGE$5
314
+ message: MESSAGE$7
386
315
  });
387
316
  },
388
317
  BlockStatement: (node) => {
389
318
  for (const index of fallbackIndices(scope, node.body)) for (const statement of Option.toArray(Array.get(node.body, index))) context.report({
390
319
  node: statement,
391
- message: MESSAGE$5
320
+ message: MESSAGE$7
392
321
  });
393
322
  if (isMemoized(scope, node)) context.report({
394
323
  node,
395
- message: MESSAGE$5
324
+ message: MESSAGE$7
396
325
  });
397
326
  }
398
327
  };
399
328
  }
400
329
  };
330
+ // src/features/define-lint-rules/model/typed-rule.ts
331
+ const typedRuleOf = ({ meta, visitorOf }) => withTypeInformation({
332
+ meta,
333
+ create: (context) => pipe(Option.fromNullishOr(context.sourceCode.parserServices), Option.match({
334
+ onNone: () => ({}),
335
+ onSome: (services) => visitorOf(context, services)
336
+ }))
337
+ });
338
+ // src/features/define-lint-rules/model/explicit-import-path.ts
339
+ const MESSAGE_ID$1 = "spellOut";
340
+ const MESSAGE$6 = "`{{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.";
341
+ const RELATIVE = /^\.{1,2}(?:\/|$)/u;
342
+ const PARTS = /^(?<path>[^?]*)(?<query>.*)$/su;
343
+ const TRAILING_SEPARATORS = /\/+$/u;
344
+ const DIRECTORY_NAMES = [".", ".."];
345
+ const INDEX = "index.";
346
+ const DEFAULT_QUOTE = "\"";
347
+ const FIRST = 0;
348
+ const partsOf = (specifier) => pipe(String$1.match(PARTS)(specifier), Option.flatMap((matched) => Option.fromNullishOr(matched.groups)), Option.map((groups) => ({
349
+ path: groups["path"] ?? "",
350
+ query: groups["query"] ?? ""
351
+ })));
352
+ const completionOf = (resolved, path) => {
353
+ const file = baseName(resolved);
354
+ const name = baseName(path);
355
+ const index = String$1.startsWith(INDEX)(file);
356
+ if (Array.contains(DIRECTORY_NAMES, name)) return Option.liftPredicate(`/${file}`, () => index);
357
+ if (String$1.startsWith(`${name}.`)(file)) return Option.some(String$1.slice(name.length)(file));
358
+ return Option.liftPredicate(`/${file}`, () => index && baseName(parent(resolved)) === name);
359
+ };
360
+ const resolvedFileOf = (services, source) => pipe(Option.fromNullishOr(services.getSymbolAtLocation(source)), Option.flatMap((symbol) => Array.head(symbol.declarations)), Option.map((declaration) => declaration.getSourceFile().fileName));
361
+ 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}`))));
362
+ const quoteOf = (source) => pipe(Option.fromNullishOr(source.raw), Option.flatMap(String$1.charAt(FIRST)), Option.getOrElse(() => DEFAULT_QUOTE));
363
+ const isStringLiteral$1 = (node) => Predicate.isNotNull(node) && node.type === "Literal" && Predicate.isString(node.value);
364
+ const visitorOf$1 = (context, services) => {
365
+ const check = (source) => {
366
+ if (!isStringLiteral$1(source)) return;
367
+ const fixed = fixedOf(services, source);
368
+ if (Option.isSome(fixed)) context.report({
369
+ node: source,
370
+ messageId: MESSAGE_ID$1,
371
+ data: {
372
+ specifier: source.value,
373
+ fixed: fixed.value
374
+ },
375
+ fix: (fixer) => fixer.replaceText(source, `${quoteOf(source)}${fixed.value}${quoteOf(source)}`)
376
+ });
377
+ };
378
+ return {
379
+ ImportDeclaration: (node) => {
380
+ check(node.source);
381
+ },
382
+ ExportAllDeclaration: (node) => {
383
+ check(node.source);
384
+ },
385
+ ExportNamedDeclaration: (node) => {
386
+ check(node.source);
387
+ },
388
+ ImportExpression: (node) => {
389
+ check(node.source);
390
+ }
391
+ };
392
+ };
393
+ const explicitImportPath = typedRuleOf({
394
+ meta: {
395
+ type: "suggestion",
396
+ fixable: "code",
397
+ messages: { [MESSAGE_ID$1]: MESSAGE$6 }
398
+ },
399
+ visitorOf: visitorOf$1
400
+ });
401
+ // src/features/define-lint-rules/model/namespace-as-value.ts
402
+ const MESSAGE$5 = "Import the members by name. A namespace import is only for code that uses the whole module as one value, such as Object.values(namespace).";
403
+ const readsMember = ({ identifier }) => {
404
+ const { parent } = identifier;
405
+ return parent.type === "MemberExpression" && parent.object === identifier || parent.type === "TSQualifiedName" && parent.left === identifier;
406
+ };
407
+ const onlyReadsMembers = (context, node) => pipe(context.sourceCode.getDeclaredVariables(node), Array.flatMap((variable) => variable.references), Array.every(readsMember));
408
+ // src/features/define-lint-rules/model/import-rules.ts
409
+ const IMPORT_RULES = {
410
+ "explicit-import-path": explicitImportPath,
411
+ "namespace-as-value": {
412
+ meta: { type: "suggestion" },
413
+ create: (context) => ({ ImportNamespaceSpecifier: (node) => {
414
+ if (onlyReadsMembers(context, node)) context.report({
415
+ node,
416
+ message: MESSAGE$5
417
+ });
418
+ } })
419
+ }
420
+ };
401
421
  // src/features/define-lint-rules/model/inline-exports.ts
402
422
  const MESSAGE$4 = "export は宣言に付ける(export const・export function など)。ファイルの末尾で export { … } にまとめない。";
403
423
  const TYPE = "type";
@@ -1107,16 +1127,8 @@ const checkScript = (context, { script, options }) => {
1107
1127
  });
1108
1128
  }
1109
1129
  };
1110
- // src/features/define-lint-rules/model/coded-rules.ts
1111
- const CODED_RULES = {
1112
- "array-from-async": arrayFromAsync,
1113
- "ecosystem-readers": ecosystemReaders,
1114
- "explicit-import-path": explicitImportPath,
1115
- "get-or-insert": getOrInsert,
1116
- "inline-exports": inlineExports,
1117
- "mcp-tool-layer": mcpToolLayer,
1118
- "readonly-parameters": readonlyParameters,
1119
- "separate-min-max": separateMinMax,
1130
+ // src/features/define-lint-rules/model/video-rules.ts
1131
+ const VIDEO_RULES = {
1120
1132
  "video-readings": videoReadings,
1121
1133
  "video-say": videoSay,
1122
1134
  "video-series": {
@@ -1144,6 +1156,18 @@ const CODED_RULES = {
1144
1156
  }
1145
1157
  }
1146
1158
  };
1159
+ // src/features/define-lint-rules/model/coded-rules.ts
1160
+ const CODED_RULES = {
1161
+ "array-from-async": arrayFromAsync,
1162
+ "ecosystem-readers": ecosystemReaders,
1163
+ "get-or-insert": getOrInsert,
1164
+ "inline-exports": inlineExports,
1165
+ "mcp-tool-layer": mcpToolLayer,
1166
+ "readonly-parameters": readonlyParameters,
1167
+ "separate-min-max": separateMinMax,
1168
+ ...IMPORT_RULES,
1169
+ ...VIDEO_RULES
1170
+ };
1147
1171
  // src/features/define-lint-rules/model/intent-rule.ts
1148
1172
  const NAMESPACE = "*";
1149
1173
  const DEFAULT = "default";