@blumintinc/eslint-plugin-blumint 1.20.76 → 1.20.77
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/prefer-spread-over-reassembly.js +44 -33
- package/package.json +1 -1
- package/release-manifest.json +14 -0
package/lib/index.js
CHANGED
|
@@ -147,23 +147,57 @@ function collectObjectForwardedFields(objectExpression, destructuredNames) {
|
|
|
147
147
|
}
|
|
148
148
|
return forwarded;
|
|
149
149
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Wrappers that exist only for the type checker: they compile away entirely, so
|
|
152
|
+
* the value they wrap is the value the function actually produces.
|
|
153
|
+
*/
|
|
154
|
+
const TRANSPARENT_WRAPPERS = new Set([
|
|
155
|
+
utils_1.AST_NODE_TYPES.TSAsExpression,
|
|
156
|
+
utils_1.AST_NODE_TYPES.TSSatisfiesExpression,
|
|
157
|
+
utils_1.AST_NODE_TYPES.TSNonNullExpression,
|
|
158
|
+
]);
|
|
159
|
+
/**
|
|
160
|
+
* Strips every type-only wrapper (`as T`, `as const`, `satisfies T`, `!`) from
|
|
161
|
+
* an expression. An assertion removes no reassembly — `{ a, b } as const` is
|
|
162
|
+
* the very same destructure-then-reassemble as `{ a, b }` — so classifying the
|
|
163
|
+
* target without stripping first turns an assertion into an accidental
|
|
164
|
+
* suppression. The loop is what handles chains such as `{...} as unknown as T`,
|
|
165
|
+
* and `enforce-object-literal-as-const` appends `as const` to exactly this
|
|
166
|
+
* shape, so wrapped literals are the common case rather than the exotic one.
|
|
167
|
+
*/
|
|
168
|
+
function unwrapTransparent(node) {
|
|
169
|
+
let current = node;
|
|
170
|
+
while (TRANSPARENT_WRAPPERS.has(current.type)) {
|
|
171
|
+
current = current.expression;
|
|
172
|
+
}
|
|
173
|
+
return current;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Classifies an already-unwrapped expression as a spread target. The fix is
|
|
177
|
+
* anchored on the node returned here — the JSX opening element or the object
|
|
178
|
+
* literal's own braces — so any wrapper stripped on the way in keeps its source
|
|
179
|
+
* text untouched.
|
|
180
|
+
*/
|
|
181
|
+
function classifyTarget(expression) {
|
|
182
|
+
if (expression.type === utils_1.AST_NODE_TYPES.JSXElement) {
|
|
154
183
|
return {
|
|
155
184
|
kind: 'jsx',
|
|
156
|
-
openingElement:
|
|
157
|
-
jsxElement:
|
|
185
|
+
openingElement: expression.openingElement,
|
|
186
|
+
jsxElement: expression,
|
|
158
187
|
};
|
|
159
188
|
}
|
|
160
189
|
// Concise arrow returning object literal: `({ x, y }) => ({ x, y, extra: 1 })`
|
|
161
190
|
// The parser represents the parenthesized object as an ObjectExpression body.
|
|
162
|
-
if (
|
|
163
|
-
return { kind: 'object', expression
|
|
191
|
+
if (expression.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
|
|
192
|
+
return { kind: 'object', expression };
|
|
164
193
|
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
function getSingleTarget(fn) {
|
|
197
|
+
const body = fn.body;
|
|
198
|
+
// Concise arrow: `(props) => <X />`, `({ x, y }) => ({ x, y } as const)`.
|
|
165
199
|
if (body.type !== utils_1.AST_NODE_TYPES.BlockStatement) {
|
|
166
|
-
return
|
|
200
|
+
return classifyTarget(unwrapTransparent(body));
|
|
167
201
|
}
|
|
168
202
|
// Require exactly one statement in the block, which must be a return.
|
|
169
203
|
if (body.body.length !== 1) {
|
|
@@ -173,30 +207,7 @@ function getSingleTarget(fn) {
|
|
|
173
207
|
if (stmt.type !== utils_1.AST_NODE_TYPES.ReturnStatement || !stmt.argument) {
|
|
174
208
|
return null;
|
|
175
209
|
}
|
|
176
|
-
|
|
177
|
-
if (arg.type === utils_1.AST_NODE_TYPES.JSXElement) {
|
|
178
|
-
return {
|
|
179
|
-
kind: 'jsx',
|
|
180
|
-
openingElement: arg.openingElement,
|
|
181
|
-
jsxElement: arg,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
// Parenthesized JSX in arrow: `(props) => (<X />)` — arg may wrap with
|
|
185
|
-
// TSAsExpression or similar. We unwrap one level of TSAsExpression / TSSatisfiesExpression.
|
|
186
|
-
if ((arg.type === utils_1.AST_NODE_TYPES.TSAsExpression ||
|
|
187
|
-
arg.type === utils_1.AST_NODE_TYPES.TSSatisfiesExpression) &&
|
|
188
|
-
arg.expression.type === utils_1.AST_NODE_TYPES.JSXElement) {
|
|
189
|
-
const jsx = arg.expression;
|
|
190
|
-
return {
|
|
191
|
-
kind: 'jsx',
|
|
192
|
-
openingElement: jsx.openingElement,
|
|
193
|
-
jsxElement: jsx,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
if (arg.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
|
|
197
|
-
return { kind: 'object', expression: arg };
|
|
198
|
-
}
|
|
199
|
-
return null;
|
|
210
|
+
return classifyTarget(unwrapTransparent(stmt.argument));
|
|
200
211
|
}
|
|
201
212
|
/**
|
|
202
213
|
* Checks whether any of the destructured names is used anywhere in the
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "1.20.77",
|
|
4
|
+
"date": "2026-08-02T08:02:01.009Z",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"name": "prefer-spread-over-reassembly",
|
|
8
|
+
"changeType": "fix",
|
|
9
|
+
"issues": [
|
|
10
|
+
1610
|
|
11
|
+
],
|
|
12
|
+
"summary": "see through transparent type-assertion wrappers (closes #1610)"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"version": "1.20.76",
|
|
4
18
|
"date": "2026-08-02T07:09:34.794Z",
|