@blumintinc/eslint-plugin-blumint 1.20.59 → 1.20.61
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
|
@@ -41,19 +41,36 @@ const NON_PLURALIZABLE_SUFFIXES = [
|
|
|
41
41
|
* the reference itself as a container.
|
|
42
42
|
*/
|
|
43
43
|
const ARRAY_GENERIC_NAMES = new Set(['Array', 'ReadonlyArray']);
|
|
44
|
+
/**
|
|
45
|
+
* Union members that only express absence. Stripping them keeps a nullable
|
|
46
|
+
* container recognisable as a container: `T[]` and `T[] | null` describe the
|
|
47
|
+
* same collection, so they must not disagree about whether a plural name fits.
|
|
48
|
+
*/
|
|
49
|
+
const NULLISH_TYPE_NODES = new Set([
|
|
50
|
+
utils_1.AST_NODE_TYPES.TSNullKeyword,
|
|
51
|
+
utils_1.AST_NODE_TYPES.TSUndefinedKeyword,
|
|
52
|
+
]);
|
|
53
|
+
/**
|
|
54
|
+
* Shared budget for wrapper peeling and union recursion. Wrapper nesting is
|
|
55
|
+
* finite in real code; the cap only guards against a pathological cycle. Every
|
|
56
|
+
* peel and every descent into a union member spends one unit, so the recursion
|
|
57
|
+
* a union introduces stays bounded by the same constant.
|
|
58
|
+
*/
|
|
59
|
+
const MAX_TYPE_DEPTH = 10;
|
|
44
60
|
/**
|
|
45
61
|
* Returns true when the type alias RHS resolves to a container shape — a
|
|
46
62
|
* `TSArrayType` (`Foo[]`) or `TSTupleType` (`[A, B]`) — for which a plural name
|
|
47
63
|
* is the correct, self-documenting choice. Sees through identity-ish wrappers
|
|
48
64
|
* over the same shape: the `readonly` type operator, parenthesized types, and
|
|
49
65
|
* the `Readonly<T>` utility type; `Array<T>`/`ReadonlyArray<T>` are containers
|
|
50
|
-
* outright.
|
|
66
|
+
* outright. A union whose non-nullish members are all containers counts too.
|
|
67
|
+
*
|
|
68
|
+
* @param depth Budget already spent by an enclosing wrapper or union member.
|
|
51
69
|
*/
|
|
52
|
-
function resolvesToContainerType(node) {
|
|
70
|
+
function resolvesToContainerType(node, depth = 0) {
|
|
53
71
|
let current = node;
|
|
54
72
|
// Fixpoint loop: peel identity wrappers until a concrete shape is reached.
|
|
55
|
-
|
|
56
|
-
for (let i = 0; i < 10; i++) {
|
|
73
|
+
for (let i = depth; i < MAX_TYPE_DEPTH; i++) {
|
|
57
74
|
switch (current.type) {
|
|
58
75
|
case utils_1.AST_NODE_TYPES.TSArrayType:
|
|
59
76
|
case utils_1.AST_NODE_TYPES.TSTupleType:
|
|
@@ -66,6 +83,18 @@ function resolvesToContainerType(node) {
|
|
|
66
83
|
current = operator.typeAnnotation;
|
|
67
84
|
continue;
|
|
68
85
|
}
|
|
86
|
+
case utils_1.AST_NODE_TYPES.TSUnionType: {
|
|
87
|
+
const union = current;
|
|
88
|
+
const substantive = union.types.filter((member) => !NULLISH_TYPE_NODES.has(member.type));
|
|
89
|
+
// `null | undefined` holds no collection at all.
|
|
90
|
+
if (substantive.length === 0)
|
|
91
|
+
return false;
|
|
92
|
+
// Requiring EVERY remaining member to be a container keeps the
|
|
93
|
+
// exemption conservative: a mixed union such as `Edge[] | Edge` can hold
|
|
94
|
+
// a single value, so a plural name there still misleads. Members recurse
|
|
95
|
+
// with the spent budget so nesting cannot escape the cap.
|
|
96
|
+
return substantive.every((member) => resolvesToContainerType(member, i + 1));
|
|
97
|
+
}
|
|
69
98
|
case utils_1.AST_NODE_TYPES.TSTypeReference: {
|
|
70
99
|
const ref = current;
|
|
71
100
|
if (ref.typeName.type !== utils_1.AST_NODE_TYPES.Identifier)
|
|
@@ -8,6 +8,11 @@ exports.preferFragmentShorthand = (0, createRule_1.createRule)({
|
|
|
8
8
|
return {
|
|
9
9
|
JSXElement(node) {
|
|
10
10
|
const openingElement = node.openingElement;
|
|
11
|
+
// The <> shorthand cannot carry attributes, so an attributed fragment
|
|
12
|
+
// (key, spread, ...) has no valid rewrite and must not be reported.
|
|
13
|
+
if (openingElement.attributes.length > 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
11
16
|
if (openingElement.name.type === 'JSXMemberExpression' &&
|
|
12
17
|
openingElement.name.object.type === 'JSXIdentifier' &&
|
|
13
18
|
openingElement.name.object.name === 'React' &&
|
|
@@ -17,11 +22,18 @@ exports.preferFragmentShorthand = (0, createRule_1.createRule)({
|
|
|
17
22
|
node,
|
|
18
23
|
messageId: 'preferShorthand',
|
|
19
24
|
data: { fragmentName: 'React.Fragment' },
|
|
20
|
-
fix: (fixer) =>
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
fix: (fixer) => {
|
|
26
|
+
const { closingElement } = node;
|
|
27
|
+
// A self-closing <React.Fragment /> has no children and no
|
|
28
|
+
// closing element; <></> is its equivalent shorthand.
|
|
29
|
+
if (!closingElement) {
|
|
30
|
+
return fixer.replaceText(node, '<></>');
|
|
31
|
+
}
|
|
32
|
+
return [
|
|
33
|
+
fixer.replaceTextRange(openingElement.range, '<>'),
|
|
34
|
+
fixer.replaceTextRange(closingElement.range, '</>'),
|
|
35
|
+
];
|
|
36
|
+
},
|
|
25
37
|
});
|
|
26
38
|
}
|
|
27
39
|
},
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "1.20.61",
|
|
4
|
+
"date": "2026-08-01T06:30:50.860Z",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"name": "prefer-fragment-shorthand",
|
|
8
|
+
"changeType": "fix",
|
|
9
|
+
"issues": [
|
|
10
|
+
1552
|
|
11
|
+
],
|
|
12
|
+
"summary": "don't report attributed fragments (closes #1552)"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"version": "1.20.60",
|
|
18
|
+
"date": "2026-08-01T05:06:58.616Z",
|
|
19
|
+
"rules": [
|
|
20
|
+
{
|
|
21
|
+
"name": "enforce-singular-type-names",
|
|
22
|
+
"changeType": "fix",
|
|
23
|
+
"issues": [
|
|
24
|
+
1550
|
|
25
|
+
],
|
|
26
|
+
"summary": "keep the container exemption when nullable (closes #1550)"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
2
30
|
{
|
|
3
31
|
"version": "1.20.59",
|
|
4
32
|
"date": "2026-08-01T04:43:54.837Z",
|