@blumintinc/eslint-plugin-blumint 1.20.8 → 1.20.9
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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { TSESLint } from '@typescript-eslint/utils';
|
|
1
2
|
type Options = [{
|
|
2
3
|
minFields?: number;
|
|
3
4
|
}];
|
|
4
|
-
export declare const preferSpreadOverReassembly:
|
|
5
|
+
export declare const preferSpreadOverReassembly: TSESLint.RuleModule<"preferSpread", Options, TSESLint.RuleListener>;
|
|
5
6
|
export {};
|
|
@@ -265,6 +265,29 @@ function freshPropsName(existingNames) {
|
|
|
265
265
|
i++;
|
|
266
266
|
return `props${i}`;
|
|
267
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Rewrites the destructured parameter to a single identifier without touching
|
|
270
|
+
* its type annotation. A parameter node's `range` spans the annotation, so
|
|
271
|
+
* replacing the whole node would delete `: FooProps` and leave an implicit
|
|
272
|
+
* `any`; the replacement is therefore bounded to the pattern's own closing
|
|
273
|
+
* brace, leaving the annotation text (generics, unions, multi-line formatting)
|
|
274
|
+
* exactly as the author wrote it. Returns null when the closing brace cannot be
|
|
275
|
+
* located, so a malformed fix is never emitted.
|
|
276
|
+
*/
|
|
277
|
+
function replacePatternWithName(fixer, sourceCode, pattern, name) {
|
|
278
|
+
if (!pattern.typeAnnotation) {
|
|
279
|
+
return fixer.replaceText(pattern, name);
|
|
280
|
+
}
|
|
281
|
+
// Scanning backwards from the annotation (whose range starts at the `:`)
|
|
282
|
+
// skips any `?` optional marker sitting between the pattern and the colon.
|
|
283
|
+
const closingBrace = sourceCode.getTokenBefore(pattern.typeAnnotation, {
|
|
284
|
+
filter: (token) => token.type === utils_1.AST_TOKEN_TYPES.Punctuator && token.value === '}',
|
|
285
|
+
});
|
|
286
|
+
if (!closingBrace) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
return fixer.replaceTextRange([pattern.range[0], closingBrace.range[1]], name);
|
|
290
|
+
}
|
|
268
291
|
exports.preferSpreadOverReassembly = (0, createRule_1.createRule)({
|
|
269
292
|
name: 'prefer-spread-over-reassembly',
|
|
270
293
|
meta: {
|
|
@@ -356,8 +379,13 @@ exports.preferSpreadOverReassembly = (0, createRule_1.createRule)({
|
|
|
356
379
|
// Choose a fresh name for the props parameter that does not collide
|
|
357
380
|
// with any binding currently in scope.
|
|
358
381
|
const propsName = freshPropsName(namesSet);
|
|
359
|
-
// 1. Replace the destructured parameter with `props` (or fresh name)
|
|
360
|
-
|
|
382
|
+
// 1. Replace the destructured parameter with `props` (or fresh name),
|
|
383
|
+
// keeping any type annotation intact.
|
|
384
|
+
const paramFix = replacePatternWithName(fixer, sourceCode, param, propsName);
|
|
385
|
+
if (!paramFix) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
fixes.push(paramFix);
|
|
361
389
|
if (target.kind === 'jsx') {
|
|
362
390
|
// 2a. Build the new JSX opening element text.
|
|
363
391
|
const attrs = target.openingElement.attributes;
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "1.20.9",
|
|
4
|
+
"date": "2026-07-28T15:52:43.296Z",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"name": "prefer-spread-over-reassembly",
|
|
8
|
+
"changeType": "fix",
|
|
9
|
+
"issues": [
|
|
10
|
+
1356
|
|
11
|
+
],
|
|
12
|
+
"summary": "preserve the parameter's type annotation (closes #1356)"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"version": "1.20.8",
|
|
4
18
|
"date": "2026-07-28T15:39:20.357Z",
|