@r_masseater/msch 0.63.0 → 0.65.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/README.md +1 -0
- package/dist/cli.mjs +661 -690
- package/dist/cli.mjs.map +1 -1
- package/dist/config-CvPuqi4L.mjs +5 -0
- package/dist/config-CvPuqi4L.mjs.map +1 -0
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +3 -2
- package/dist/config.mjs.map +1 -1
- package/dist/decision-rules.d.mts +1 -1
- package/dist/decision-rules.mjs +1 -1
- package/dist/{define-lint-preset-DAhPB3gc.mjs → define-lint-preset-DpGK82kj.mjs} +2 -7
- package/dist/define-lint-preset-DpGK82kj.mjs.map +1 -0
- package/dist/exits.mjs +12 -29
- package/dist/exits.mjs.map +1 -1
- package/dist/{index-DbHT4Cyx.d.mts → index-lKj9OQdX.d.mts} +1 -4
- package/dist/lint-rules.mjs +37 -380
- package/dist/lint-rules.mjs.map +1 -1
- package/dist/lint.d.mts +1 -1
- package/dist/lint.mjs +1 -1
- package/dist/lookup-DmifnzVb.mjs +46 -0
- package/dist/lookup-DmifnzVb.mjs.map +1 -0
- package/dist/lookup-report-ARfHc4ey.mjs +29 -0
- package/dist/lookup-report-ARfHc4ey.mjs.map +1 -0
- package/dist/publish.mjs +18 -32
- package/dist/publish.mjs.map +1 -1
- package/dist/reference-links-B9NZUUF8.mjs +172 -0
- package/dist/reference-links-B9NZUUF8.mjs.map +1 -0
- package/dist/refs.d.mts +1 -0
- package/dist/refs.mjs +209 -0
- package/dist/refs.mjs.map +1 -0
- package/dist/{upstream-exits-DitN-yYH.mjs → upstream-exits-Dp0EeI5D.mjs} +8 -33
- package/dist/upstream-exits-Dp0EeI5D.mjs.map +1 -0
- package/package.json +9 -6
- package/skills/msch-checks/SKILL.md +6 -1
- package/skills/msch-publishing/SKILL.md +1 -2
- package/skills/msch-repository-config/SKILL.md +0 -1
- package/skills/msch-workspace-settings/SKILL.md +0 -1
- package/dist/comment-directives-BD6WGsC7.mjs +0 -27
- package/dist/comment-directives-BD6WGsC7.mjs.map +0 -1
- package/dist/define-lint-preset-DAhPB3gc.mjs.map +0 -1
- package/dist/upstream-exits-DitN-yYH.mjs.map +0 -1
package/dist/lint-rules.mjs
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { c as segments, l as toPosix, n as baseName, o as parent } from "./app-BwjhFdKD.mjs";
|
|
2
|
-
import { Array,
|
|
2
|
+
import { Array, 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";
|
|
5
5
|
import { withTypeInformation } from "@r_masseater/oxlint-typed-rules";
|
|
6
6
|
// src/features/define-lint-rules/model/get-or-insert-ast.ts
|
|
7
|
-
const START
|
|
8
|
-
const END
|
|
7
|
+
const START = 0;
|
|
8
|
+
const END = 1;
|
|
9
9
|
const KEY = 0;
|
|
10
10
|
const VALUE = 1;
|
|
11
11
|
const ONE$2 = 1;
|
|
12
|
-
const RangeSchema
|
|
13
|
-
const RangedSchema
|
|
14
|
-
const decodeRanged = Schema.decodeUnknownOption(RangedSchema
|
|
15
|
-
const IdentifierSchema
|
|
12
|
+
const RangeSchema = Schema.Tuple([Schema.Finite, Schema.Finite]);
|
|
13
|
+
const RangedSchema = Schema.Struct({ range: RangeSchema });
|
|
14
|
+
const decodeRanged = Schema.decodeUnknownOption(RangedSchema);
|
|
15
|
+
const IdentifierSchema = Schema.Struct({
|
|
16
16
|
type: Schema.Literal("Identifier"),
|
|
17
17
|
name: Schema.String
|
|
18
18
|
});
|
|
19
19
|
const MemberSchema = Schema.Struct({
|
|
20
20
|
type: Schema.Literal("MemberExpression"),
|
|
21
21
|
computed: Schema.Literal(false),
|
|
22
|
-
object: RangedSchema
|
|
23
|
-
property: IdentifierSchema
|
|
22
|
+
object: RangedSchema,
|
|
23
|
+
property: IdentifierSchema
|
|
24
24
|
});
|
|
25
25
|
const MemberCallSchema = Schema.Struct({
|
|
26
26
|
type: Schema.Literal("CallExpression"),
|
|
27
27
|
callee: MemberSchema,
|
|
28
|
-
arguments: Schema.Array(RangedSchema
|
|
28
|
+
arguments: Schema.Array(RangedSchema)
|
|
29
29
|
});
|
|
30
30
|
const decodeMemberCall = Schema.decodeUnknownOption(MemberCallSchema);
|
|
31
31
|
const decodeCall = Schema.decodeUnknownOption(Schema.Struct({
|
|
32
32
|
type: Schema.Literal("CallExpression"),
|
|
33
|
-
callee: RangedSchema
|
|
33
|
+
callee: RangedSchema,
|
|
34
34
|
arguments: Schema.Array(Schema.Unknown)
|
|
35
35
|
}));
|
|
36
36
|
const decodeBlock = Schema.decodeUnknownOption(Schema.Struct({
|
|
@@ -43,20 +43,20 @@ const decodeExpressionStatement = Schema.decodeUnknownOption(Schema.Struct({
|
|
|
43
43
|
}));
|
|
44
44
|
const decodeReturn = Schema.decodeUnknownOption(Schema.Struct({
|
|
45
45
|
type: Schema.Literal("ReturnStatement"),
|
|
46
|
-
argument: RangedSchema
|
|
46
|
+
argument: RangedSchema
|
|
47
47
|
}));
|
|
48
48
|
const decodeTyped = Schema.decodeUnknownOption(Schema.Struct({ type: Schema.String }));
|
|
49
|
-
const textOf
|
|
50
|
-
const textOfNode = (scope) => (node) => pipe(decodeRanged(node), Option.map(textOf
|
|
49
|
+
const textOf = (scope) => (node) => String$1.slice(node.range[START], node.range[END])(scope.text);
|
|
50
|
+
const textOfNode = (scope) => (node) => pipe(decodeRanged(node), Option.map(textOf(scope)));
|
|
51
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
|
|
53
|
-
key: textOf
|
|
54
|
-
value: pipe(Array.get(call.arguments, VALUE), Option.map(textOf
|
|
52
|
+
map: textOf(scope)(call.callee.object),
|
|
53
|
+
key: textOf(scope)(key),
|
|
54
|
+
value: pipe(Array.get(call.arguments, VALUE), Option.map(textOf(scope)))
|
|
55
55
|
})))));
|
|
56
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
|
|
57
|
+
const calleeMatches = (scope) => (pattern) => (node) => pipe(decodeCall(node), Option.filter((call) => pattern.test(textOf(scope)(call.callee))), Option.map((call) => call.arguments));
|
|
58
58
|
const expressionOf = (statement) => pipe(decodeExpressionStatement(statement), Option.map((found) => found.expression));
|
|
59
|
-
const returnedText = (scope) => (statement) => pipe(decodeReturn(statement), Option.map((found) => textOf
|
|
59
|
+
const returnedText = (scope) => (statement) => pipe(decodeReturn(statement), Option.map((found) => textOf(scope)(found.argument)));
|
|
60
60
|
const bodyOf = (node) => pipe(decodeBlock(node), Option.map((block) => block.body));
|
|
61
61
|
const onlyStatement = (statement) => Option.match(bodyOf(statement), {
|
|
62
62
|
onNone: () => Option.some(statement),
|
|
@@ -67,14 +67,14 @@ const typeOf = (node) => pipe(decodeTyped(node), Option.match({
|
|
|
67
67
|
onSome: (found) => found.type
|
|
68
68
|
}));
|
|
69
69
|
const parentOf = (node) => pipe(Option.liftPredicate(node, Predicate.hasProperty("parent")), Option.flatMap((found) => Option.fromNullishOr(found.parent)));
|
|
70
|
-
const childrenOf
|
|
70
|
+
const childrenOf = (keys, node) => pipe(Option.liftPredicate(node, Predicate.isObject), Option.match({
|
|
71
71
|
onNone: () => [],
|
|
72
72
|
onSome: (found) => pipe(keys[typeOf(found)] ?? [], Array.flatMap((key) => pipe(Option.liftPredicate(found, Predicate.hasProperty(key)), Option.match({
|
|
73
73
|
onNone: () => [],
|
|
74
74
|
onSome: (owner) => Array.ensure(owner[key])
|
|
75
75
|
}))), Array.filter(Predicate.isObject))
|
|
76
76
|
}));
|
|
77
|
-
const descendants = (keys) => (node) => [node, ...pipe(childrenOf
|
|
77
|
+
const descendants = (keys) => (node) => [node, ...pipe(childrenOf(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
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.";
|
|
@@ -289,7 +289,7 @@ const decodeNot = Schema.decodeUnknownOption(Schema.Struct({
|
|
|
289
289
|
operator: Schema.Literal("!"),
|
|
290
290
|
argument: Schema.Unknown
|
|
291
291
|
}));
|
|
292
|
-
const DeclaratorSchema
|
|
292
|
+
const DeclaratorSchema = Schema.Struct({
|
|
293
293
|
id: Schema.Struct({
|
|
294
294
|
type: Schema.Literal("Identifier"),
|
|
295
295
|
name: Schema.String
|
|
@@ -298,7 +298,7 @@ const DeclaratorSchema$1 = Schema.Struct({
|
|
|
298
298
|
});
|
|
299
299
|
const decodeDeclaration = Schema.decodeUnknownOption(Schema.Struct({
|
|
300
300
|
type: Schema.Literal("VariableDeclaration"),
|
|
301
|
-
declarations: Schema.Array(DeclaratorSchema
|
|
301
|
+
declarations: Schema.Array(DeclaratorSchema)
|
|
302
302
|
}));
|
|
303
303
|
const decodeNullish = Schema.decodeUnknownOption(Schema.Struct({
|
|
304
304
|
type: Schema.Literal("LogicalExpression"),
|
|
@@ -397,367 +397,24 @@ const getOrInsert = {
|
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
399
|
};
|
|
400
|
-
// src/features/define-lint-rules/model/inline-exports-resolve.ts
|
|
401
|
-
const DEFAULT_NAME$1 = "default";
|
|
402
|
-
const CLASS_DECLARATION = "ClassDeclaration";
|
|
403
|
-
const TYPE_DECLARATIONS = /* @__PURE__ */ new Set(["TSTypeAliasDeclaration", "TSInterfaceDeclaration"]);
|
|
404
|
-
const isTypeOnly$1 = (list) => (specifier) => list.typeOnly || specifier.typeOnly;
|
|
405
|
-
const exportsAsItself = (list) => (name) => pipe(list.specifiers, Array.some((specifier) => Option.contains(specifier.local, name) && specifier.exported === name));
|
|
406
|
-
const declarationOf$1 = (list, specifier) => (statements) => {
|
|
407
|
-
const whole = pipe(statements, Array.every((statement) => pipe(statement.names, Array.every(exportsAsItself(list)))));
|
|
408
|
-
const keepsKind = !isTypeOnly$1(list)(specifier) || pipe(statements, Array.every((statement) => TYPE_DECLARATIONS.has(statement.type)));
|
|
409
|
-
if (!whole || !keepsKind) return Option.none();
|
|
410
|
-
return Option.some({
|
|
411
|
-
kind: "declaration",
|
|
412
|
-
statements
|
|
413
|
-
});
|
|
414
|
-
};
|
|
415
|
-
const declarationsNamed = (list, name) => pipe(list.body, Array.filter((statement) => statement.kind === "declaration" && pipe(statement.names, Array.contains(name))));
|
|
416
|
-
const importIn = (name) => (statement) => {
|
|
417
|
-
if (statement.kind !== "import") return Option.none();
|
|
418
|
-
return pipe(statement.bindings, Array.findFirst((binding) => binding.local === name), Option.map((binding) => ({
|
|
419
|
-
kind: "import",
|
|
420
|
-
statement,
|
|
421
|
-
binding
|
|
422
|
-
})));
|
|
423
|
-
};
|
|
424
|
-
const isTypeOnlyClass = (list) => (specifier) => isTypeOnly$1(list)(specifier) && pipe(specifier.local, Option.exists((local) => {
|
|
425
|
-
const statements = declarationsNamed(list, local);
|
|
426
|
-
return Array.isReadonlyArrayNonEmpty(statements) && pipe(statements, Array.every((statement) => statement.type === CLASS_DECLARATION));
|
|
427
|
-
}));
|
|
428
|
-
const resolutionOf = (list) => (specifier) => pipe(specifier.local, Option.flatMap((local) => {
|
|
429
|
-
if (specifier.exported === DEFAULT_NAME$1) return Option.some({
|
|
430
|
-
kind: "default",
|
|
431
|
-
name: local
|
|
432
|
-
});
|
|
433
|
-
if (local !== specifier.exported) return Option.none();
|
|
434
|
-
const statements = declarationsNamed(list, local);
|
|
435
|
-
if (Array.isReadonlyArrayNonEmpty(statements)) return declarationOf$1(list, specifier)(statements);
|
|
436
|
-
return pipe(list.body, Array.findFirst(importIn(local)));
|
|
437
|
-
}));
|
|
438
|
-
const kindOf = (kind) => (resolved) => pipe(resolved.resolution, Option.filter((found) => found.kind === kind), Option.toArray);
|
|
439
|
-
const restOf = (resolved) => pipe(resolved, Array.filter((entry) => Option.isNone(entry.resolution)), Array.map((entry) => entry.specifier));
|
|
440
|
-
const resolvedOf = (list) => pipe(list.specifiers, Array.map((specifier) => ({
|
|
441
|
-
specifier,
|
|
442
|
-
resolution: resolutionOf(list)(specifier)
|
|
443
|
-
})));
|
|
444
|
-
// src/features/define-lint-rules/model/inline-exports-text.ts
|
|
445
|
-
const START$2 = 0;
|
|
446
|
-
const END$2 = 1;
|
|
447
|
-
const NEXT = 1;
|
|
448
|
-
const NEWLINE$1 = "\n";
|
|
449
|
-
const textOf = (source) => (range) => pipe(source.text, String$1.slice(range[START$2], range[END$2]));
|
|
450
|
-
const lineStartOf = (source, offset) => pipe(source.text, String$1.slice(START$2, offset), String$1.lastIndexOf(NEWLINE$1), Option.match({
|
|
451
|
-
onNone: () => START$2,
|
|
452
|
-
onSome: (index) => index + NEXT
|
|
453
|
-
}));
|
|
454
|
-
const indentOf = (source) => (offset) => textOf(source)([lineStartOf(source, offset), offset]);
|
|
455
|
-
const lineRangeOf = (source) => (range) => {
|
|
456
|
-
const indented = String$1.isEmpty(String$1.trim(indentOf(source)(range[START$2])));
|
|
457
|
-
const endsLine = pipe(source.text, String$1.charAt(range[END$2]), Option.contains(NEWLINE$1));
|
|
458
|
-
return [Boolean.match(indented, {
|
|
459
|
-
onFalse: () => range[START$2],
|
|
460
|
-
onTrue: () => lineStartOf(source, range[START$2])
|
|
461
|
-
}), Boolean.match(endsLine, {
|
|
462
|
-
onFalse: () => range[END$2],
|
|
463
|
-
onTrue: () => range[END$2] + NEXT
|
|
464
|
-
})];
|
|
465
|
-
};
|
|
466
|
-
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({
|
|
467
|
-
onNone: () => [],
|
|
468
|
-
onSome: (comment) => [...commentsBefore(source)(comment[START$2]), comment]
|
|
469
|
-
}));
|
|
470
|
-
const leadingTextOf = (source) => (start) => pipe(commentsBefore(source)(start), Array.map(textOf(source)), Array.join(NEWLINE$1));
|
|
471
|
-
// src/features/define-lint-rules/model/inline-exports-plan.ts
|
|
472
|
-
const NAMESPACE_NAME$1 = "*";
|
|
473
|
-
const START$1 = 0;
|
|
474
|
-
const END$1 = 1;
|
|
475
|
-
const SINGLE = 1;
|
|
476
|
-
const NEWLINE = "\n";
|
|
477
|
-
const EXPORT = "export ";
|
|
478
|
-
const KINDS = [false, true];
|
|
479
|
-
const keywordOf = (typeOnly) => Boolean.match(typeOnly, {
|
|
480
|
-
onFalse: () => "export",
|
|
481
|
-
onTrue: () => "export type"
|
|
482
|
-
});
|
|
483
|
-
const reexportsOf = (list, resolved) => pipe(resolved, Array.flatMap((entry) => pipe(kindOf("import")(entry), Array.map((found) => ({
|
|
484
|
-
statement: found.statement,
|
|
485
|
-
binding: found.binding,
|
|
486
|
-
typeOnly: isTypeOnly$1(list)(entry.specifier) || found.binding.typeOnly
|
|
487
|
-
})))));
|
|
488
|
-
const statementsOf = (reexports) => pipe(reexports, Array.map((entry) => entry.statement), Array.dedupe);
|
|
489
|
-
const groupOf = (reexports, statement) => (typeOnly) => {
|
|
490
|
-
const bindings = pipe(reexports, Array.filter((entry) => entry.statement === statement && entry.typeOnly === typeOnly), Array.map((entry) => entry.binding));
|
|
491
|
-
if (Array.isReadonlyArrayEmpty(bindings)) return [];
|
|
492
|
-
return [{
|
|
493
|
-
statement,
|
|
494
|
-
bindings,
|
|
495
|
-
typeOnly
|
|
496
|
-
}];
|
|
497
|
-
};
|
|
498
|
-
const splitNamespaces = (group) => {
|
|
499
|
-
if (!(pipe(group.bindings, Array.some((binding) => binding.imported === NAMESPACE_NAME$1)) && group.bindings.length > SINGLE)) return [group];
|
|
500
|
-
return pipe(group.bindings, Array.map((binding) => ({
|
|
501
|
-
...group,
|
|
502
|
-
bindings: [binding]
|
|
503
|
-
})));
|
|
504
|
-
};
|
|
505
|
-
const groupsOf = (reexports) => pipe(statementsOf(reexports), Array.flatMap((statement) => pipe(KINDS, Array.flatMap(groupOf(reexports, statement)))), Array.flatMap(splitNamespaces));
|
|
506
|
-
const renamedOf = (binding) => Boolean.match(binding.imported === binding.local, {
|
|
507
|
-
onFalse: () => `${binding.imported} as ${binding.local}`,
|
|
508
|
-
onTrue: () => binding.imported
|
|
509
|
-
});
|
|
510
|
-
const reexportTextOf = (source) => (group) => {
|
|
511
|
-
const from = textOf(source)(group.statement.from);
|
|
512
|
-
const keyword = keywordOf(group.typeOnly);
|
|
513
|
-
return pipe(group.bindings, Array.findFirst((binding) => binding.imported === NAMESPACE_NAME$1), Option.match({
|
|
514
|
-
onSome: (namespace) => `${keyword} * as ${namespace.local} from ${from};`,
|
|
515
|
-
onNone: () => `${keyword} { ${pipe(group.bindings, Array.map(renamedOf), Array.join(", "))} } from ${from};`
|
|
516
|
-
}));
|
|
517
|
-
};
|
|
518
|
-
const replacementOf = (source, list, resolved) => {
|
|
519
|
-
const rest = restOf(resolved);
|
|
520
|
-
const names = pipe(rest, Array.map((specifier) => textOf(source)(specifier.range)), Array.join(", "));
|
|
521
|
-
const remaining = Boolean.match(Array.isReadonlyArrayEmpty(rest), {
|
|
522
|
-
onFalse: () => [`${keywordOf(list.typeOnly)} { ${names} };`],
|
|
523
|
-
onTrue: () => []
|
|
524
|
-
});
|
|
525
|
-
const defaults = pipe(resolved, Array.flatMap(kindOf("default")), Array.map((found) => `export default ${found.name};`));
|
|
526
|
-
const reexports = pipe(groupsOf(reexportsOf(list, resolved)), Array.map(reexportTextOf(source)));
|
|
527
|
-
return pipe([
|
|
528
|
-
...remaining,
|
|
529
|
-
...defaults,
|
|
530
|
-
...reexports
|
|
531
|
-
], Array.join(NEWLINE));
|
|
532
|
-
};
|
|
533
|
-
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))))));
|
|
534
|
-
const prefixOf = (source, comments) => (statement) => {
|
|
535
|
-
const start = statement.range[START$1];
|
|
536
|
-
if (String$1.isEmpty(comments) || pipe(leadingTextOf(source)(start), String$1.includes(comments))) return EXPORT;
|
|
537
|
-
return `${comments}${NEWLINE}${indentOf(source)(start)}${EXPORT}`;
|
|
538
|
-
};
|
|
539
|
-
const listEditOf = (source, list, text) => {
|
|
540
|
-
if (!String$1.isEmpty(text)) return {
|
|
541
|
-
range: list.range,
|
|
542
|
-
text
|
|
543
|
-
};
|
|
544
|
-
const start = pipe(commentsBefore(source)(list.range[START$1]), Array.head, Option.match({
|
|
545
|
-
onNone: () => list.range[START$1],
|
|
546
|
-
onSome: (first) => first[START$1]
|
|
547
|
-
}));
|
|
548
|
-
return {
|
|
549
|
-
range: lineRangeOf(source)([start, list.range[END$1]]),
|
|
550
|
-
text: ""
|
|
551
|
-
};
|
|
552
|
-
};
|
|
553
|
-
const editsOf = (source) => (list) => {
|
|
554
|
-
const resolved = resolvedOf(list);
|
|
555
|
-
if (restOf(resolved).length === list.specifiers.length) return Option.none();
|
|
556
|
-
const prefix = prefixOf(source, leadingTextOf(source)(list.range[START$1]));
|
|
557
|
-
const declarations = pipe(resolved, Array.flatMap(kindOf("declaration")), Array.flatMap((found) => found.statements), Array.dedupe, Array.map((statement) => ({
|
|
558
|
-
range: [statement.range[START$1], statement.range[START$1]],
|
|
559
|
-
text: prefix(statement)
|
|
560
|
-
})));
|
|
561
|
-
const removals = pipe(removedOf(source, reexportsOf(list, resolved)), Array.map((statement) => ({
|
|
562
|
-
range: lineRangeOf(source)(statement.range),
|
|
563
|
-
text: ""
|
|
564
|
-
})));
|
|
565
|
-
return Option.some([
|
|
566
|
-
...declarations,
|
|
567
|
-
...removals,
|
|
568
|
-
listEditOf(source, list, replacementOf(source, list, resolved))
|
|
569
|
-
]);
|
|
570
|
-
};
|
|
571
|
-
// src/features/define-lint-rules/model/inline-exports-source.ts
|
|
572
|
-
const TYPE_KIND = "type";
|
|
573
|
-
const DEFAULT_NAME = "default";
|
|
574
|
-
const NAMESPACE_NAME = "*";
|
|
575
|
-
const RangeSchema = Schema.Tuple([Schema.Finite, Schema.Finite]);
|
|
576
|
-
const KindSchema = Schema.optionalKey(Schema.String);
|
|
577
|
-
const IdentifierSchema = Schema.Struct({
|
|
578
|
-
type: Schema.Literal("Identifier"),
|
|
579
|
-
name: Schema.String
|
|
580
|
-
});
|
|
581
|
-
const StringSchema = Schema.Struct({
|
|
582
|
-
type: Schema.Literal("Literal"),
|
|
583
|
-
value: Schema.String
|
|
584
|
-
});
|
|
585
|
-
const NameSchema = Schema.Union([IdentifierSchema, StringSchema]);
|
|
586
|
-
const PatternSchema = Schema.Union([
|
|
587
|
-
IdentifierSchema,
|
|
588
|
-
Schema.Struct({
|
|
589
|
-
type: Schema.Literal("ObjectPattern"),
|
|
590
|
-
properties: Schema.Array(Schema.Unknown)
|
|
591
|
-
}),
|
|
592
|
-
Schema.Struct({
|
|
593
|
-
type: Schema.Literal("ArrayPattern"),
|
|
594
|
-
elements: Schema.Array(Schema.Unknown)
|
|
595
|
-
}),
|
|
596
|
-
Schema.Struct({
|
|
597
|
-
type: Schema.Literal("Property"),
|
|
598
|
-
value: Schema.Unknown
|
|
599
|
-
}),
|
|
600
|
-
Schema.Struct({
|
|
601
|
-
type: Schema.Literal("AssignmentPattern"),
|
|
602
|
-
left: Schema.Unknown
|
|
603
|
-
}),
|
|
604
|
-
Schema.Struct({
|
|
605
|
-
type: Schema.Literal("RestElement"),
|
|
606
|
-
argument: Schema.Unknown
|
|
607
|
-
})
|
|
608
|
-
]);
|
|
609
|
-
const decodePattern = Schema.decodeUnknownOption(PatternSchema);
|
|
610
|
-
const BindingSchema = Schema.Union([Schema.Struct({
|
|
611
|
-
type: Schema.Literal("ImportSpecifier"),
|
|
612
|
-
local: IdentifierSchema,
|
|
613
|
-
imported: NameSchema,
|
|
614
|
-
importKind: KindSchema
|
|
615
|
-
}), Schema.Struct({
|
|
616
|
-
type: Schema.Literals(["ImportDefaultSpecifier", "ImportNamespaceSpecifier"]),
|
|
617
|
-
local: IdentifierSchema
|
|
618
|
-
})]);
|
|
619
|
-
const RangedSchema = Schema.Struct({ range: RangeSchema });
|
|
620
|
-
const DeclaratorSchema = Schema.Struct({ id: Schema.Unknown });
|
|
621
|
-
const ExportSpecifierSchema = Schema.Struct({
|
|
622
|
-
range: RangeSchema,
|
|
623
|
-
local: NameSchema,
|
|
624
|
-
exported: NameSchema,
|
|
625
|
-
exportKind: KindSchema
|
|
626
|
-
});
|
|
627
|
-
const ParentSchema = Schema.Struct({ body: Schema.Array(Schema.Unknown) });
|
|
628
|
-
const QuotedSchema = Schema.fromJsonString(Schema.String);
|
|
629
|
-
const decodeImport = Schema.decodeUnknownOption(Schema.Struct({
|
|
630
|
-
type: Schema.Literal("ImportDeclaration"),
|
|
631
|
-
range: RangeSchema,
|
|
632
|
-
source: RangedSchema,
|
|
633
|
-
importKind: KindSchema,
|
|
634
|
-
specifiers: Schema.Array(BindingSchema)
|
|
635
|
-
}));
|
|
636
|
-
const decodeVariable = Schema.decodeUnknownOption(Schema.Struct({
|
|
637
|
-
type: Schema.Literal("VariableDeclaration"),
|
|
638
|
-
range: RangeSchema,
|
|
639
|
-
declarations: Schema.Array(DeclaratorSchema)
|
|
640
|
-
}));
|
|
641
|
-
const decodeNamed = Schema.decodeUnknownOption(Schema.Struct({
|
|
642
|
-
type: Schema.String,
|
|
643
|
-
range: RangeSchema,
|
|
644
|
-
id: IdentifierSchema
|
|
645
|
-
}));
|
|
646
|
-
const decodeList = Schema.decodeUnknownOption(Schema.Struct({
|
|
647
|
-
range: RangeSchema,
|
|
648
|
-
source: Schema.Null,
|
|
649
|
-
declaration: Schema.Null,
|
|
650
|
-
exportKind: KindSchema,
|
|
651
|
-
specifiers: Schema.Array(ExportSpecifierSchema),
|
|
652
|
-
parent: ParentSchema
|
|
653
|
-
}));
|
|
654
|
-
const nameOf = (name) => {
|
|
655
|
-
if (name.type === "Literal") return name.value;
|
|
656
|
-
return name.name;
|
|
657
|
-
};
|
|
658
|
-
const identifierOf = (name) => {
|
|
659
|
-
if (name.type === "Literal") return Option.none();
|
|
660
|
-
return Option.some(name.name);
|
|
661
|
-
};
|
|
662
|
-
const childOf = (pattern) => {
|
|
663
|
-
if (pattern.type === "Property") return pattern.value;
|
|
664
|
-
if (pattern.type === "AssignmentPattern") return pattern.left;
|
|
665
|
-
return pattern.argument;
|
|
666
|
-
};
|
|
667
|
-
const childrenOf = (pattern) => {
|
|
668
|
-
if (pattern.type === "ObjectPattern") return pattern.properties;
|
|
669
|
-
if (pattern.type === "ArrayPattern") return pattern.elements;
|
|
670
|
-
if (pattern.type === "Identifier") return [];
|
|
671
|
-
return [childOf(pattern)];
|
|
672
|
-
};
|
|
673
|
-
const bindingNames = (node) => pipe(decodePattern(node), Option.match({
|
|
674
|
-
onNone: () => [],
|
|
675
|
-
onSome: (pattern) => {
|
|
676
|
-
if (pattern.type === "Identifier") return [pattern.name];
|
|
677
|
-
return pipe(childrenOf(pattern), Array.flatMap(bindingNames));
|
|
678
|
-
}
|
|
679
|
-
}));
|
|
680
|
-
const importedOf = (binding) => {
|
|
681
|
-
if (binding.type === "ImportSpecifier") {
|
|
682
|
-
if (binding.imported.type === "Literal") {
|
|
683
|
-
const { value } = binding.imported;
|
|
684
|
-
return pipe(Schema.encodeOption(QuotedSchema)(value), Option.getOrElse(() => value));
|
|
685
|
-
}
|
|
686
|
-
return binding.imported.name;
|
|
687
|
-
}
|
|
688
|
-
if (binding.type === "ImportDefaultSpecifier") return DEFAULT_NAME;
|
|
689
|
-
return NAMESPACE_NAME;
|
|
690
|
-
};
|
|
691
|
-
const typeOnlyOf = (binding) => binding.type === "ImportSpecifier" && binding.importKind === TYPE_KIND;
|
|
692
|
-
const importOf = (node) => pipe(decodeImport(node), Option.map((statement) => ({
|
|
693
|
-
kind: "import",
|
|
694
|
-
range: statement.range,
|
|
695
|
-
from: statement.source.range,
|
|
696
|
-
bindings: pipe(statement.specifiers, Array.map((binding) => ({
|
|
697
|
-
local: binding.local.name,
|
|
698
|
-
imported: importedOf(binding),
|
|
699
|
-
typeOnly: statement.importKind === TYPE_KIND || typeOnlyOf(binding)
|
|
700
|
-
})))
|
|
701
|
-
})));
|
|
702
|
-
const declarationOf = (node) => pipe(decodeVariable(node), Option.map((statement) => ({
|
|
703
|
-
kind: "declaration",
|
|
704
|
-
type: statement.type,
|
|
705
|
-
range: statement.range,
|
|
706
|
-
names: pipe(statement.declarations, Array.flatMap((declarator) => bindingNames(declarator.id)))
|
|
707
|
-
})), Option.orElse(() => pipe(decodeNamed(node), Option.map((statement) => ({
|
|
708
|
-
kind: "declaration",
|
|
709
|
-
type: statement.type,
|
|
710
|
-
range: statement.range,
|
|
711
|
-
names: [statement.id.name]
|
|
712
|
-
})))));
|
|
713
|
-
const statementOf = (node) => pipe(importOf(node), Option.orElse(() => declarationOf(node)));
|
|
714
|
-
const exportListOf = (node) => pipe(decodeList(node), Option.filter((list) => Array.isReadonlyArrayNonEmpty(list.specifiers)), Option.map((list) => ({
|
|
715
|
-
range: list.range,
|
|
716
|
-
typeOnly: list.exportKind === TYPE_KIND,
|
|
717
|
-
specifiers: pipe(list.specifiers, Array.map((specifier) => ({
|
|
718
|
-
range: specifier.range,
|
|
719
|
-
local: identifierOf(specifier.local),
|
|
720
|
-
exported: nameOf(specifier.exported),
|
|
721
|
-
typeOnly: specifier.exportKind === TYPE_KIND
|
|
722
|
-
}))),
|
|
723
|
-
body: pipe(list.parent.body, Array.map(statementOf), Array.getSomes)
|
|
724
|
-
})));
|
|
725
400
|
// src/features/define-lint-rules/model/inline-exports.ts
|
|
726
401
|
const MESSAGE$2 = "export は宣言に付ける(export const・export function など)。ファイルの末尾で export { … } にまとめない。";
|
|
727
|
-
const
|
|
728
|
-
const
|
|
729
|
-
const
|
|
730
|
-
const
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const reportList = (context, node, list) => {
|
|
737
|
-
pipe(editsOf(sourceOf$1(context, list))(list), Option.match({
|
|
738
|
-
onNone: () => {
|
|
739
|
-
context.report({
|
|
740
|
-
node,
|
|
741
|
-
message: MESSAGE$2
|
|
742
|
-
});
|
|
743
|
-
},
|
|
744
|
-
onSome: (edits) => {
|
|
745
|
-
context.report({
|
|
746
|
-
node,
|
|
747
|
-
message: MESSAGE$2,
|
|
748
|
-
fix: (fixer) => pipe(edits, Array.map((edit) => fixer.replaceTextRange([edit.range[START], edit.range[END]], edit.text)))
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
}));
|
|
752
|
-
};
|
|
402
|
+
const TYPE = "type";
|
|
403
|
+
const CLASS_NAME = "ClassName";
|
|
404
|
+
const isList = (node) => node.declaration === null && node.source === null && !Array.isReadonlyArrayEmpty(node.specifiers);
|
|
405
|
+
const localName = (specifier) => {
|
|
406
|
+
if (specifier.local.type === "Literal") return specifier.local.value;
|
|
407
|
+
return specifier.local.name;
|
|
408
|
+
};
|
|
409
|
+
const isClass = (context, name) => pipe(context.sourceCode.scopeManager.scopes, Array.flatMap((scope) => scope.variables), Array.filter((variable) => variable.name === name), Array.flatMap((variable) => variable.defs), (defs) => Array.isReadonlyArrayNonEmpty(defs) && pipe(defs, Array.every(({ type }) => type === CLASS_NAME)));
|
|
410
|
+
const isTypeOnlyClass = (context, node) => (specifier) => (node.exportKind === TYPE || specifier.exportKind === TYPE) && isClass(context, localName(specifier));
|
|
753
411
|
const inlineExports = {
|
|
754
|
-
meta: {
|
|
755
|
-
type: "suggestion",
|
|
756
|
-
fixable: "code"
|
|
757
|
-
},
|
|
412
|
+
meta: { type: "suggestion" },
|
|
758
413
|
create: (context) => ({ ExportNamedDeclaration: (node) => {
|
|
759
|
-
|
|
760
|
-
|
|
414
|
+
if (isList(node) && !pipe(node.specifiers, Array.every(isTypeOnlyClass(context, node)))) context.report({
|
|
415
|
+
node,
|
|
416
|
+
message: MESSAGE$2
|
|
417
|
+
});
|
|
761
418
|
} })
|
|
762
419
|
};
|
|
763
420
|
// src/features/define-lint-rules/model/mcp-tool-layer.ts
|