yukigo 0.2.0 → 0.2.3

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 (76) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/analyzer/index.d.ts +7 -0
  3. package/dist/analyzer/inspections/generic/generic.d.ts +1 -2
  4. package/dist/analyzer/inspections/generic/generic.js +2 -5
  5. package/dist/src/analyzer/GraphBuilder.d.ts +30 -0
  6. package/dist/src/analyzer/GraphBuilder.js +100 -0
  7. package/dist/src/analyzer/index.d.ts +59 -0
  8. package/dist/src/analyzer/index.js +152 -0
  9. package/dist/src/analyzer/inspections/functional/functional.d.ts +44 -0
  10. package/dist/src/analyzer/inspections/functional/functional.js +149 -0
  11. package/dist/src/analyzer/inspections/functional/smells.d.ts +16 -0
  12. package/dist/src/analyzer/inspections/functional/smells.js +98 -0
  13. package/dist/src/analyzer/inspections/generic/generic.d.ts +178 -0
  14. package/dist/src/analyzer/inspections/generic/generic.js +604 -0
  15. package/dist/src/analyzer/inspections/generic/smells.d.ts +61 -0
  16. package/dist/src/analyzer/inspections/generic/smells.js +349 -0
  17. package/dist/src/analyzer/inspections/imperative/imperative.d.ts +35 -0
  18. package/dist/src/analyzer/inspections/imperative/imperative.js +109 -0
  19. package/dist/src/analyzer/inspections/imperative/smells.d.ts +16 -0
  20. package/dist/src/analyzer/inspections/imperative/smells.js +58 -0
  21. package/dist/src/analyzer/inspections/logic/logic.d.ts +32 -0
  22. package/dist/src/analyzer/inspections/logic/logic.js +96 -0
  23. package/dist/src/analyzer/inspections/logic/smells.d.ts +15 -0
  24. package/dist/src/analyzer/inspections/logic/smells.js +60 -0
  25. package/dist/src/analyzer/inspections/object/object.d.ts +90 -0
  26. package/dist/src/analyzer/inspections/object/object.js +321 -0
  27. package/dist/src/analyzer/inspections/object/smells.d.ts +30 -0
  28. package/dist/src/analyzer/inspections/object/smells.js +135 -0
  29. package/dist/src/analyzer/utils.d.ts +30 -0
  30. package/dist/src/analyzer/utils.js +78 -0
  31. package/dist/src/index.d.ts +4 -0
  32. package/dist/src/index.js +4 -0
  33. package/dist/src/interpreter/components/EnvBuilder.d.ts +21 -0
  34. package/dist/src/interpreter/components/EnvBuilder.js +155 -0
  35. package/dist/src/interpreter/components/Operations.d.ts +14 -0
  36. package/dist/src/interpreter/components/Operations.js +84 -0
  37. package/dist/src/interpreter/components/PatternMatcher.d.ts +73 -0
  38. package/dist/src/interpreter/components/PatternMatcher.js +358 -0
  39. package/dist/src/interpreter/components/RuntimeContext.d.ts +35 -0
  40. package/dist/src/interpreter/components/RuntimeContext.js +93 -0
  41. package/dist/src/interpreter/components/TestRunner.d.ts +19 -0
  42. package/dist/src/interpreter/components/TestRunner.js +110 -0
  43. package/dist/src/interpreter/components/Visitor.d.ts +71 -0
  44. package/dist/src/interpreter/components/Visitor.js +638 -0
  45. package/dist/src/interpreter/components/logic/LogicEngine.d.ts +29 -0
  46. package/dist/src/interpreter/components/logic/LogicEngine.js +259 -0
  47. package/dist/src/interpreter/components/logic/LogicResolver.d.ts +53 -0
  48. package/dist/src/interpreter/components/logic/LogicResolver.js +484 -0
  49. package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +14 -0
  50. package/dist/src/interpreter/components/logic/LogicTranslator.js +99 -0
  51. package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +12 -0
  52. package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +149 -0
  53. package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +19 -0
  54. package/dist/src/interpreter/components/runtimes/LazyRuntime.js +269 -0
  55. package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +35 -0
  56. package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +126 -0
  57. package/dist/src/interpreter/errors.d.ts +19 -0
  58. package/dist/src/interpreter/errors.js +36 -0
  59. package/dist/src/interpreter/index.d.ts +24 -0
  60. package/dist/src/interpreter/index.js +41 -0
  61. package/dist/src/interpreter/trampoline.d.ts +17 -0
  62. package/dist/src/interpreter/trampoline.js +38 -0
  63. package/dist/src/interpreter/utils.d.ts +11 -0
  64. package/dist/src/interpreter/utils.js +65 -0
  65. package/dist/src/tester/index.d.ts +25 -0
  66. package/dist/src/tester/index.js +113 -0
  67. package/dist/src/utils/helpers.d.ts +13 -0
  68. package/dist/src/utils/helpers.js +52 -0
  69. package/dist/utils/helpers.d.ts +5 -1
  70. package/dist/utils/helpers.js +82 -6
  71. package/package.json +4 -2
  72. package/src/analyzer/index.ts +9 -0
  73. package/src/analyzer/inspections/generic/generic.ts +2 -6
  74. package/src/utils/helpers.ts +112 -10
  75. package/tests/analyzer/helpers.spec.ts +16 -10
  76. package/tests/tester/Tester.spec.ts +0 -1
@@ -0,0 +1,349 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BooleanPrimitive, Call, Function, NilPrimitive, Return, Sequence, StopTraversalException, SymbolPrimitive, Variable, } from "yukigo-ast";
8
+ import { AutoScoped, ScopedVisitor } from "../../utils.js";
9
+ function isSequenceEmpty(node) {
10
+ return node instanceof Sequence && node.statements.length === 0;
11
+ }
12
+ /**
13
+ * Basic Levenshtein distance for typo detection
14
+ */
15
+ function getLevenshteinDistance(a, b) {
16
+ const matrix = [];
17
+ for (let i = 0; i <= b.length; i++)
18
+ matrix[i] = [i];
19
+ for (let j = 0; j <= a.length; j++)
20
+ matrix[0][j] = j;
21
+ for (let i = 1; i <= b.length; i++) {
22
+ for (let j = 1; j <= a.length; j++) {
23
+ if (b.charAt(i - 1) === a.charAt(j - 1)) {
24
+ matrix[i][j] = matrix[i - 1][j - 1];
25
+ }
26
+ else {
27
+ matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
28
+ }
29
+ }
30
+ }
31
+ return matrix[b.length][a.length];
32
+ }
33
+ let DiscardsExceptions = class DiscardsExceptions extends ScopedVisitor {
34
+ visitCatch(node) {
35
+ if (!node.body ||
36
+ node.body instanceof NilPrimitive ||
37
+ isSequenceEmpty(node.body)) {
38
+ throw new StopTraversalException();
39
+ }
40
+ }
41
+ };
42
+ DiscardsExceptions = __decorate([
43
+ AutoScoped
44
+ ], DiscardsExceptions);
45
+ export { DiscardsExceptions };
46
+ let DoesConsolePrint = class DoesConsolePrint extends ScopedVisitor {
47
+ visitPrint(node) {
48
+ throw new StopTraversalException();
49
+ }
50
+ visitCall(node) {
51
+ const name = node.callee.value;
52
+ if (this.isPrintFunc(name))
53
+ throw new StopTraversalException();
54
+ }
55
+ visitApplication(node) {
56
+ const func = node.functionExpr;
57
+ if (!(func instanceof SymbolPrimitive))
58
+ return func.accept(this);
59
+ const name = func.value;
60
+ if (this.isPrintFunc(name))
61
+ throw new StopTraversalException();
62
+ }
63
+ isPrintFunc(name) {
64
+ const printFuncs = [
65
+ "print",
66
+ "println",
67
+ "puts",
68
+ "log",
69
+ "console.log",
70
+ "System.out.println",
71
+ "fmt.Println",
72
+ ];
73
+ if (printFuncs.includes(name))
74
+ return true;
75
+ return false;
76
+ }
77
+ };
78
+ DoesConsolePrint = __decorate([
79
+ AutoScoped
80
+ ], DoesConsolePrint);
81
+ export { DoesConsolePrint };
82
+ let HasDeclarationTypos = class HasDeclarationTypos extends ScopedVisitor {
83
+ /*
84
+ * Checks if two variables declared in the same scope are suspiciously similar
85
+ * (Levenshtein distance <= 2), indicating a possible typo (e.g., 'count' vs 'conut').
86
+ */
87
+ visitSequence(node) {
88
+ const declaredNames = [];
89
+ for (const stmt of node.statements) {
90
+ if (stmt instanceof Variable)
91
+ declaredNames.push(stmt.identifier.value);
92
+ }
93
+ for (let i = 0; i < declaredNames.length; i++) {
94
+ for (let j = i + 1; j < declaredNames.length; j++) {
95
+ const a = declaredNames[i];
96
+ const b = declaredNames[j];
97
+ if (a.length > 3 && b.length > 3) {
98
+ if (getLevenshteinDistance(a, b) <= 2) {
99
+ throw new StopTraversalException();
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ };
106
+ HasDeclarationTypos = __decorate([
107
+ AutoScoped
108
+ ], HasDeclarationTypos);
109
+ export { HasDeclarationTypos };
110
+ let HasEmptyIfBranches = class HasEmptyIfBranches extends ScopedVisitor {
111
+ visitIf(node) {
112
+ const isThenEmpty = !node.then || isSequenceEmpty(node.then);
113
+ const isElseEmpty = node.elseExpr && isSequenceEmpty(node.elseExpr);
114
+ if (isThenEmpty || isElseEmpty)
115
+ throw new StopTraversalException();
116
+ }
117
+ };
118
+ HasEmptyIfBranches = __decorate([
119
+ AutoScoped
120
+ ], HasEmptyIfBranches);
121
+ export { HasEmptyIfBranches };
122
+ let HasLongParameterList = class HasLongParameterList extends ScopedVisitor {
123
+ maxParams;
124
+ constructor(maxParams = 5, scope) {
125
+ super(scope);
126
+ this.maxParams = Number(maxParams);
127
+ }
128
+ visitEquation(node) {
129
+ const params = node.patterns;
130
+ if (params.length > this.maxParams)
131
+ throw new StopTraversalException();
132
+ }
133
+ };
134
+ HasLongParameterList = __decorate([
135
+ AutoScoped
136
+ ], HasLongParameterList);
137
+ export { HasLongParameterList };
138
+ let HasMisspelledIdentifiers = class HasMisspelledIdentifiers extends ScopedVisitor {
139
+ dictionary;
140
+ constructor(dictionaryWords = [], scope) {
141
+ super(scope);
142
+ // In a real app, load a standard dictionary + jargon here
143
+ this.dictionary = new Set(dictionaryWords.map((w) => w.toLowerCase()));
144
+ }
145
+ visitVariable(node) {
146
+ this.checkSpelling(node.identifier.value);
147
+ }
148
+ visitFunction(node) {
149
+ this.checkSpelling(node.identifier.value);
150
+ }
151
+ checkSpelling(word) {
152
+ // Skip if no dictionary provided or word is very short
153
+ if (this.dictionary.size === 0 || word.length < 3)
154
+ return;
155
+ // Naive camelCase splitter
156
+ const parts = word.split(/(?=[A-Z])|[-_]/);
157
+ for (const part of parts) {
158
+ if (!this.dictionary.has(part.toLowerCase()))
159
+ throw new StopTraversalException();
160
+ }
161
+ }
162
+ };
163
+ HasMisspelledIdentifiers = __decorate([
164
+ AutoScoped
165
+ ], HasMisspelledIdentifiers);
166
+ export { HasMisspelledIdentifiers };
167
+ let HasRedundantBooleanComparison = class HasRedundantBooleanComparison extends ScopedVisitor {
168
+ visitLogicalBinaryOperation(node) {
169
+ const isLeftBool = node.left instanceof BooleanPrimitive;
170
+ const isRightBool = node.right instanceof BooleanPrimitive;
171
+ if (isLeftBool || isRightBool)
172
+ throw new StopTraversalException();
173
+ }
174
+ };
175
+ HasRedundantBooleanComparison = __decorate([
176
+ AutoScoped
177
+ ], HasRedundantBooleanComparison);
178
+ export { HasRedundantBooleanComparison };
179
+ let HasRedundantIf = class HasRedundantIf extends ScopedVisitor {
180
+ visitIf(node) {
181
+ if (node.elseExpr) {
182
+ const thenStmt = node.then;
183
+ const elseStmt = node.elseExpr;
184
+ if (thenStmt instanceof Sequence && elseStmt instanceof Sequence) {
185
+ // Check if returning booleans
186
+ if (thenStmt.statements.some((stmt) => stmt instanceof BooleanPrimitive) &&
187
+ elseStmt.statements.some((stmt) => stmt instanceof BooleanPrimitive)) {
188
+ throw new StopTraversalException();
189
+ }
190
+ }
191
+ }
192
+ }
193
+ };
194
+ HasRedundantIf = __decorate([
195
+ AutoScoped
196
+ ], HasRedundantIf);
197
+ export { HasRedundantIf };
198
+ let HasRedundantLocalVariableReturn = class HasRedundantLocalVariableReturn extends ScopedVisitor {
199
+ /*
200
+ * Detects:
201
+ * var x = something;
202
+ * return x;
203
+ */
204
+ visitSequence(node) {
205
+ const stmts = node.statements;
206
+ for (let i = 0; i < stmts.length - 1; i++) {
207
+ const stmt = stmts[i];
208
+ const nextStmt = stmts[i + 1];
209
+ if (stmt instanceof Variable && nextStmt instanceof Return) {
210
+ if (nextStmt.body instanceof SymbolPrimitive &&
211
+ nextStmt.body.value === stmt.identifier.value) {
212
+ throw new StopTraversalException();
213
+ }
214
+ }
215
+ }
216
+ }
217
+ };
218
+ HasRedundantLocalVariableReturn = __decorate([
219
+ AutoScoped
220
+ ], HasRedundantLocalVariableReturn);
221
+ export { HasRedundantLocalVariableReturn };
222
+ let HasTooShortIdentifiers = class HasTooShortIdentifiers extends ScopedVisitor {
223
+ minLength;
224
+ constructor(minLength = 3, scope) {
225
+ super(scope);
226
+ this.minLength = Number(minLength);
227
+ }
228
+ visitVariable(node) {
229
+ // exclude common counters
230
+ const allowed = ["i", "j", "k", "x", "y", "z", "id"];
231
+ const name = node.identifier.value;
232
+ if (name.length < this.minLength && !allowed.includes(name)) {
233
+ throw new StopTraversalException();
234
+ }
235
+ }
236
+ };
237
+ HasTooShortIdentifiers = __decorate([
238
+ AutoScoped
239
+ ], HasTooShortIdentifiers);
240
+ export { HasTooShortIdentifiers };
241
+ let HasUsageTypos = class HasUsageTypos extends ScopedVisitor {
242
+ visitSequence(node) {
243
+ const declaredNames = new Set();
244
+ const usedNames = new Set();
245
+ for (const stmt of node.statements) {
246
+ if (stmt instanceof Function || stmt instanceof Variable) {
247
+ declaredNames.add(stmt.identifier.value);
248
+ }
249
+ }
250
+ for (const stmt of node.statements) {
251
+ if (stmt instanceof Call)
252
+ usedNames.add(stmt.callee.value);
253
+ }
254
+ for (const usage of usedNames) {
255
+ if (!declaredNames.has(usage)) {
256
+ for (const decl of declaredNames) {
257
+ if (usage.length > 3 && getLevenshteinDistance(usage, decl) <= 1) {
258
+ throw new StopTraversalException();
259
+ }
260
+ }
261
+ }
262
+ }
263
+ }
264
+ };
265
+ HasUsageTypos = __decorate([
266
+ AutoScoped
267
+ ], HasUsageTypos);
268
+ export { HasUsageTypos };
269
+ let UsesWrongCaseBindings = class UsesWrongCaseBindings extends ScopedVisitor {
270
+ caseType;
271
+ constructor(caseType = "camel", scopeName) {
272
+ super(scopeName);
273
+ this.caseType = caseType;
274
+ }
275
+ visitSymbolPrimitive(node) {
276
+ this.checkCase(node.value);
277
+ }
278
+ checkCase(name) {
279
+ // Ignore operators (names not starting with a letter or underscore)
280
+ if (!/^[a-zA-Z_]/.test(name))
281
+ return;
282
+ let regex;
283
+ switch (this.caseType) {
284
+ case "snake":
285
+ regex = /^[a-z][a-z0-9_]*$/;
286
+ break;
287
+ case "pascal":
288
+ regex = /^[A-Z][a-zA-Z0-9]*$/;
289
+ break;
290
+ case "camel":
291
+ default:
292
+ regex = /^[a-z][a-zA-Z0-9]*$/;
293
+ break;
294
+ }
295
+ if (!regex.test(name)) {
296
+ throw new StopTraversalException();
297
+ }
298
+ }
299
+ };
300
+ UsesWrongCaseBindings = __decorate([
301
+ AutoScoped
302
+ ], UsesWrongCaseBindings);
303
+ export { UsesWrongCaseBindings };
304
+ let IsLongCode = class IsLongCode extends ScopedVisitor {
305
+ maxStatements;
306
+ constructor(maxStatements = 50, scopeName) {
307
+ super(scopeName);
308
+ this.maxStatements = Number(maxStatements);
309
+ }
310
+ visitSequence(node) {
311
+ if (node.statements.length > this.maxStatements) {
312
+ throw new StopTraversalException();
313
+ }
314
+ }
315
+ };
316
+ IsLongCode = __decorate([
317
+ AutoScoped
318
+ ], IsLongCode);
319
+ export { IsLongCode };
320
+ let ShouldInvertIfCondition = class ShouldInvertIfCondition extends ScopedVisitor {
321
+ visitIf(node) {
322
+ const thenEmpty = !node.then || isSequenceEmpty(node.then);
323
+ const elseNonEmpty = node.elseExpr && !isSequenceEmpty(node.elseExpr);
324
+ if (thenEmpty && elseNonEmpty) {
325
+ throw new StopTraversalException();
326
+ }
327
+ }
328
+ };
329
+ ShouldInvertIfCondition = __decorate([
330
+ AutoScoped
331
+ ], ShouldInvertIfCondition);
332
+ export { ShouldInvertIfCondition };
333
+ export const genericSmells = {
334
+ DiscardsExceptions: DiscardsExceptions,
335
+ DoesConsolePrint: DoesConsolePrint,
336
+ HasDeclarationTypos: HasDeclarationTypos,
337
+ HasEmptyIfBranches: HasEmptyIfBranches,
338
+ HasLongParameterList: HasLongParameterList,
339
+ HasMisspelledIdentifiers: HasMisspelledIdentifiers,
340
+ HasRedundantBooleanComparison: HasRedundantBooleanComparison,
341
+ HasRedundantIf: HasRedundantIf,
342
+ HasRedundantLocalVariableReturn: HasRedundantLocalVariableReturn,
343
+ HasTooShortIdentifiers: HasTooShortIdentifiers,
344
+ HasUsageTypos: HasUsageTypos,
345
+ HasWrongCaseIdentifiers: UsesWrongCaseBindings,
346
+ UsesWrongCaseBindings: UsesWrongCaseBindings,
347
+ IsLongCode: IsLongCode,
348
+ ShouldInvertIfCondition: ShouldInvertIfCondition,
349
+ };
@@ -0,0 +1,35 @@
1
+ import { Enumeration, ForLoop, Procedure, Repeat, Switch, While } from "yukigo-ast";
2
+ import { ScopedVisitor, VisitorConstructor, InspectionVisitor } from "../../utils.js";
3
+ export declare class DeclaresEnumeration extends InspectionVisitor {
4
+ private readonly enumName;
5
+ constructor(enumName: string);
6
+ visitEnumeration(node: Enumeration): void;
7
+ }
8
+ export declare class DeclaresProcedure extends ScopedVisitor {
9
+ private readonly procedureName;
10
+ constructor(procedureName: string, scope?: string);
11
+ visitProcedure(node: Procedure): void;
12
+ }
13
+ export declare class UsesForLoop extends ScopedVisitor {
14
+ constructor(scope?: string);
15
+ visitForLoop(node: ForLoop): void;
16
+ }
17
+ export declare class UsesWhile extends ScopedVisitor {
18
+ constructor(scope?: string);
19
+ visitWhile(node: While): void;
20
+ }
21
+ export declare class UsesRepeat extends ScopedVisitor {
22
+ constructor(scope?: string);
23
+ visitRepeat(node: Repeat): void;
24
+ }
25
+ export declare class UsesLoop extends ScopedVisitor {
26
+ constructor(scope?: string);
27
+ visitForLoop(node: ForLoop): void;
28
+ visitWhile(node: While): void;
29
+ visitRepeat(node: Repeat): void;
30
+ }
31
+ export declare class UsesSwitch extends ScopedVisitor {
32
+ constructor(scope?: string);
33
+ visitSwitch(node: Switch): void;
34
+ }
35
+ export declare const imperativeInspections: Record<string, VisitorConstructor>;
@@ -0,0 +1,109 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { StopTraversalException, } from "yukigo-ast";
8
+ import { AutoScoped, ScopedVisitor, InspectionVisitor, } from "../../utils.js";
9
+ export class DeclaresEnumeration extends InspectionVisitor {
10
+ enumName;
11
+ constructor(enumName) {
12
+ super();
13
+ this.enumName = enumName;
14
+ }
15
+ visitEnumeration(node) {
16
+ if (node.identifier.value === this.enumName)
17
+ throw new StopTraversalException();
18
+ }
19
+ }
20
+ let DeclaresProcedure = class DeclaresProcedure extends ScopedVisitor {
21
+ procedureName;
22
+ constructor(procedureName, scope) {
23
+ super(scope);
24
+ this.procedureName = procedureName;
25
+ }
26
+ visitProcedure(node) {
27
+ if (node.identifier.value === this.procedureName)
28
+ throw new StopTraversalException();
29
+ }
30
+ };
31
+ DeclaresProcedure = __decorate([
32
+ AutoScoped
33
+ ], DeclaresProcedure);
34
+ export { DeclaresProcedure };
35
+ let UsesForLoop = class UsesForLoop extends ScopedVisitor {
36
+ constructor(scope) {
37
+ super(scope);
38
+ }
39
+ visitForLoop(node) {
40
+ throw new StopTraversalException();
41
+ }
42
+ };
43
+ UsesForLoop = __decorate([
44
+ AutoScoped
45
+ ], UsesForLoop);
46
+ export { UsesForLoop };
47
+ let UsesWhile = class UsesWhile extends ScopedVisitor {
48
+ constructor(scope) {
49
+ super(scope);
50
+ }
51
+ visitWhile(node) {
52
+ throw new StopTraversalException();
53
+ }
54
+ };
55
+ UsesWhile = __decorate([
56
+ AutoScoped
57
+ ], UsesWhile);
58
+ export { UsesWhile };
59
+ let UsesRepeat = class UsesRepeat extends ScopedVisitor {
60
+ constructor(scope) {
61
+ super(scope);
62
+ }
63
+ visitRepeat(node) {
64
+ throw new StopTraversalException();
65
+ }
66
+ };
67
+ UsesRepeat = __decorate([
68
+ AutoScoped
69
+ ], UsesRepeat);
70
+ export { UsesRepeat };
71
+ let UsesLoop = class UsesLoop extends ScopedVisitor {
72
+ constructor(scope) {
73
+ super(scope);
74
+ }
75
+ visitForLoop(node) {
76
+ throw new StopTraversalException();
77
+ }
78
+ visitWhile(node) {
79
+ throw new StopTraversalException();
80
+ }
81
+ visitRepeat(node) {
82
+ throw new StopTraversalException();
83
+ }
84
+ };
85
+ UsesLoop = __decorate([
86
+ AutoScoped
87
+ ], UsesLoop);
88
+ export { UsesLoop };
89
+ let UsesSwitch = class UsesSwitch extends ScopedVisitor {
90
+ constructor(scope) {
91
+ super(scope);
92
+ }
93
+ visitSwitch(node) {
94
+ throw new StopTraversalException();
95
+ }
96
+ };
97
+ UsesSwitch = __decorate([
98
+ AutoScoped
99
+ ], UsesSwitch);
100
+ export { UsesSwitch };
101
+ export const imperativeInspections = {
102
+ DeclaresEnumeration: DeclaresEnumeration,
103
+ DeclaresProcedure: DeclaresProcedure,
104
+ UsesForLoop: UsesForLoop,
105
+ UsesRepeat: UsesRepeat,
106
+ UsesWhile: UsesWhile,
107
+ UsesLoop: UsesLoop,
108
+ UsesSwitch: UsesSwitch,
109
+ };
@@ -0,0 +1,16 @@
1
+ import { If, Repeat, Return, While } from "yukigo-ast";
2
+ import { ScopedVisitor, VisitorConstructor } from "../../utils.js";
3
+ export declare class HasAssignmentCondition extends ScopedVisitor {
4
+ visitIf(node: If): void;
5
+ visitWhile(node: While): void;
6
+ }
7
+ export declare class HasAssignmentReturn extends ScopedVisitor {
8
+ visitReturn(node: Return): void;
9
+ }
10
+ export declare class HasEmptyRepeat extends ScopedVisitor {
11
+ visitRepeat(node: Repeat): void;
12
+ }
13
+ export declare class HasRedundantRepeat extends ScopedVisitor {
14
+ visitRepeat(node: Repeat): void;
15
+ }
16
+ export declare const imperativeSmells: Record<string, VisitorConstructor>;
@@ -0,0 +1,58 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Assignment, NumberPrimitive, Sequence, StopTraversalException, } from "yukigo-ast";
8
+ import { AutoScoped, ScopedVisitor } from "../../utils.js";
9
+ let HasAssignmentCondition = class HasAssignmentCondition extends ScopedVisitor {
10
+ visitIf(node) {
11
+ if (node.condition instanceof Assignment)
12
+ throw new StopTraversalException();
13
+ }
14
+ visitWhile(node) {
15
+ if (node.condition instanceof Assignment)
16
+ throw new StopTraversalException();
17
+ }
18
+ };
19
+ HasAssignmentCondition = __decorate([
20
+ AutoScoped
21
+ ], HasAssignmentCondition);
22
+ export { HasAssignmentCondition };
23
+ let HasAssignmentReturn = class HasAssignmentReturn extends ScopedVisitor {
24
+ visitReturn(node) {
25
+ if (node.body && node.body instanceof Assignment)
26
+ throw new StopTraversalException();
27
+ }
28
+ };
29
+ HasAssignmentReturn = __decorate([
30
+ AutoScoped
31
+ ], HasAssignmentReturn);
32
+ export { HasAssignmentReturn };
33
+ let HasEmptyRepeat = class HasEmptyRepeat extends ScopedVisitor {
34
+ visitRepeat(node) {
35
+ if (node.body instanceof Sequence && node.body.statements.length === 0)
36
+ throw new StopTraversalException();
37
+ }
38
+ };
39
+ HasEmptyRepeat = __decorate([
40
+ AutoScoped
41
+ ], HasEmptyRepeat);
42
+ export { HasEmptyRepeat };
43
+ let HasRedundantRepeat = class HasRedundantRepeat extends ScopedVisitor {
44
+ visitRepeat(node) {
45
+ if (node.count instanceof NumberPrimitive && node.count.value === 1)
46
+ throw new StopTraversalException();
47
+ }
48
+ };
49
+ HasRedundantRepeat = __decorate([
50
+ AutoScoped
51
+ ], HasRedundantRepeat);
52
+ export { HasRedundantRepeat };
53
+ export const imperativeSmells = {
54
+ HasAssignmentCondition: HasAssignmentCondition,
55
+ HasAssignmentReturn: HasAssignmentReturn,
56
+ HasEmptyRepeat: HasEmptyRepeat,
57
+ HasRedundantRepeat: HasRedundantRepeat,
58
+ };
@@ -0,0 +1,32 @@
1
+ import { Exist, Fact, Findall, Forall, Not, Rule } from "yukigo-ast";
2
+ import { ScopedVisitor, VisitorConstructor, InspectionVisitor } from "../../utils.js";
3
+ export declare class DeclaresFact extends InspectionVisitor {
4
+ private readonly target?;
5
+ constructor(target?: string | undefined);
6
+ visitFact(node: Fact): void;
7
+ }
8
+ export declare class DeclaresRule extends InspectionVisitor {
9
+ private readonly target?;
10
+ constructor(target?: string | undefined);
11
+ visitRule(node: Rule): void;
12
+ }
13
+ export declare class DeclaresPredicate extends InspectionVisitor {
14
+ private readonly target?;
15
+ constructor(target?: string | undefined);
16
+ visitFact(node: Fact): void;
17
+ visitRule(node: Rule): void;
18
+ }
19
+ export declare class UsesFindall extends ScopedVisitor {
20
+ constructor(scope?: string);
21
+ visitFindall(node: Findall): void;
22
+ }
23
+ export declare class UsesForall extends ScopedVisitor {
24
+ constructor(scope?: string);
25
+ visitForall(node: Forall): void;
26
+ }
27
+ export declare class UsesNot extends ScopedVisitor {
28
+ constructor(scope?: string);
29
+ visitNot(node: Not): void;
30
+ visitExist(node: Exist): void;
31
+ }
32
+ export declare const logicInspections: Record<string, VisitorConstructor>;
@@ -0,0 +1,96 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { StopTraversalException, } from "yukigo-ast";
8
+ import { AutoScoped, ScopedVisitor, InspectionVisitor } from "../../utils.js";
9
+ export class DeclaresFact extends InspectionVisitor {
10
+ target;
11
+ constructor(target) {
12
+ super();
13
+ this.target = target;
14
+ }
15
+ visitFact(node) {
16
+ const bindingName = node.identifier.value;
17
+ if (!this.target || bindingName === this.target)
18
+ throw new StopTraversalException();
19
+ }
20
+ }
21
+ export class DeclaresRule extends InspectionVisitor {
22
+ target;
23
+ constructor(target) {
24
+ super();
25
+ this.target = target;
26
+ }
27
+ visitRule(node) {
28
+ const bindingName = node.identifier.value;
29
+ if (!this.target || bindingName === this.target)
30
+ throw new StopTraversalException();
31
+ }
32
+ }
33
+ export class DeclaresPredicate extends InspectionVisitor {
34
+ target;
35
+ constructor(target) {
36
+ super();
37
+ this.target = target;
38
+ }
39
+ visitFact(node) {
40
+ new DeclaresFact(this.target).visitFact(node);
41
+ }
42
+ visitRule(node) {
43
+ new DeclaresRule(this.target).visitRule(node);
44
+ }
45
+ }
46
+ let UsesFindall = class UsesFindall extends ScopedVisitor {
47
+ constructor(scope) {
48
+ super(scope);
49
+ }
50
+ visitFindall(node) {
51
+ throw new StopTraversalException();
52
+ }
53
+ };
54
+ UsesFindall = __decorate([
55
+ AutoScoped
56
+ ], UsesFindall);
57
+ export { UsesFindall };
58
+ let UsesForall = class UsesForall extends ScopedVisitor {
59
+ constructor(scope) {
60
+ super(scope);
61
+ }
62
+ visitForall(node) {
63
+ throw new StopTraversalException();
64
+ }
65
+ };
66
+ UsesForall = __decorate([
67
+ AutoScoped
68
+ ], UsesForall);
69
+ export { UsesForall };
70
+ let UsesNot = class UsesNot extends ScopedVisitor {
71
+ constructor(scope) {
72
+ super(scope);
73
+ }
74
+ visitNot(node) {
75
+ throw new StopTraversalException();
76
+ }
77
+ visitExist(node) {
78
+ if (node.identifier.value === "not")
79
+ throw new StopTraversalException();
80
+ }
81
+ };
82
+ UsesNot = __decorate([
83
+ AutoScoped
84
+ ], UsesNot);
85
+ export { UsesNot };
86
+ export const logicInspections = {
87
+ DeclaresFact: DeclaresFact,
88
+ DeclaresRule: DeclaresRule,
89
+ DeclaresPredicate: DeclaresPredicate,
90
+ UsesFindall: UsesFindall,
91
+ HasFindall: UsesFindall,
92
+ UsesForall: UsesForall,
93
+ HasForall: UsesForall,
94
+ UsesNot: UsesNot,
95
+ HasNot: UsesNot,
96
+ };