@blumintinc/eslint-plugin-blumint 1.20.57 → 1.20.58
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 +1 -1
- package/lib/rules/enforce-memoize-async.js +40 -0
- package/package.json +1 -1
- package/release-manifest.json +14 -0
package/lib/index.js
CHANGED
|
@@ -42,6 +42,39 @@ function bindsMemoize(variable) {
|
|
|
42
42
|
ALLOWED_MEMOIZE_MODULES.has(String(declaration.source.value)));
|
|
43
43
|
}));
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Whether a declared return type annotation promises no value: `void` or
|
|
47
|
+
* `Promise<void>`.
|
|
48
|
+
*
|
|
49
|
+
* Memoizing such a method caches nothing — there is no result to hand back —
|
|
50
|
+
* while changing runtime behaviour: the side effects run once per instance and
|
|
51
|
+
* every later call silently no-ops. Because the decision comes from the
|
|
52
|
+
* annotation node, spacing and line breaks inside the type are irrelevant.
|
|
53
|
+
*
|
|
54
|
+
* The check stays keyed to a plain `void`: a union (`Promise<void | undefined>`)
|
|
55
|
+
* or a type parameter (`Promise<T>`) can resolve to a value, so those still
|
|
56
|
+
* warrant caching. Absent annotations are likewise not exempt — this rule is
|
|
57
|
+
* syntactic (no `parserOptions.project`), so an unannotated body carries no
|
|
58
|
+
* declaration of intent to honour, and exempting inferred void would silently
|
|
59
|
+
* drop methods the author never marked value-less.
|
|
60
|
+
*/
|
|
61
|
+
function declaresVoidResult(returnType) {
|
|
62
|
+
const annotation = returnType?.typeAnnotation;
|
|
63
|
+
if (!annotation) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (annotation.type === utils_1.AST_NODE_TYPES.TSVoidKeyword) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (annotation.type !== utils_1.AST_NODE_TYPES.TSTypeReference ||
|
|
70
|
+
annotation.typeName.type !== utils_1.AST_NODE_TYPES.Identifier ||
|
|
71
|
+
annotation.typeName.name !== 'Promise') {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const typeArguments = annotation.typeParameters?.params;
|
|
75
|
+
return (typeArguments?.length === 1 &&
|
|
76
|
+
typeArguments[0].type === utils_1.AST_NODE_TYPES.TSVoidKeyword);
|
|
77
|
+
}
|
|
45
78
|
/**
|
|
46
79
|
* Matches a memoize decorator in supported syntaxes:
|
|
47
80
|
* - @Alias()
|
|
@@ -148,6 +181,13 @@ exports.enforceMemoizeAsync = (0, createRule_1.createRule)({
|
|
|
148
181
|
if (node.value.params.length > 1) {
|
|
149
182
|
return;
|
|
150
183
|
}
|
|
184
|
+
// A method declared to produce no value has no result to cache, so the
|
|
185
|
+
// decorator's benefit is unobtainable while its cost is real: the
|
|
186
|
+
// fixer would convert a repeatable side effect into a
|
|
187
|
+
// once-per-instance one, unattended, under `--fix`.
|
|
188
|
+
if (declaresVoidResult(node.value.returnType)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
151
191
|
const { aliases: memoizeAliases, namespaces: memoizeNamespaces } = memoizeImports();
|
|
152
192
|
const hasMemoizeImport = memoizeAliases.size > 0 || memoizeNamespaces.size > 0;
|
|
153
193
|
// Check if method already has @Memoize or @Memoize() decorator
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "1.20.58",
|
|
4
|
+
"date": "2026-08-01T04:26:49.434Z",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"name": "enforce-memoize-async",
|
|
8
|
+
"changeType": "fix",
|
|
9
|
+
"issues": [
|
|
10
|
+
1548
|
|
11
|
+
],
|
|
12
|
+
"summary": "skip methods declared Promise<void> (closes #1548)"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"version": "1.20.57",
|
|
4
18
|
"date": "2026-08-01T03:42:42.343Z",
|