yukigo 0.2.2 → 0.3.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.
- package/.mocharc.json +3 -3
- package/CHANGELOG.md +102 -41
- package/README.md +193 -193
- package/dist/analyzer/GraphBuilder.d.ts +1 -0
- package/dist/analyzer/GraphBuilder.js +2 -1
- package/dist/analyzer/index.d.ts +0 -7
- package/dist/analyzer/index.js +3 -3
- package/dist/analyzer/inspections/functional/functional.d.ts +1 -1
- package/dist/analyzer/inspections/functional/functional.js +1 -1
- package/dist/analyzer/inspections/functional/smells.d.ts +3 -3
- package/dist/analyzer/inspections/functional/smells.js +27 -35
- package/dist/analyzer/inspections/generic/generic.d.ts +21 -14
- package/dist/analyzer/inspections/generic/generic.js +78 -59
- package/dist/analyzer/inspections/generic/smells.d.ts +2 -0
- package/dist/analyzer/inspections/generic/smells.js +55 -64
- package/dist/analyzer/inspections/imperative/imperative.d.ts +3 -3
- package/dist/analyzer/inspections/imperative/imperative.js +3 -3
- package/dist/analyzer/inspections/imperative/smells.d.ts +1 -0
- package/dist/analyzer/inspections/imperative/smells.js +8 -5
- package/dist/analyzer/inspections/logic/logic.d.ts +8 -8
- package/dist/analyzer/inspections/logic/logic.js +5 -5
- package/dist/analyzer/inspections/logic/smells.js +2 -2
- package/dist/analyzer/inspections/object/object.d.ts +5 -5
- package/dist/analyzer/inspections/object/object.js +22 -21
- package/dist/analyzer/inspections/object/smells.js +11 -23
- package/dist/analyzer/utils.d.ts +6 -2
- package/dist/analyzer/utils.js +6 -2
- package/dist/interpreter/components/EnvBuilder.d.ts +20 -1
- package/dist/interpreter/components/EnvBuilder.js +211 -66
- package/dist/interpreter/components/EqualityComparer.d.ts +15 -0
- package/dist/interpreter/components/EqualityComparer.js +69 -0
- package/dist/interpreter/components/Operations.d.ts +17 -14
- package/dist/interpreter/components/Operations.js +61 -62
- package/dist/interpreter/components/PatternMatcher.d.ts +19 -58
- package/dist/interpreter/components/PatternMatcher.js +185 -286
- package/dist/interpreter/components/RuntimeContext.d.ts +24 -15
- package/dist/interpreter/components/RuntimeContext.js +43 -4
- package/dist/interpreter/components/TestRunner.d.ts +15 -13
- package/dist/interpreter/components/TestRunner.js +86 -53
- package/dist/interpreter/components/evaluators/BaseEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/BaseEvaluator.js +20 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.d.ts +34 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.js +298 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.d.ts +25 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.js +226 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.js +50 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.d.ts +28 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.js +240 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.d.ts +15 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.js +14 -0
- package/dist/interpreter/components/evaluators/index.d.ts +110 -0
- package/dist/interpreter/components/evaluators/index.js +21 -0
- package/dist/interpreter/components/evaluators/utils.d.ts +7 -0
- package/dist/interpreter/components/evaluators/utils.js +50 -0
- package/dist/interpreter/components/hooks/YukigoHook.d.ts +27 -0
- package/dist/interpreter/components/hooks/YukigoHook.js +1 -0
- package/dist/interpreter/components/kernel/commands.d.ts +122 -0
- package/dist/interpreter/components/kernel/commands.js +203 -0
- package/dist/interpreter/components/kernel/index.d.ts +51 -0
- package/dist/interpreter/components/kernel/index.js +176 -0
- package/dist/interpreter/components/logic/LogicEngine.d.ts +26 -23
- package/dist/interpreter/components/logic/LogicEngine.js +234 -221
- package/dist/interpreter/components/logic/LogicResolver.d.ts +22 -51
- package/dist/interpreter/components/logic/LogicResolver.js +73 -440
- package/dist/interpreter/components/logic/LogicTerm.d.ts +104 -0
- package/dist/interpreter/components/logic/LogicTerm.js +423 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +25 -9
- package/dist/interpreter/components/logic/LogicTranslator.js +211 -74
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +6 -4
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +82 -84
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +13 -14
- package/dist/interpreter/components/runtimes/LazyRuntime.js +112 -239
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +17 -14
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +105 -74
- package/dist/interpreter/errors.d.ts +10 -0
- package/dist/interpreter/errors.js +17 -0
- package/dist/interpreter/index.d.ts +9 -5
- package/dist/interpreter/index.js +11 -13
- package/dist/interpreter/primitives/YuValue.d.ts +21 -0
- package/dist/interpreter/primitives/YuValue.js +40 -0
- package/dist/interpreter/primitives/capabilities.d.ts +90 -0
- package/dist/interpreter/primitives/capabilities.js +1 -0
- package/dist/interpreter/primitives/entities/LazyList.d.ts +48 -0
- package/dist/interpreter/primitives/entities/LazyList.js +164 -0
- package/dist/interpreter/primitives/entities/LogicResult.d.ts +51 -0
- package/dist/interpreter/primitives/entities/LogicResult.js +101 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.d.ts +24 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.js +57 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.d.ts +40 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.js +73 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.d.ts +27 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.js +82 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.d.ts +19 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.js +59 -0
- package/dist/interpreter/primitives/index.d.ts +14 -0
- package/dist/interpreter/primitives/index.js +14 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.d.ts +24 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.js +69 -0
- package/dist/interpreter/primitives/scalars/YuChar.d.ts +28 -0
- package/dist/interpreter/primitives/scalars/YuChar.js +78 -0
- package/dist/interpreter/primitives/scalars/YuNil.d.ts +25 -0
- package/dist/interpreter/primitives/scalars/YuNil.js +73 -0
- package/dist/interpreter/primitives/scalars/YuNumber.d.ts +49 -0
- package/dist/interpreter/primitives/scalars/YuNumber.js +165 -0
- package/dist/interpreter/primitives/sequences/YuArray.d.ts +33 -0
- package/dist/interpreter/primitives/sequences/YuArray.js +150 -0
- package/dist/interpreter/primitives/sequences/YuString.d.ts +40 -0
- package/dist/interpreter/primitives/sequences/YuString.js +130 -0
- package/dist/interpreter/utils.d.ts +23 -10
- package/dist/interpreter/utils.js +25 -30
- package/dist/tester/index.d.ts +3 -3
- package/dist/tester/index.js +39 -28
- package/dist/utils/helpers.d.ts +12 -5
- package/dist/utils/helpers.js +6 -79
- package/package.json +3 -16
- package/src/analyzer/GraphBuilder.ts +143 -142
- package/src/analyzer/index.ts +185 -194
- package/src/analyzer/inspections/functional/functional.ts +121 -121
- package/src/analyzer/inspections/functional/smells.ts +88 -102
- package/src/analyzer/inspections/generic/generic.ts +610 -581
- package/src/analyzer/inspections/generic/smells.ts +355 -365
- package/src/analyzer/inspections/imperative/imperative.ts +104 -101
- package/src/analyzer/inspections/imperative/smells.ts +58 -54
- package/src/analyzer/inspections/logic/logic.ts +84 -90
- package/src/analyzer/inspections/logic/smells.ts +54 -54
- package/src/analyzer/inspections/object/object.ts +295 -264
- package/src/analyzer/inspections/object/smells.ts +130 -144
- package/src/analyzer/utils.ts +115 -109
- package/src/index.ts +3 -3
- package/src/interpreter/components/EnvBuilder.ts +405 -202
- package/src/interpreter/components/EqualityComparer.ts +107 -0
- package/src/interpreter/components/Operations.ts +126 -99
- package/src/interpreter/components/PatternMatcher.ts +375 -475
- package/src/interpreter/components/RuntimeContext.ts +181 -119
- package/src/interpreter/components/TestRunner.ts +223 -151
- package/src/interpreter/components/evaluators/BaseEvaluator.ts +36 -0
- package/src/interpreter/components/evaluators/ExpressionEvaluator.ts +475 -0
- package/src/interpreter/components/evaluators/OperationEvaluator.ts +477 -0
- package/src/interpreter/components/evaluators/PrimitiveEvaluator.ts +80 -0
- package/src/interpreter/components/evaluators/StatementEvaluator.ts +372 -0
- package/src/interpreter/components/evaluators/TestingEvaluator.ts +26 -0
- package/src/interpreter/components/evaluators/index.ts +34 -0
- package/src/interpreter/components/evaluators/utils.ts +64 -0
- package/src/interpreter/components/hooks/YukigoHook.ts +45 -0
- package/src/interpreter/components/kernel/commands.ts +255 -0
- package/src/interpreter/components/kernel/index.ts +222 -0
- package/src/interpreter/components/logic/LogicEngine.ts +509 -519
- package/src/interpreter/components/logic/LogicResolver.ts +209 -858
- package/src/interpreter/components/logic/LogicTerm.ts +477 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +362 -149
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +249 -227
- package/src/interpreter/components/runtimes/LazyRuntime.ts +226 -334
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +262 -224
- package/src/interpreter/errors.ts +68 -47
- package/src/interpreter/index.ts +50 -52
- package/src/interpreter/primitives/YuValue.ts +64 -0
- package/src/interpreter/primitives/capabilities.ts +111 -0
- package/src/interpreter/primitives/entities/LazyList.ts +225 -0
- package/src/interpreter/primitives/entities/LogicResult.ts +133 -0
- package/src/interpreter/primitives/entities/RuntimeClass.ts +70 -0
- package/src/interpreter/primitives/entities/RuntimeFunction.ts +108 -0
- package/src/interpreter/primitives/entities/RuntimeObject.ts +110 -0
- package/src/interpreter/primitives/entities/RuntimePredicate.ts +77 -0
- package/src/interpreter/primitives/index.ts +17 -0
- package/src/interpreter/primitives/scalars/YuBoolean.ts +79 -0
- package/src/interpreter/primitives/scalars/YuChar.ts +94 -0
- package/src/interpreter/primitives/scalars/YuNil.ts +84 -0
- package/src/interpreter/primitives/scalars/YuNumber.ts +187 -0
- package/src/interpreter/primitives/sequences/YuArray.ts +178 -0
- package/src/interpreter/primitives/sequences/YuString.ts +165 -0
- package/src/interpreter/utils.ts +105 -84
- package/src/tester/index.ts +157 -128
- package/src/utils/helpers.ts +81 -168
- package/tests/analyzer/functional.spec.ts +221 -207
- package/tests/analyzer/generic.spec.ts +178 -178
- package/tests/analyzer/helpers.spec.ts +83 -89
- package/tests/analyzer/logic.spec.ts +237 -237
- package/tests/analyzer/oop.spec.ts +320 -323
- package/tests/analyzer/transitive.spec.ts +166 -166
- package/tests/interpreter/EnvBuilder.spec.ts +181 -183
- package/tests/interpreter/FunctionRuntime.spec.ts +224 -223
- package/tests/interpreter/LazyRuntime.spec.ts +227 -225
- package/tests/interpreter/LogicEngine.spec.ts +371 -327
- package/tests/interpreter/LogicSubstitution.spec.ts +90 -80
- package/tests/interpreter/ObjectRuntime.spec.ts +431 -606
- package/tests/interpreter/Operations.spec.ts +312 -220
- package/tests/interpreter/PatternSystem.spec.ts +254 -213
- package/tests/interpreter/Tests.spec.ts +122 -122
- package/tests/interpreter/interpreter.spec.ts +1143 -991
- package/tests/kernel/YukigoKernel.spec.ts +112 -0
- package/tests/tester/Tester.spec.ts +188 -152
- package/tsconfig.build.json +16 -15
- package/tsconfig.json +27 -25
- package/dist/interpreter/components/Visitor.d.ts +0 -70
- package/dist/interpreter/components/Visitor.js +0 -634
- package/dist/interpreter/entities.d.ts +0 -105
- package/dist/interpreter/entities.js +0 -96
- package/dist/interpreter/trampoline.d.ts +0 -17
- package/dist/interpreter/trampoline.js +0 -38
- package/dist/src/analyzer/GraphBuilder.d.ts +0 -30
- package/dist/src/analyzer/GraphBuilder.js +0 -100
- package/dist/src/analyzer/index.d.ts +0 -59
- package/dist/src/analyzer/index.js +0 -152
- package/dist/src/analyzer/inspections/functional/functional.d.ts +0 -44
- package/dist/src/analyzer/inspections/functional/functional.js +0 -149
- package/dist/src/analyzer/inspections/functional/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/functional/smells.js +0 -98
- package/dist/src/analyzer/inspections/generic/generic.d.ts +0 -178
- package/dist/src/analyzer/inspections/generic/generic.js +0 -604
- package/dist/src/analyzer/inspections/generic/smells.d.ts +0 -61
- package/dist/src/analyzer/inspections/generic/smells.js +0 -349
- package/dist/src/analyzer/inspections/imperative/imperative.d.ts +0 -35
- package/dist/src/analyzer/inspections/imperative/imperative.js +0 -109
- package/dist/src/analyzer/inspections/imperative/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/imperative/smells.js +0 -58
- package/dist/src/analyzer/inspections/logic/logic.d.ts +0 -32
- package/dist/src/analyzer/inspections/logic/logic.js +0 -96
- package/dist/src/analyzer/inspections/logic/smells.d.ts +0 -15
- package/dist/src/analyzer/inspections/logic/smells.js +0 -60
- package/dist/src/analyzer/inspections/object/object.d.ts +0 -90
- package/dist/src/analyzer/inspections/object/object.js +0 -321
- package/dist/src/analyzer/inspections/object/smells.d.ts +0 -30
- package/dist/src/analyzer/inspections/object/smells.js +0 -135
- package/dist/src/analyzer/utils.d.ts +0 -30
- package/dist/src/analyzer/utils.js +0 -78
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -4
- package/dist/src/interpreter/components/EnvBuilder.d.ts +0 -21
- package/dist/src/interpreter/components/EnvBuilder.js +0 -155
- package/dist/src/interpreter/components/Operations.d.ts +0 -14
- package/dist/src/interpreter/components/Operations.js +0 -84
- package/dist/src/interpreter/components/PatternMatcher.d.ts +0 -73
- package/dist/src/interpreter/components/PatternMatcher.js +0 -358
- package/dist/src/interpreter/components/RuntimeContext.d.ts +0 -35
- package/dist/src/interpreter/components/RuntimeContext.js +0 -93
- package/dist/src/interpreter/components/TestRunner.d.ts +0 -19
- package/dist/src/interpreter/components/TestRunner.js +0 -110
- package/dist/src/interpreter/components/Visitor.d.ts +0 -71
- package/dist/src/interpreter/components/Visitor.js +0 -638
- package/dist/src/interpreter/components/logic/LogicEngine.d.ts +0 -29
- package/dist/src/interpreter/components/logic/LogicEngine.js +0 -259
- package/dist/src/interpreter/components/logic/LogicResolver.d.ts +0 -53
- package/dist/src/interpreter/components/logic/LogicResolver.js +0 -484
- package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +0 -14
- package/dist/src/interpreter/components/logic/LogicTranslator.js +0 -99
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +0 -12
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +0 -149
- package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +0 -19
- package/dist/src/interpreter/components/runtimes/LazyRuntime.js +0 -269
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +0 -35
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +0 -126
- package/dist/src/interpreter/errors.d.ts +0 -19
- package/dist/src/interpreter/errors.js +0 -36
- package/dist/src/interpreter/index.d.ts +0 -24
- package/dist/src/interpreter/index.js +0 -41
- package/dist/src/interpreter/trampoline.d.ts +0 -17
- package/dist/src/interpreter/trampoline.js +0 -38
- package/dist/src/interpreter/utils.d.ts +0 -11
- package/dist/src/interpreter/utils.js +0 -65
- package/dist/src/tester/index.d.ts +0 -25
- package/dist/src/tester/index.js +0 -113
- package/dist/src/utils/helpers.d.ts +0 -13
- package/dist/src/utils/helpers.js +0 -52
- package/src/interpreter/components/Visitor.ts +0 -1065
- package/src/interpreter/trampoline.ts +0 -71
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Lambda, Equation,
|
|
1
|
+
import { Lambda, Equation, Guard } from "yukigo-ast";
|
|
2
2
|
import { ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
3
3
|
export declare class HasRedundantLambda extends ScopedVisitor {
|
|
4
4
|
visitLambda(node: Lambda): void;
|
|
5
5
|
}
|
|
6
6
|
export declare class HasRedundantGuards extends ScopedVisitor {
|
|
7
|
-
|
|
7
|
+
visitGuard(node: Guard): void;
|
|
8
8
|
private isAlwaysTrue;
|
|
9
9
|
}
|
|
10
10
|
export declare class ShouldUseOtherwise extends ScopedVisitor {
|
|
11
|
-
|
|
11
|
+
visitGuard(node: Guard): void;
|
|
12
12
|
}
|
|
13
13
|
export declare class HasRedundantParameter extends ScopedVisitor {
|
|
14
14
|
visitEquation(node: Equation): void;
|
|
@@ -4,24 +4,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { Call, VariablePattern, Variable, StopTraversalException, BooleanPrimitive, Application,
|
|
7
|
+
import { Call, VariablePattern, Variable, StopTraversalException, BooleanPrimitive, Application, Otherwise, } from "yukigo-ast";
|
|
8
8
|
import { AutoScoped, ScopedVisitor } from "../../utils.js";
|
|
9
9
|
import { Uses } from "../generic/generic.js";
|
|
10
10
|
let HasRedundantLambda = class HasRedundantLambda extends ScopedVisitor {
|
|
11
11
|
visitLambda(node) {
|
|
12
12
|
if (node.parameters.length !== 1)
|
|
13
13
|
return;
|
|
14
|
-
if (!
|
|
14
|
+
if (!node.body.is(Application))
|
|
15
15
|
return;
|
|
16
16
|
const param = node.parameters[0];
|
|
17
17
|
const call = node.body;
|
|
18
|
-
if (call.functionExpr
|
|
19
|
-
call.functionExpr instanceof Call)
|
|
18
|
+
if (call.functionExpr.is(Application) || call.functionExpr.is(Call))
|
|
20
19
|
return;
|
|
21
20
|
const arg = call.parameter;
|
|
22
|
-
|
|
23
|
-
arg
|
|
24
|
-
param.name.value === arg.identifier.value
|
|
21
|
+
const hasRedudantParam = param.is(VariablePattern) &&
|
|
22
|
+
arg.is(Variable) &&
|
|
23
|
+
param.name.value === arg.identifier.value;
|
|
24
|
+
if (hasRedudantParam)
|
|
25
25
|
throw new StopTraversalException();
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -30,23 +30,16 @@ HasRedundantLambda = __decorate([
|
|
|
30
30
|
], HasRedundantLambda);
|
|
31
31
|
export { HasRedundantLambda };
|
|
32
32
|
let HasRedundantGuards = class HasRedundantGuards extends ScopedVisitor {
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
// If there is only 1 guard...
|
|
37
|
-
if (node.body.length === 1) {
|
|
38
|
-
const guard = node.body[0];
|
|
39
|
-
// ...and that guard is "True" or "otherwise"
|
|
40
|
-
if (this.isAlwaysTrue(guard.condition))
|
|
41
|
-
throw new StopTraversalException();
|
|
42
|
-
}
|
|
33
|
+
visitGuard(node) {
|
|
34
|
+
if (this.isAlwaysTrue(node.condition))
|
|
35
|
+
throw new StopTraversalException();
|
|
43
36
|
}
|
|
44
37
|
isAlwaysTrue(node) {
|
|
45
38
|
// check for boolean literal 'True'
|
|
46
|
-
if (node
|
|
39
|
+
if (node.is(BooleanPrimitive) && node.value === true)
|
|
47
40
|
return true;
|
|
48
41
|
// check for default case
|
|
49
|
-
if (node
|
|
42
|
+
if (node.is(Otherwise))
|
|
50
43
|
return true;
|
|
51
44
|
return false;
|
|
52
45
|
}
|
|
@@ -56,9 +49,8 @@ HasRedundantGuards = __decorate([
|
|
|
56
49
|
], HasRedundantGuards);
|
|
57
50
|
export { HasRedundantGuards };
|
|
58
51
|
let ShouldUseOtherwise = class ShouldUseOtherwise extends ScopedVisitor {
|
|
59
|
-
|
|
60
|
-
if (node.condition
|
|
61
|
-
node.condition.value === true)
|
|
52
|
+
visitGuard(node) {
|
|
53
|
+
if (node.condition.is(BooleanPrimitive) && node.condition.value === true)
|
|
62
54
|
throw new StopTraversalException();
|
|
63
55
|
}
|
|
64
56
|
};
|
|
@@ -69,19 +61,19 @@ export { ShouldUseOtherwise };
|
|
|
69
61
|
let HasRedundantParameter = class HasRedundantParameter extends ScopedVisitor {
|
|
70
62
|
visitEquation(node) {
|
|
71
63
|
for (const pattern of node.patterns) {
|
|
72
|
-
if (pattern
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
64
|
+
if (!pattern.is(VariablePattern))
|
|
65
|
+
continue;
|
|
66
|
+
const paramName = pattern.name.value;
|
|
67
|
+
const usageChecker = new Uses(paramName, this.binding);
|
|
68
|
+
try {
|
|
69
|
+
node.accept(usageChecker);
|
|
70
|
+
// uses didnt throw so the param is not being used
|
|
71
|
+
throw new StopTraversalException();
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
if (e instanceof StopTraversalException)
|
|
75
|
+
continue;
|
|
76
|
+
throw e;
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArithmeticBinaryOperation, ArithmeticUnaryOperation, Assignment,
|
|
2
|
-
import { VisitorConstructor, ScopedVisitor } from "../../utils.js";
|
|
1
|
+
import { ArithmeticBinaryOperation, ArithmeticUnaryOperation, Assignment, Attribute, Call, Catch, Class, EntryPoint, Equation, Fact, Function, If, LogicalBinaryOperation, LogicalUnaryOperation, Method, Object, Print, Procedure, Raise, Record as RecordNode, Rule, SimpleType, SymbolPrimitive, Try, TypeAlias, TypeSignature, TypeVar, Variable } from "yukigo-ast";
|
|
2
|
+
import { VisitorConstructor, ScopedVisitor, InspectionVisitor } from "../../utils.js";
|
|
3
3
|
export declare class Assigns extends ScopedVisitor {
|
|
4
4
|
private readonly targetIdentifier;
|
|
5
5
|
constructor(targetIdentifier: string, scope?: string);
|
|
@@ -44,7 +44,7 @@ export declare class DeclaresComputationWithArity extends ScopedVisitor {
|
|
|
44
44
|
visitFact(node: Fact): void;
|
|
45
45
|
visitRule(node: Rule): void;
|
|
46
46
|
}
|
|
47
|
-
export declare class DeclaresEntryPoint extends
|
|
47
|
+
export declare class DeclaresEntryPoint extends InspectionVisitor {
|
|
48
48
|
visitEntryPoint(node: EntryPoint): void;
|
|
49
49
|
}
|
|
50
50
|
export declare class DeclaresFunction extends ScopedVisitor {
|
|
@@ -52,6 +52,7 @@ export declare class DeclaresFunction extends ScopedVisitor {
|
|
|
52
52
|
constructor(targetBinding: string, scope?: string);
|
|
53
53
|
visitFunction(node: Function): void;
|
|
54
54
|
}
|
|
55
|
+
type CallableDeclaration = Function | Method | Procedure | Fact | Rule;
|
|
55
56
|
export declare class DeclaresRecursively extends ScopedVisitor {
|
|
56
57
|
private readonly targetBinding;
|
|
57
58
|
constructor(targetBinding: string, scope?: string);
|
|
@@ -60,9 +61,9 @@ export declare class DeclaresRecursively extends ScopedVisitor {
|
|
|
60
61
|
visitProcedure(node: Procedure): void;
|
|
61
62
|
visitFact(node: Fact): void;
|
|
62
63
|
visitRule(node: Rule): void;
|
|
63
|
-
visitNested(node:
|
|
64
|
+
visitNested(node: CallableDeclaration): void;
|
|
64
65
|
}
|
|
65
|
-
export declare class HasDirectRecursion extends
|
|
66
|
+
export declare class HasDirectRecursion extends InspectionVisitor {
|
|
66
67
|
private readonly binding;
|
|
67
68
|
private isInsideBody;
|
|
68
69
|
constructor(binding: string);
|
|
@@ -73,12 +74,12 @@ export declare class HasDirectRecursion extends TraverseVisitor {
|
|
|
73
74
|
visitEquation(node: Equation): void;
|
|
74
75
|
visitSymbolPrimitive(node: SymbolPrimitive): void;
|
|
75
76
|
}
|
|
76
|
-
export declare class DeclaresTypeAlias extends
|
|
77
|
+
export declare class DeclaresTypeAlias extends InspectionVisitor {
|
|
77
78
|
private readonly typeAliasName;
|
|
78
79
|
constructor(typeAliasName: string);
|
|
79
80
|
visitTypeAlias(node: TypeAlias): void;
|
|
80
81
|
}
|
|
81
|
-
export declare class DeclaresTypeSignature extends
|
|
82
|
+
export declare class DeclaresTypeSignature extends InspectionVisitor {
|
|
82
83
|
private readonly targetBinding;
|
|
83
84
|
constructor(targetBinding: string);
|
|
84
85
|
visitTypeSignature(node: TypeSignature): void;
|
|
@@ -121,41 +122,46 @@ export declare class UsesType extends ScopedVisitor {
|
|
|
121
122
|
visitSimpleType(node: SimpleType): void;
|
|
122
123
|
visitTypeVar(node: TypeVar): void;
|
|
123
124
|
}
|
|
124
|
-
export declare class HasBinding extends
|
|
125
|
+
export declare class HasBinding extends InspectionVisitor {
|
|
126
|
+
private readonly targetBinding;
|
|
127
|
+
constructor(targetBinding: string);
|
|
128
|
+
private check;
|
|
125
129
|
visitFunction(node: Function): void;
|
|
126
130
|
visitObject(node: Object): void;
|
|
127
131
|
visitClass(node: Class): void;
|
|
128
132
|
visitRule(node: Rule): void;
|
|
129
133
|
visitFact(node: Fact): void;
|
|
130
134
|
visitTypeAlias(node: TypeAlias): void;
|
|
131
|
-
visitTypeSignature(node: TypeSignature): void;
|
|
132
135
|
visitRecord(node: RecordNode): void;
|
|
136
|
+
visitVariable(node: Variable): void;
|
|
137
|
+
visitMethod(node: Method): void;
|
|
138
|
+
visitProcedure(node: Procedure): void;
|
|
133
139
|
}
|
|
134
|
-
export declare class SubordinatesDeclarationsTo extends
|
|
140
|
+
export declare class SubordinatesDeclarationsTo extends InspectionVisitor {
|
|
135
141
|
private childName;
|
|
136
142
|
private parentName;
|
|
137
143
|
constructor(childName: string, parentName: string);
|
|
138
144
|
visitFunction(node: Function): void;
|
|
139
145
|
}
|
|
140
|
-
export declare class SubordinatesDeclarationsToEntryPoint extends
|
|
146
|
+
export declare class SubordinatesDeclarationsToEntryPoint extends InspectionVisitor {
|
|
141
147
|
private childName;
|
|
142
148
|
constructor(childName: string);
|
|
143
149
|
visitEntryPoint(node: EntryPoint): void;
|
|
144
150
|
}
|
|
145
|
-
export declare class TypesAs extends
|
|
151
|
+
export declare class TypesAs extends InspectionVisitor {
|
|
146
152
|
private typeName;
|
|
147
153
|
private bindingName;
|
|
148
154
|
constructor(typeName: string, bindingName: string);
|
|
149
155
|
visitTypeSignature(node: TypeSignature): void;
|
|
150
156
|
}
|
|
151
|
-
export declare class TypesParameterAs extends
|
|
157
|
+
export declare class TypesParameterAs extends InspectionVisitor {
|
|
152
158
|
private paramIndex;
|
|
153
159
|
private typeName;
|
|
154
160
|
private bindingName;
|
|
155
161
|
constructor(paramIndex: number, typeName: string, bindingName: string);
|
|
156
162
|
visitTypeSignature(node: TypeSignature): void;
|
|
157
163
|
}
|
|
158
|
-
export declare class TypesReturnAs extends
|
|
164
|
+
export declare class TypesReturnAs extends InspectionVisitor {
|
|
159
165
|
private typeName;
|
|
160
166
|
private bindingName;
|
|
161
167
|
constructor(typeName: string, bindingName: string);
|
|
@@ -176,3 +182,4 @@ export declare class UsesExceptions extends ScopedVisitor {
|
|
|
176
182
|
visitRaise(node: Raise): void;
|
|
177
183
|
}
|
|
178
184
|
export declare const genericInspections: Record<string, VisitorConstructor>;
|
|
185
|
+
export {};
|
|
@@ -4,8 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
8
|
-
import { ScopedVisitor, AutoScoped } from "../../utils.js";
|
|
7
|
+
import { NativeBody, ParameterizedType, StopTraversalException, SymbolPrimitive, VariablePattern, } from "yukigo-ast";
|
|
8
|
+
import { ScopedVisitor, InspectionVisitor, AutoScoped, } from "../../utils.js";
|
|
9
9
|
let Assigns = class Assigns extends ScopedVisitor {
|
|
10
10
|
targetIdentifier;
|
|
11
11
|
constructor(targetIdentifier, scope) {
|
|
@@ -158,7 +158,7 @@ DeclaresComputationWithArity = __decorate([
|
|
|
158
158
|
AutoScoped
|
|
159
159
|
], DeclaresComputationWithArity);
|
|
160
160
|
export { DeclaresComputationWithArity };
|
|
161
|
-
export class DeclaresEntryPoint extends
|
|
161
|
+
export class DeclaresEntryPoint extends InspectionVisitor {
|
|
162
162
|
visitEntryPoint(node) {
|
|
163
163
|
throw new StopTraversalException();
|
|
164
164
|
}
|
|
@@ -182,7 +182,7 @@ let DeclaresRecursively = class DeclaresRecursively extends ScopedVisitor {
|
|
|
182
182
|
targetBinding;
|
|
183
183
|
constructor(targetBinding, scope) {
|
|
184
184
|
super(scope);
|
|
185
|
-
this.targetBinding = targetBinding;
|
|
185
|
+
this.targetBinding = new SymbolPrimitive(targetBinding);
|
|
186
186
|
}
|
|
187
187
|
visitFunction(node) {
|
|
188
188
|
super.visitFunction(node);
|
|
@@ -205,9 +205,8 @@ let DeclaresRecursively = class DeclaresRecursively extends ScopedVisitor {
|
|
|
205
205
|
this.visitNested(node);
|
|
206
206
|
}
|
|
207
207
|
visitNested(node) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
node.identifier.value === this.targetBinding)
|
|
208
|
+
const hasOwnIdentifier = node.identifier.equals(this.targetBinding);
|
|
209
|
+
if (hasOwnIdentifier)
|
|
211
210
|
throw new StopTraversalException();
|
|
212
211
|
}
|
|
213
212
|
};
|
|
@@ -215,7 +214,7 @@ DeclaresRecursively = __decorate([
|
|
|
215
214
|
AutoScoped
|
|
216
215
|
], DeclaresRecursively);
|
|
217
216
|
export { DeclaresRecursively };
|
|
218
|
-
export class HasDirectRecursion extends
|
|
217
|
+
export class HasDirectRecursion extends InspectionVisitor {
|
|
219
218
|
binding;
|
|
220
219
|
isInsideBody = false;
|
|
221
220
|
constructor(binding) {
|
|
@@ -245,12 +244,9 @@ export class HasDirectRecursion extends TraverseVisitor {
|
|
|
245
244
|
visitEquation(node) {
|
|
246
245
|
this.isInsideBody = true;
|
|
247
246
|
try {
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
else {
|
|
252
|
-
this.traverseCollection(node.body);
|
|
253
|
-
}
|
|
247
|
+
if (node.body instanceof NativeBody)
|
|
248
|
+
return;
|
|
249
|
+
node.body.accept(this);
|
|
254
250
|
}
|
|
255
251
|
finally {
|
|
256
252
|
this.isInsideBody = false;
|
|
@@ -261,7 +257,7 @@ export class HasDirectRecursion extends TraverseVisitor {
|
|
|
261
257
|
throw new StopTraversalException();
|
|
262
258
|
}
|
|
263
259
|
}
|
|
264
|
-
export class DeclaresTypeAlias extends
|
|
260
|
+
export class DeclaresTypeAlias extends InspectionVisitor {
|
|
265
261
|
typeAliasName;
|
|
266
262
|
constructor(typeAliasName) {
|
|
267
263
|
super();
|
|
@@ -272,7 +268,7 @@ export class DeclaresTypeAlias extends TraverseVisitor {
|
|
|
272
268
|
throw new StopTraversalException();
|
|
273
269
|
}
|
|
274
270
|
}
|
|
275
|
-
export class DeclaresTypeSignature extends
|
|
271
|
+
export class DeclaresTypeSignature extends InspectionVisitor {
|
|
276
272
|
targetBinding;
|
|
277
273
|
constructor(targetBinding) {
|
|
278
274
|
super();
|
|
@@ -398,37 +394,59 @@ UsesType = __decorate([
|
|
|
398
394
|
AutoScoped
|
|
399
395
|
], UsesType);
|
|
400
396
|
export { UsesType };
|
|
401
|
-
|
|
397
|
+
export class HasBinding extends InspectionVisitor {
|
|
398
|
+
targetBinding;
|
|
399
|
+
constructor(targetBinding) {
|
|
400
|
+
super();
|
|
401
|
+
this.targetBinding = targetBinding;
|
|
402
|
+
}
|
|
403
|
+
check(identifier) {
|
|
404
|
+
if (identifier && identifier.value === this.targetBinding) {
|
|
405
|
+
throw new StopTraversalException();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
402
408
|
visitFunction(node) {
|
|
403
|
-
|
|
409
|
+
this.check(node.identifier);
|
|
410
|
+
super.visitFunction(node);
|
|
404
411
|
}
|
|
405
412
|
visitObject(node) {
|
|
406
|
-
|
|
413
|
+
this.check(node.identifier);
|
|
414
|
+
super.visitObject(node);
|
|
407
415
|
}
|
|
408
416
|
visitClass(node) {
|
|
409
|
-
|
|
417
|
+
this.check(node.identifier);
|
|
418
|
+
super.visitClass(node);
|
|
410
419
|
}
|
|
411
420
|
visitRule(node) {
|
|
412
|
-
|
|
421
|
+
this.check(node.identifier);
|
|
422
|
+
super.visitRule(node);
|
|
413
423
|
}
|
|
414
424
|
visitFact(node) {
|
|
415
|
-
|
|
425
|
+
this.check(node.identifier);
|
|
426
|
+
super.visitFact(node);
|
|
416
427
|
}
|
|
417
428
|
visitTypeAlias(node) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
visitTypeSignature(node) {
|
|
421
|
-
throw new StopTraversalException();
|
|
429
|
+
this.check(node.identifier);
|
|
430
|
+
super.visitTypeAlias(node);
|
|
422
431
|
}
|
|
423
432
|
visitRecord(node) {
|
|
424
|
-
|
|
433
|
+
this.check(node.name);
|
|
434
|
+
super.visitRecord(node);
|
|
425
435
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
436
|
+
visitVariable(node) {
|
|
437
|
+
this.check(node.identifier);
|
|
438
|
+
super.visitVariable(node);
|
|
439
|
+
}
|
|
440
|
+
visitMethod(node) {
|
|
441
|
+
this.check(node.identifier);
|
|
442
|
+
super.visitMethod(node);
|
|
443
|
+
}
|
|
444
|
+
visitProcedure(node) {
|
|
445
|
+
this.check(node.identifier);
|
|
446
|
+
super.visitProcedure(node);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
export class SubordinatesDeclarationsTo extends InspectionVisitor {
|
|
432
450
|
childName;
|
|
433
451
|
parentName;
|
|
434
452
|
constructor(childName, parentName) {
|
|
@@ -446,7 +464,7 @@ export class SubordinatesDeclarationsTo extends TraverseVisitor {
|
|
|
446
464
|
}
|
|
447
465
|
}
|
|
448
466
|
}
|
|
449
|
-
export class SubordinatesDeclarationsToEntryPoint extends
|
|
467
|
+
export class SubordinatesDeclarationsToEntryPoint extends InspectionVisitor {
|
|
450
468
|
childName;
|
|
451
469
|
constructor(childName) {
|
|
452
470
|
super();
|
|
@@ -457,7 +475,7 @@ export class SubordinatesDeclarationsToEntryPoint extends TraverseVisitor {
|
|
|
457
475
|
node.expression.statements.forEach((stmt) => stmt.accept(childFinder));
|
|
458
476
|
}
|
|
459
477
|
}
|
|
460
|
-
export class TypesAs extends
|
|
478
|
+
export class TypesAs extends InspectionVisitor {
|
|
461
479
|
typeName;
|
|
462
480
|
bindingName;
|
|
463
481
|
constructor(typeName, bindingName) {
|
|
@@ -475,7 +493,11 @@ export class TypesAs extends TraverseVisitor {
|
|
|
475
493
|
}
|
|
476
494
|
}
|
|
477
495
|
}
|
|
478
|
-
|
|
496
|
+
function isFormatAgnosticMatch(actual, expected) {
|
|
497
|
+
const normalize = (str) => str.replace(/\s+/g, " ").trim();
|
|
498
|
+
return normalize(actual) === normalize(expected);
|
|
499
|
+
}
|
|
500
|
+
export class TypesParameterAs extends InspectionVisitor {
|
|
479
501
|
paramIndex;
|
|
480
502
|
typeName;
|
|
481
503
|
bindingName;
|
|
@@ -486,21 +508,19 @@ export class TypesParameterAs extends TraverseVisitor {
|
|
|
486
508
|
this.bindingName = bindingName;
|
|
487
509
|
}
|
|
488
510
|
visitTypeSignature(node) {
|
|
489
|
-
if (node.identifier.value
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
}
|
|
511
|
+
if (node.identifier.value !== this.bindingName)
|
|
512
|
+
return;
|
|
513
|
+
if (!node.body.is(ParameterizedType))
|
|
514
|
+
return;
|
|
515
|
+
const paramType = node.body.inputs[this.paramIndex];
|
|
516
|
+
if (!paramType)
|
|
517
|
+
return;
|
|
518
|
+
const actualType = paramType.toString();
|
|
519
|
+
if (isFormatAgnosticMatch(actualType, this.typeName))
|
|
520
|
+
throw new StopTraversalException();
|
|
501
521
|
}
|
|
502
522
|
}
|
|
503
|
-
export class TypesReturnAs extends
|
|
523
|
+
export class TypesReturnAs extends InspectionVisitor {
|
|
504
524
|
typeName;
|
|
505
525
|
bindingName;
|
|
506
526
|
constructor(typeName, bindingName) {
|
|
@@ -509,14 +529,12 @@ export class TypesReturnAs extends TraverseVisitor {
|
|
|
509
529
|
this.bindingName = bindingName;
|
|
510
530
|
}
|
|
511
531
|
visitTypeSignature(node) {
|
|
512
|
-
if (node.identifier.value
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
}
|
|
532
|
+
if (node.identifier.value !== this.bindingName)
|
|
533
|
+
return;
|
|
534
|
+
if (node.body.is(ParameterizedType)) {
|
|
535
|
+
const actualType = node.body.returnType.toString();
|
|
536
|
+
if (isFormatAgnosticMatch(actualType, this.typeName))
|
|
537
|
+
throw new StopTraversalException();
|
|
520
538
|
}
|
|
521
539
|
}
|
|
522
540
|
}
|
|
@@ -528,8 +546,9 @@ let Rescues = class Rescues extends ScopedVisitor {
|
|
|
528
546
|
}
|
|
529
547
|
visitCatch(node) {
|
|
530
548
|
for (const pattern of node.patterns) {
|
|
531
|
-
|
|
532
|
-
pattern.name.value === this.exceptionName
|
|
549
|
+
const capturesExceptionAs = pattern.is(VariablePattern) &&
|
|
550
|
+
pattern.name.value === this.exceptionName;
|
|
551
|
+
if (capturesExceptionAs) {
|
|
533
552
|
throw new StopTraversalException();
|
|
534
553
|
}
|
|
535
554
|
}
|
|
@@ -32,9 +32,11 @@ export declare class HasRedundantBooleanComparison extends ScopedVisitor {
|
|
|
32
32
|
}
|
|
33
33
|
export declare class HasRedundantIf extends ScopedVisitor {
|
|
34
34
|
visitIf(node: If): void;
|
|
35
|
+
private isBooleanBlock;
|
|
35
36
|
}
|
|
36
37
|
export declare class HasRedundantLocalVariableReturn extends ScopedVisitor {
|
|
37
38
|
visitSequence(node: Sequence): void;
|
|
39
|
+
private isPointlessAssignment;
|
|
38
40
|
}
|
|
39
41
|
export declare class HasTooShortIdentifiers extends ScopedVisitor {
|
|
40
42
|
private readonly minLength;
|