@blumintinc/eslint-plugin-blumint 0.1.23 → 1.0.2

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 (52) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +277 -55
  3. package/assets/logo.svg +26 -0
  4. package/jest.config.js +13 -0
  5. package/package.json +74 -25
  6. package/plugin/README.md +80 -0
  7. package/{docs → plugin/docs}/rules/class-methods-read-top-to-bottom.md +3 -1
  8. package/{docs → plugin/docs}/rules/dynamic-https-errors.md +1 -1
  9. package/{docs → plugin/docs}/rules/require-memo.md +9 -2
  10. package/plugin/package-lock.json +7662 -0
  11. package/plugin/package.json +45 -0
  12. package/tsconfig.json +79 -0
  13. package/lib/index.js +0 -69
  14. package/lib/rules/array-methods-this-context.js +0 -64
  15. package/lib/rules/class-methods-read-top-to-bottom.js +0 -72
  16. package/lib/rules/dynamic-https-errors.js +0 -57
  17. package/lib/rules/export-if-in-doubt.js +0 -69
  18. package/lib/rules/extract-global-constants.js +0 -63
  19. package/lib/rules/generic-starts-with-t.js +0 -35
  20. package/lib/rules/no-async-array-filter.js +0 -40
  21. package/lib/rules/no-async-foreach.js +0 -37
  22. package/lib/rules/no-conditional-literals-in-jsx.js +0 -61
  23. package/lib/rules/no-filter-without-return.js +0 -41
  24. package/lib/rules/no-misused-switch-case.js +0 -35
  25. package/lib/rules/no-unpinned-dependencies.js +0 -65
  26. package/lib/rules/no-useless-fragment.js +0 -46
  27. package/lib/rules/prefer-fragment-shorthand.js +0 -40
  28. package/lib/rules/prefer-type-over-interface.js +0 -45
  29. package/lib/rules/require-memo.js +0 -134
  30. package/lib/utils/ASTHelpers.js +0 -336
  31. package/lib/utils/ClassGraphBuilder.js +0 -80
  32. package/lib/utils/ClassGraphSorter.js +0 -99
  33. package/lib/utils/createRule.js +0 -6
  34. package/lib/utils/graph/ClassGraphBuilder.js +0 -80
  35. package/lib/utils/graph/ClassGraphSorter.js +0 -10
  36. package/lib/utils/graph/ClassGraphSorterReadability.js +0 -94
  37. package/lib/utils/graph.js +0 -109
  38. package/lib/utils/ruleTester.js +0 -23
  39. package/lib/utils/testClass.js +0 -45
  40. /package/{docs → plugin/docs}/rules/array-methods-this-context.md +0 -0
  41. /package/{docs → plugin/docs}/rules/export-if-in-doubt.md +0 -0
  42. /package/{docs → plugin/docs}/rules/extract-global-constants.md +0 -0
  43. /package/{docs → plugin/docs}/rules/generic-starts-with-t.md +0 -0
  44. /package/{docs → plugin/docs}/rules/no-async-array-filter.md +0 -0
  45. /package/{docs → plugin/docs}/rules/no-async-foreach.md +0 -0
  46. /package/{docs → plugin/docs}/rules/no-conditional-literals-in-jsx.md +0 -0
  47. /package/{docs → plugin/docs}/rules/no-filter-without-return.md +0 -0
  48. /package/{docs → plugin/docs}/rules/no-misused-switch-case.md +0 -0
  49. /package/{docs → plugin/docs}/rules/no-unpinned-dependencies.md +0 -0
  50. /package/{docs → plugin/docs}/rules/no-useless-fragment.md +0 -0
  51. /package/{docs → plugin/docs}/rules/prefer-fragment-shorthand.md +0 -0
  52. /package/{docs → plugin/docs}/rules/prefer-type-over-interface.md +0 -0
@@ -1,336 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ASTHelpers = void 0;
4
- class ASTHelpers {
5
- static blockIncludesIdentifier(block) {
6
- for (const statement of block.body) {
7
- if (ASTHelpers.declarationIncludesIdentifier(statement)) {
8
- return true;
9
- }
10
- }
11
- return false;
12
- }
13
- static declarationIncludesIdentifier(node) {
14
- if (!node) {
15
- return false;
16
- }
17
- switch (node.type) {
18
- case 'TSNonNullExpression':
19
- return this.declarationIncludesIdentifier(node.expression);
20
- case 'ArrayPattern':
21
- return node.elements.some((element) => ASTHelpers.declarationIncludesIdentifier(element));
22
- case 'ObjectPattern':
23
- return node.properties.some((property) => this.declarationIncludesIdentifier(property.value || null));
24
- case 'AssignmentPattern':
25
- return this.declarationIncludesIdentifier(node.left);
26
- case 'RestElement':
27
- return this.declarationIncludesIdentifier(node.argument);
28
- case 'AwaitExpression':
29
- return this.declarationIncludesIdentifier(node.argument);
30
- case 'AssignmentExpression':
31
- return (this.declarationIncludesIdentifier(node.left) ||
32
- this.declarationIncludesIdentifier(node.right));
33
- case 'BlockStatement':
34
- return node.body.some((statement) => statement.type === 'BlockStatement' &&
35
- ASTHelpers.blockIncludesIdentifier(statement));
36
- case 'IfStatement':
37
- return (this.declarationIncludesIdentifier(node.test) ||
38
- this.declarationIncludesIdentifier(node.consequent) ||
39
- this.declarationIncludesIdentifier(node.alternate));
40
- case 'TSTypeAssertion':
41
- return this.declarationIncludesIdentifier(node.expression);
42
- case 'Identifier':
43
- return true;
44
- case 'SpreadElement':
45
- return ASTHelpers.declarationIncludesIdentifier(node.argument);
46
- case 'ChainExpression':
47
- return ASTHelpers.declarationIncludesIdentifier(node.expression);
48
- case 'ArrayExpression':
49
- return node.elements.some((element) => element &&
50
- (element.type === 'SpreadElement'
51
- ? ASTHelpers.declarationIncludesIdentifier(element.argument)
52
- : ASTHelpers.declarationIncludesIdentifier(element)));
53
- case 'ObjectExpression':
54
- return node.properties.some((property) => {
55
- if (property.type === 'Property') {
56
- return ASTHelpers.declarationIncludesIdentifier(property.value);
57
- }
58
- else if (property.type === 'SpreadElement') {
59
- return ASTHelpers.declarationIncludesIdentifier(property.argument);
60
- }
61
- return false;
62
- });
63
- case 'Property':
64
- return this.declarationIncludesIdentifier(node.value);
65
- case 'BinaryExpression':
66
- case 'LogicalExpression':
67
- return (this.declarationIncludesIdentifier(node.left) ||
68
- this.declarationIncludesIdentifier(node.right));
69
- case 'UnaryExpression':
70
- case 'UpdateExpression':
71
- return this.declarationIncludesIdentifier(node.argument);
72
- case 'MemberExpression':
73
- if (node.object.type === 'ThisExpression') {
74
- return true;
75
- }
76
- return (this.declarationIncludesIdentifier(node.object) ||
77
- this.declarationIncludesIdentifier(node.property));
78
- case 'CallExpression':
79
- case 'NewExpression':
80
- // For function and constructor calls, we care about both the callee and the arguments.
81
- return (this.declarationIncludesIdentifier(node.callee) ||
82
- node.arguments.some((arg) => this.declarationIncludesIdentifier(arg)));
83
- case 'ConditionalExpression':
84
- return (this.declarationIncludesIdentifier(node.test) ||
85
- this.declarationIncludesIdentifier(node.consequent) ||
86
- this.declarationIncludesIdentifier(node.alternate));
87
- case 'TSAsExpression':
88
- return this.declarationIncludesIdentifier(node.expression);
89
- default:
90
- return false;
91
- }
92
- }
93
- static classMethodDependenciesOf(node, graph, className) {
94
- const dependencies = [];
95
- if (!node) {
96
- return dependencies;
97
- }
98
- switch (node.type) {
99
- case 'MethodDefinition':
100
- const functionBody = node.value.body;
101
- return (functionBody?.body || [])
102
- .map((statement) => ASTHelpers.classMethodDependenciesOf(statement, graph, className))
103
- .flat();
104
- case 'Identifier':
105
- dependencies.push(node.name);
106
- break;
107
- case 'ExpressionStatement':
108
- return ASTHelpers.classMethodDependenciesOf(node.expression, graph, className);
109
- case 'MemberExpression':
110
- if ((node.object.type === 'ThisExpression' &&
111
- node.property.type === 'Identifier') ||
112
- (node.object.type === 'Identifier' &&
113
- node.object.name === className &&
114
- node.property.type === 'Identifier')) {
115
- dependencies.push(node.property.name);
116
- }
117
- else {
118
- return [
119
- ...ASTHelpers.classMethodDependenciesOf(node.object, graph, className),
120
- ...ASTHelpers.classMethodDependenciesOf(node.property, graph, className),
121
- ];
122
- }
123
- break;
124
- case 'TSNonNullExpression':
125
- return ASTHelpers.classMethodDependenciesOf(node.expression, graph, className);
126
- case 'ArrayPattern':
127
- return node.elements
128
- .map((element) => ASTHelpers.classMethodDependenciesOf(element, graph, className))
129
- .flat();
130
- case 'ObjectPattern':
131
- return node.properties
132
- .map((property) => ASTHelpers.classMethodDependenciesOf(property.value || null, graph, className))
133
- .flat();
134
- case 'AssignmentPattern':
135
- return ASTHelpers.classMethodDependenciesOf(node.left, graph, className);
136
- case 'RestElement':
137
- return ASTHelpers.classMethodDependenciesOf(node.argument, graph, className);
138
- case 'AwaitExpression':
139
- return ASTHelpers.classMethodDependenciesOf(node.argument, graph, className);
140
- case 'AssignmentExpression':
141
- return [
142
- ...ASTHelpers.classMethodDependenciesOf(node.left, graph, className),
143
- ...ASTHelpers.classMethodDependenciesOf(node.right, graph, className),
144
- ];
145
- case 'BlockStatement':
146
- return node.body
147
- .map((statement) => ASTHelpers.classMethodDependenciesOf(statement, graph, className))
148
- .flat()
149
- .filter(Boolean);
150
- case 'IfStatement':
151
- return [
152
- ...ASTHelpers.classMethodDependenciesOf(node.test, graph, className),
153
- ...ASTHelpers.classMethodDependenciesOf(node.consequent, graph, className),
154
- ...ASTHelpers.classMethodDependenciesOf(node.alternate, graph, className),
155
- ];
156
- case 'TSTypeAssertion':
157
- return ASTHelpers.classMethodDependenciesOf(node.expression, graph, className);
158
- case 'Identifier':
159
- return dependencies;
160
- case 'SpreadElement':
161
- return ASTHelpers.classMethodDependenciesOf(node.argument, graph, className);
162
- case 'ChainExpression':
163
- return ASTHelpers.classMethodDependenciesOf(node.expression, graph, className);
164
- case 'ArrayExpression':
165
- return node.elements
166
- .map((element) => element &&
167
- (element.type === 'SpreadElement'
168
- ? ASTHelpers.classMethodDependenciesOf(element.argument, graph, className)
169
- : ASTHelpers.classMethodDependenciesOf(element, graph, className)))
170
- .flat()
171
- .filter(Boolean);
172
- case 'ObjectExpression':
173
- return node.properties
174
- .map((property) => {
175
- if (property.type === 'Property') {
176
- return ASTHelpers.classMethodDependenciesOf(property.value, graph, className);
177
- }
178
- else if (property.type === 'SpreadElement') {
179
- return ASTHelpers.classMethodDependenciesOf(property.argument, graph, className);
180
- }
181
- return false;
182
- })
183
- .flat()
184
- .filter(Boolean);
185
- case 'Property':
186
- return ASTHelpers.classMethodDependenciesOf(node.value, graph, className);
187
- case 'BinaryExpression':
188
- case 'LogicalExpression':
189
- return [
190
- ...ASTHelpers.classMethodDependenciesOf(node.left, graph, className),
191
- ...ASTHelpers.classMethodDependenciesOf(node.right, graph, className),
192
- ];
193
- case 'UnaryExpression':
194
- case 'UpdateExpression':
195
- return ASTHelpers.classMethodDependenciesOf(node.argument, graph, className);
196
- case 'CallExpression':
197
- case 'NewExpression':
198
- // For function and constructor calls, we care about both the callee and the arguments.
199
- return [
200
- ...ASTHelpers.classMethodDependenciesOf(node.callee, graph, className),
201
- ...node.arguments
202
- .map((arg) => ASTHelpers.classMethodDependenciesOf(arg, graph, className))
203
- .flat(),
204
- ];
205
- case 'ConditionalExpression':
206
- return [
207
- ...ASTHelpers.classMethodDependenciesOf(node.test, graph, className),
208
- ...ASTHelpers.classMethodDependenciesOf(node.consequent, graph, className),
209
- ...ASTHelpers.classMethodDependenciesOf(node.alternate, graph, className),
210
- ];
211
- case 'TSAsExpression':
212
- return ASTHelpers.classMethodDependenciesOf(node.expression, graph, className);
213
- case 'VariableDeclaration':
214
- return node.declarations
215
- .map((declaration) => ASTHelpers.classMethodDependenciesOf(declaration, graph, className))
216
- .flat()
217
- .filter(Boolean);
218
- case 'VariableDeclarator':
219
- return ASTHelpers.classMethodDependenciesOf(node.init, graph, className);
220
- case 'ForOfStatement':
221
- return [
222
- ...ASTHelpers.classMethodDependenciesOf(node.left, graph, className),
223
- ...ASTHelpers.classMethodDependenciesOf(node.body, graph, className),
224
- ...ASTHelpers.classMethodDependenciesOf(node.right, graph, className),
225
- ];
226
- case 'ForStatement':
227
- return [node.body, node.init, node.test, node.update]
228
- .map((node) => ASTHelpers.classMethodDependenciesOf(node, graph, className))
229
- .flat();
230
- case 'ThrowStatement':
231
- return ASTHelpers.classMethodDependenciesOf(node.argument, graph, className);
232
- case 'TemplateLiteral':
233
- return node.expressions
234
- .map((expression) => ASTHelpers.classMethodDependenciesOf(expression, graph, className))
235
- .flat();
236
- case 'ReturnStatement':
237
- return ASTHelpers.classMethodDependenciesOf(node.argument, graph, className);
238
- case 'ArrowFunctionExpression':
239
- return [
240
- ...node.params.flatMap((param) => ASTHelpers.classMethodDependenciesOf(param, graph, className)),
241
- ...ASTHelpers.classMethodDependenciesOf(node.body, graph, className),
242
- ];
243
- default:
244
- break;
245
- }
246
- // Removing duplicates
247
- return [
248
- ...new Set(dependencies.filter((dep) => graph?.[dep]?.type !== 'property')),
249
- ];
250
- }
251
- static isNode(value) {
252
- return typeof value === 'object' && value !== null && 'type' in value;
253
- }
254
- static hasReturnStatement(node) {
255
- if (node.type === 'ReturnStatement') {
256
- return true;
257
- }
258
- if (node.type === 'IfStatement') {
259
- const consequentHasReturn = ASTHelpers.hasReturnStatement(node.consequent);
260
- const alternateHasReturn = !!node.alternate && ASTHelpers.hasReturnStatement(node.alternate);
261
- return consequentHasReturn && alternateHasReturn;
262
- }
263
- if (node.type === 'BlockStatement') {
264
- for (const statement of node.body) {
265
- if (ASTHelpers.hasReturnStatement(statement)) {
266
- return true;
267
- }
268
- }
269
- }
270
- for (const key in node) {
271
- if (key === 'parent') {
272
- continue; // Ignore the parent property
273
- }
274
- const value = node[key];
275
- if (ASTHelpers.isNode(value)) {
276
- if (ASTHelpers.hasReturnStatement(value)) {
277
- return true;
278
- }
279
- }
280
- }
281
- return false;
282
- }
283
- static isNodeExported(node) {
284
- // Checking if the node is exported as a named export.
285
- if (node.parent && node.parent.type === 'ExportNamedDeclaration') {
286
- return true;
287
- }
288
- // Checking if the node is exported as default.
289
- if (node.parent &&
290
- node.parent.parent &&
291
- node.parent.parent.type === 'ExportDefaultDeclaration') {
292
- return true;
293
- }
294
- // Checking if the node is exported in a list of exports.
295
- if (node.parent &&
296
- node.parent.parent &&
297
- node.parent.parent.type === 'ExportSpecifier' &&
298
- node.parent.parent.exported.name === node.name) {
299
- return true;
300
- }
301
- return false;
302
- }
303
- static returnsJSX(node) {
304
- if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
305
- return true;
306
- }
307
- if (node.type === 'BlockStatement') {
308
- for (const statement of node.body) {
309
- if (statement.type === 'ReturnStatement' &&
310
- (statement.argument?.type === 'JSXElement' ||
311
- statement.argument?.type === 'JSXFragment')) {
312
- return true;
313
- }
314
- // Handle conditional returns
315
- if (statement.type === 'ReturnStatement' &&
316
- statement.argument?.type === 'ConditionalExpression') {
317
- const conditionalExpr = statement.argument;
318
- if (ASTHelpers.returnsJSX(conditionalExpr.consequent) ||
319
- ASTHelpers.returnsJSX(conditionalExpr.alternate)) {
320
- return true;
321
- }
322
- }
323
- }
324
- }
325
- if (node.type === 'ConditionalExpression') {
326
- return (ASTHelpers.returnsJSX(node.consequent) ||
327
- ASTHelpers.returnsJSX(node.alternate));
328
- }
329
- return false;
330
- }
331
- static hasParameters(node) {
332
- return node.params && node.params.length > 0;
333
- }
334
- }
335
- exports.ASTHelpers = ASTHelpers;
336
- //# sourceMappingURL=ASTHelpers.js.map
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClassGraphBuilder = void 0;
4
- /* eslint-disable security/detect-object-injection */
5
- const utils_1 = require("@typescript-eslint/utils");
6
- const ClassGraphSorter_1 = require("./ClassGraphSorter");
7
- const ASTHelpers_1 = require("./ASTHelpers");
8
- /**
9
- * Builds a graph of class methods and properties with their dependencies from a class declaration.
10
- * A dependency in this case is the name of another class method.
11
- */
12
- class ClassGraphBuilder {
13
- constructor(className, classBody) {
14
- this.className = className;
15
- this.classBody = classBody;
16
- this.graph = {};
17
- this.buildGraph();
18
- // Note: extension requires injection of other sorters
19
- this.sorter = new ClassGraphSorter_1.ClassGraphSorterReadability(this.graph);
20
- }
21
- buildGraph() {
22
- // NOTE: these need to be run sequentially for each member,
23
- // since we need to know the class members before we can search
24
- // methods for dependencies
25
- this.classBody.body.forEach((member) => {
26
- if (ClassGraphBuilder.isClassMember(member)) {
27
- this.addMemberToGraph(member);
28
- }
29
- });
30
- this.classBody.body.forEach((member) => {
31
- if (ClassGraphBuilder.isNamedClassMethod(member)) {
32
- const { key } = member;
33
- if (utils_1.ASTUtils.isIdentifier(key)) {
34
- this.addDependencies(member, key.name);
35
- }
36
- }
37
- });
38
- }
39
- static isClassMember(node) {
40
- return (node.type === 'MethodDefinition' || node.type === 'PropertyDefinition');
41
- }
42
- addMemberToGraph(member) {
43
- const name = member.key.name;
44
- const type = ClassGraphBuilder.nodeTypeOf(member);
45
- const node = ClassGraphBuilder.createGraphNode(name, type, member.accessibility, member.static);
46
- this.graph[name] = node;
47
- }
48
- static nodeTypeOf(member) {
49
- if (member.type === 'MethodDefinition') {
50
- return member.kind === 'constructor' ? 'constructor' : 'method';
51
- }
52
- return 'property';
53
- }
54
- static createGraphNode(name, type, accessibility, isStatic = false) {
55
- return {
56
- name,
57
- type,
58
- accessibility,
59
- isStatic,
60
- dependencies: [],
61
- };
62
- }
63
- static isNamedClassMethod(node) {
64
- return node.type === 'MethodDefinition';
65
- }
66
- addDependencies(node, methodName) {
67
- const newDependencies = ASTHelpers_1.ASTHelpers.classMethodDependenciesOf(node, this.graph, this.className).filter((name) => !!this.graph[name] && name !== methodName);
68
- if (this.graph[methodName]) {
69
- this.graph[methodName].dependencies.push(...newDependencies);
70
- }
71
- }
72
- get graphSorted() {
73
- return this.sorter.nodesSorted;
74
- }
75
- get memberNamesSorted() {
76
- return this.sorter.nodeNamesSorted;
77
- }
78
- }
79
- exports.ClassGraphBuilder = ClassGraphBuilder;
80
- //# sourceMappingURL=ClassGraphBuilder.js.map
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClassGraphSorterReadability = exports.ClassGraphSorter = void 0;
4
- class ClassGraphSorter {
5
- constructor(graph) {
6
- this.graph = graph;
7
- }
8
- }
9
- exports.ClassGraphSorter = ClassGraphSorter;
10
- class ClassGraphSorterReadability extends ClassGraphSorter {
11
- constructor(graph) {
12
- super(graph);
13
- this.graph = graph;
14
- }
15
- get nodeNamesSorted() {
16
- return this.nodesSorted.map((node) => node.name);
17
- }
18
- get nodesSorted() {
19
- return this.sortNodes();
20
- }
21
- sortNodes() {
22
- const { methods, properties, classConstructor } = this.groupNodesByType();
23
- const [propertiesSorted, methodsSorted] = [properties, methods].map((nodeGroup) => nodeGroup.sort(ClassGraphSorterReadability.sortMembersForReadability));
24
- const searchNodeCandidates = [classConstructor, ...methodsSorted].filter((node) => !!node);
25
- const searchNodeCandidatesValidated = searchNodeCandidates.filter((method, _index, arr) => ClassGraphSorterReadability.SEARCH_NODE_PRIORITY_FUNCTIONS.some((fn) => !!fn(method, arr)));
26
- const searchNodesSorted = searchNodeCandidatesValidated.sort((a, b) => {
27
- const getPriority = (method) => {
28
- const priority = ClassGraphSorterReadability.SEARCH_NODE_PRIORITY_FUNCTIONS.findIndex((fn) => !!fn(method, methodsSorted));
29
- return priority === -1
30
- ? ClassGraphSorterReadability.SEARCH_NODE_PRIORITY_FUNCTIONS.length
31
- : priority;
32
- };
33
- return getPriority(a) - getPriority(b);
34
- });
35
- const dfsSortedNodes = this.dependencyDfs(searchNodesSorted);
36
- return [...propertiesSorted, ...dfsSortedNodes];
37
- }
38
- groupNodesByType() {
39
- const nodes = Object.values(this.graph);
40
- return nodes.reduce((acc, node) => {
41
- switch (node.type) {
42
- case 'property':
43
- acc.properties.push(node);
44
- break;
45
- case 'constructor':
46
- acc.classConstructor = node;
47
- break;
48
- case 'method':
49
- acc.methods.push(node);
50
- break;
51
- }
52
- return acc;
53
- }, {
54
- properties: [],
55
- methods: [],
56
- classConstructor: null,
57
- });
58
- }
59
- static sortMembersForReadability(a, b) {
60
- // NOTE: the ordering from Object.entries is safe here since it is readonly
61
- for (const [key, priorities] of Object.entries(ClassGraphSorterReadability.MODIFIER_PRIORITY_MAP)) {
62
- const indexA = priorities.indexOf(a[key]);
63
- const indexB = priorities.indexOf(b[key]);
64
- if (indexA !== indexB) {
65
- return indexA - indexB;
66
- }
67
- }
68
- return 0;
69
- }
70
- dependencyDfs(searchNodes) {
71
- const visited = new Set();
72
- const dfsSortedNodes = [];
73
- const dfs = (node) => {
74
- if (visited.has(node.name) || !node) {
75
- return;
76
- }
77
- visited.add(node.name);
78
- dfsSortedNodes.push(node);
79
- for (const dep of node.dependencies) {
80
- dfs(this.graph[String(dep)]);
81
- }
82
- };
83
- searchNodes.forEach((node) => dfs(node));
84
- return dfsSortedNodes;
85
- }
86
- }
87
- exports.ClassGraphSorterReadability = ClassGraphSorterReadability;
88
- ClassGraphSorterReadability.MODIFIER_PRIORITY_MAP = {
89
- isStatic: [true, false],
90
- accessibility: ['public', undefined, 'private'],
91
- };
92
- ClassGraphSorterReadability.SEARCH_NODE_PRIORITY_FUNCTIONS = [
93
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
- (method, _methods) => method.type === 'constructor',
95
- (method, _methods) => !_methods.some((node) => node.dependencies.includes(method.name)),
96
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
97
- (method, _methods) => method.dependencies.length === 0,
98
- ];
99
- //# sourceMappingURL=ClassGraphSorter.js.map
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRule = void 0;
4
- const utils_1 = require("@typescript-eslint/utils");
5
- exports.createRule = utils_1.ESLintUtils.RuleCreator((name) => `https://github.com/BluMintInc/eslint-custom-rules/plugin/docs/rules/${name}.md`);
6
- //# sourceMappingURL=createRule.js.map
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClassGraphBuilder = void 0;
4
- /* eslint-disable security/detect-object-injection */
5
- const utils_1 = require("@typescript-eslint/utils");
6
- const ClassGraphSorterReadability_1 = require("./ClassGraphSorterReadability");
7
- const ASTHelpers_1 = require("../ASTHelpers");
8
- /**
9
- * Builds a graph of class methods and properties with their dependencies from a class declaration.
10
- * A dependency in this case is the name of another class method.
11
- */
12
- class ClassGraphBuilder {
13
- constructor(className, classBody) {
14
- this.className = className;
15
- this.classBody = classBody;
16
- this.graph = {};
17
- this.buildGraph();
18
- // Note: extension requires injection of other sorters
19
- this.sorter = new ClassGraphSorterReadability_1.ClassGraphSorterReadability(this.graph);
20
- }
21
- buildGraph() {
22
- // NOTE: these need to be run sequentially for each member,
23
- // since we need to know the class members before we can search
24
- // methods for dependencies
25
- this.classBody.body.forEach((member) => {
26
- if (ClassGraphBuilder.isClassMember(member)) {
27
- this.addMemberToGraph(member);
28
- }
29
- });
30
- this.classBody.body.forEach((member) => {
31
- if (ClassGraphBuilder.isNamedClassMethod(member)) {
32
- const { key } = member;
33
- if (utils_1.ASTUtils.isIdentifier(key)) {
34
- this.addDependencies(member, key.name);
35
- }
36
- }
37
- });
38
- }
39
- static isClassMember(node) {
40
- return (node.type === 'MethodDefinition' || node.type === 'PropertyDefinition');
41
- }
42
- addMemberToGraph(member) {
43
- const name = member.key.name;
44
- const type = ClassGraphBuilder.nodeTypeOf(member);
45
- const node = ClassGraphBuilder.createGraphNode(name, type, member.accessibility, member.static);
46
- this.graph[name] = node;
47
- }
48
- static nodeTypeOf(member) {
49
- if (member.type === 'MethodDefinition') {
50
- return member.kind === 'constructor' ? 'constructor' : 'method';
51
- }
52
- return 'property';
53
- }
54
- static createGraphNode(name, type, accessibility, isStatic = false) {
55
- return {
56
- name,
57
- type,
58
- accessibility,
59
- isStatic,
60
- dependencies: [],
61
- };
62
- }
63
- static isNamedClassMethod(node) {
64
- return node.type === 'MethodDefinition';
65
- }
66
- addDependencies(node, methodName) {
67
- const newDependencies = ASTHelpers_1.ASTHelpers.classMethodDependenciesOf(node, this.graph, this.className).filter((name) => !!this.graph[name] && name !== methodName);
68
- if (this.graph[methodName]) {
69
- this.graph[methodName].dependencies.push(...newDependencies);
70
- }
71
- }
72
- get graphSorted() {
73
- return this.sorter.nodesSorted;
74
- }
75
- get memberNamesSorted() {
76
- return this.sorter.nodeNamesSorted;
77
- }
78
- }
79
- exports.ClassGraphBuilder = ClassGraphBuilder;
80
- //# sourceMappingURL=ClassGraphBuilder.js.map
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClassGraphSorter = void 0;
4
- class ClassGraphSorter {
5
- constructor(graph) {
6
- this.graph = graph;
7
- }
8
- }
9
- exports.ClassGraphSorter = ClassGraphSorter;
10
- //# sourceMappingURL=ClassGraphSorter.js.map