@blumintinc/eslint-plugin-blumint 1.1.6 → 1.1.7
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/lib/index.js
CHANGED
|
@@ -49,10 +49,12 @@ exports.classMethodsReadTopToBottom = (0, createRule_1.createRule)({
|
|
|
49
49
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
50
50
|
const memberNode = node.body.find((member) => getMemberName(member) === n);
|
|
51
51
|
const comments = sourceCode.getCommentsBefore(memberNode);
|
|
52
|
-
memberNode.range =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
memberNode.range = comments.length
|
|
53
|
+
? [
|
|
54
|
+
Math.min(memberNode.range[0], Math.min(...comments.map((comment) => comment.range[0]))),
|
|
55
|
+
Math.max(memberNode.range[1], Math.max(...comments.map((comment) => comment.range[1]))),
|
|
56
|
+
]
|
|
57
|
+
: memberNode.range;
|
|
56
58
|
return sourceCode.getText(memberNode);
|
|
57
59
|
})
|
|
58
60
|
.join('\n');
|
|
@@ -23,6 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
const createRule_1 = require("../utils/createRule");
|
|
26
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
26
27
|
const ts = __importStar(require("typescript"));
|
|
27
28
|
module.exports = (0, createRule_1.createRule)({
|
|
28
29
|
name: 'consistent-callback-naming',
|
|
@@ -150,14 +151,84 @@ module.exports = (0, createRule_1.createRule)({
|
|
|
150
151
|
'FunctionDeclaration, VariableDeclarator'(node) {
|
|
151
152
|
const functionName = node.id?.type === 'Identifier' ? node.id.name : undefined;
|
|
152
153
|
if (functionName && functionName.startsWith('handle') && node.id) {
|
|
154
|
+
// Skip autofixing for "handler" and "handlers"
|
|
155
|
+
if (functionName === 'handler' || functionName === 'handlers') {
|
|
156
|
+
context.report({
|
|
157
|
+
node,
|
|
158
|
+
messageId: 'callbackFunctionPrefix',
|
|
159
|
+
});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
// Skip autofixing for class parameters and getters
|
|
163
|
+
const parent = node.parent;
|
|
164
|
+
if (parent?.type === utils_1.AST_NODE_TYPES.PropertyDefinition || parent?.type === utils_1.AST_NODE_TYPES.MethodDefinition) {
|
|
165
|
+
context.report({
|
|
166
|
+
node,
|
|
167
|
+
messageId: 'callbackFunctionPrefix',
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
// Get all references to this variable
|
|
172
|
+
const scope = context.getScope();
|
|
173
|
+
const variable = scope.variables.find(v => v.name === functionName);
|
|
174
|
+
const references = new Set(variable?.references ?? []);
|
|
175
|
+
// Get references from all scopes
|
|
176
|
+
const allScopes = [scope];
|
|
177
|
+
let currentScope = scope;
|
|
178
|
+
while (currentScope.upper) {
|
|
179
|
+
currentScope = currentScope.upper;
|
|
180
|
+
allScopes.push(currentScope);
|
|
181
|
+
}
|
|
182
|
+
// Get references from all scopes and their children
|
|
183
|
+
for (const s of allScopes) {
|
|
184
|
+
// Get references from current scope
|
|
185
|
+
const currentVar = s.variables.find(v => v.name === functionName);
|
|
186
|
+
if (currentVar) {
|
|
187
|
+
currentVar.references.forEach(ref => references.add(ref));
|
|
188
|
+
}
|
|
189
|
+
// Get references from child scopes
|
|
190
|
+
const childScopes = s.childScopes;
|
|
191
|
+
for (const childScope of childScopes) {
|
|
192
|
+
const childVar = childScope.variables.find(v => v.name === functionName);
|
|
193
|
+
if (childVar) {
|
|
194
|
+
childVar.references.forEach(ref => references.add(ref));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Get references from sibling scopes
|
|
199
|
+
const siblingScopes = scope.upper?.childScopes ?? [];
|
|
200
|
+
for (const siblingScope of siblingScopes) {
|
|
201
|
+
if (siblingScope !== scope) {
|
|
202
|
+
const siblingVar = siblingScope.variables.find(v => v.name === functionName);
|
|
203
|
+
if (siblingVar) {
|
|
204
|
+
siblingVar.references.forEach(ref => references.add(ref));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Get references from global scope
|
|
209
|
+
const sourceCode = context.getSourceCode();
|
|
210
|
+
if (sourceCode.scopeManager?.globalScope) {
|
|
211
|
+
const globalVar = sourceCode.scopeManager.globalScope.variables.find(v => v.name === functionName);
|
|
212
|
+
if (globalVar) {
|
|
213
|
+
globalVar.references.forEach(ref => references.add(ref));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
153
216
|
context.report({
|
|
154
217
|
node,
|
|
155
218
|
messageId: 'callbackFunctionPrefix',
|
|
156
|
-
fix(fixer) {
|
|
219
|
+
*fix(fixer) {
|
|
157
220
|
// Remove 'handle' prefix and convert first character to lowercase
|
|
158
221
|
const newName = functionName.slice(6).charAt(0).toLowerCase() +
|
|
159
222
|
functionName.slice(7);
|
|
160
|
-
|
|
223
|
+
// Fix the declaration and all references
|
|
224
|
+
const fixes = [];
|
|
225
|
+
fixes.push(fixer.replaceText(node.id, newName));
|
|
226
|
+
for (const ref of references) {
|
|
227
|
+
if (ref.identifier !== node.id) {
|
|
228
|
+
fixes.push(fixer.replaceText(ref.identifier, newName));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return fixes;
|
|
161
232
|
},
|
|
162
233
|
});
|
|
163
234
|
}
|
|
@@ -168,6 +239,22 @@ module.exports = (0, createRule_1.createRule)({
|
|
|
168
239
|
node.key.name &&
|
|
169
240
|
node.key.name.startsWith('handle')) {
|
|
170
241
|
const name = node.key.name;
|
|
242
|
+
// Skip autofixing for "handler" and "handlers"
|
|
243
|
+
if (name === 'handler' || name === 'handlers') {
|
|
244
|
+
context.report({
|
|
245
|
+
node: node.key,
|
|
246
|
+
messageId: 'callbackFunctionPrefix',
|
|
247
|
+
});
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
// Skip autofixing for class parameters and getters
|
|
251
|
+
if (node.type === 'MethodDefinition' && node.kind === 'get') {
|
|
252
|
+
context.report({
|
|
253
|
+
node: node.key,
|
|
254
|
+
messageId: 'callbackFunctionPrefix',
|
|
255
|
+
});
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
171
258
|
context.report({
|
|
172
259
|
node: node.key,
|
|
173
260
|
messageId: 'callbackFunctionPrefix',
|
|
@@ -179,6 +266,16 @@ module.exports = (0, createRule_1.createRule)({
|
|
|
179
266
|
});
|
|
180
267
|
}
|
|
181
268
|
},
|
|
269
|
+
// Check constructor parameters
|
|
270
|
+
'TSParameterProperty'(node) {
|
|
271
|
+
if (node.parameter.type === 'Identifier' &&
|
|
272
|
+
node.parameter.name.startsWith('handle')) {
|
|
273
|
+
context.report({
|
|
274
|
+
node,
|
|
275
|
+
messageId: 'callbackFunctionPrefix',
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
},
|
|
182
279
|
};
|
|
183
280
|
},
|
|
184
281
|
});
|