eslint-plugin-react-x 1.40.3-beta.0 → 1.40.3-beta.1
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/dist/index.js +35 -34
- package/dist/index.mjs +35 -34
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -141,7 +141,7 @@ var settings3 = {
|
|
|
141
141
|
|
|
142
142
|
// package.json
|
|
143
143
|
var name4 = "eslint-plugin-react-x";
|
|
144
|
-
var version = "1.40.3-beta.
|
|
144
|
+
var version = "1.40.3-beta.1";
|
|
145
145
|
var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("x"));
|
|
146
146
|
|
|
147
147
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -1772,7 +1772,7 @@ function create30(context) {
|
|
|
1772
1772
|
{
|
|
1773
1773
|
collectDisplayName: true,
|
|
1774
1774
|
collectHookCalls: false,
|
|
1775
|
-
hint: ER21__namespace.
|
|
1775
|
+
hint: ER21__namespace.DEFAULT_COMPONENT_DETECTION_HINT
|
|
1776
1776
|
}
|
|
1777
1777
|
);
|
|
1778
1778
|
return {
|
|
@@ -2004,7 +2004,7 @@ var no_nested_component_definitions_default = createRule({
|
|
|
2004
2004
|
defaultOptions: []
|
|
2005
2005
|
});
|
|
2006
2006
|
function create33(context) {
|
|
2007
|
-
const hint = ER21__namespace.
|
|
2007
|
+
const hint = ER21__namespace.ComponentDetectionHint.SkipArrayMapArgument | ER21__namespace.ComponentDetectionHint.SkipNullLiteral | ER21__namespace.ComponentDetectionHint.SkipUndefined | ER21__namespace.ComponentDetectionHint.SkipBooleanLiteral | ER21__namespace.ComponentDetectionHint.SkipStringLiteral | ER21__namespace.ComponentDetectionHint.SkipNumberLiteral | ER21__namespace.ComponentDetectionHint.StrictLogical | ER21__namespace.ComponentDetectionHint.StrictConditional;
|
|
2008
2008
|
const collector = ER21__namespace.useComponentCollector(context, { hint });
|
|
2009
2009
|
const collectorLegacy = ER21__namespace.useComponentCollectorLegacy();
|
|
2010
2010
|
return {
|
|
@@ -3122,7 +3122,7 @@ function create49(context, [option]) {
|
|
|
3122
3122
|
const { allowExpressions = true } = option;
|
|
3123
3123
|
return {
|
|
3124
3124
|
JSXElement(node) {
|
|
3125
|
-
if (!JSX8__namespace.
|
|
3125
|
+
if (!JSX8__namespace.isJsxFragmentElement(node)) return;
|
|
3126
3126
|
checkNode(context, node, allowExpressions);
|
|
3127
3127
|
},
|
|
3128
3128
|
JSXFragment(node) {
|
|
@@ -3130,12 +3130,11 @@ function create49(context, [option]) {
|
|
|
3130
3130
|
}
|
|
3131
3131
|
};
|
|
3132
3132
|
}
|
|
3133
|
-
var isLiteral = AST11__namespace.isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText]);
|
|
3134
3133
|
function isWhiteSpace(node) {
|
|
3135
3134
|
return typeof node.value === "string" && node.raw.trim() === "";
|
|
3136
3135
|
}
|
|
3137
3136
|
function isPaddingSpaces(node) {
|
|
3138
|
-
return
|
|
3137
|
+
return JSX8__namespace.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
3139
3138
|
}
|
|
3140
3139
|
function trimLikeReact(text) {
|
|
3141
3140
|
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
@@ -3145,37 +3144,18 @@ function trimLikeReact(text) {
|
|
|
3145
3144
|
return text.slice(start, end);
|
|
3146
3145
|
}
|
|
3147
3146
|
function checkNode(context, node, allowExpressions) {
|
|
3148
|
-
function fix(fixer) {
|
|
3149
|
-
if (node.parent.type !== types.AST_NODE_TYPES.JSXElement && node.parent.type !== types.AST_NODE_TYPES.JSXFragment) {
|
|
3150
|
-
if (node.children.length === 0) {
|
|
3151
|
-
return null;
|
|
3152
|
-
}
|
|
3153
|
-
if (node.children.some(
|
|
3154
|
-
(child) => isLiteral(child) && !isWhiteSpace(child) || AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(child)
|
|
3155
|
-
)) {
|
|
3156
|
-
return null;
|
|
3157
|
-
}
|
|
3158
|
-
}
|
|
3159
|
-
if (JSX8__namespace.isUserDefinedElement(node.parent)) {
|
|
3160
|
-
return null;
|
|
3161
|
-
}
|
|
3162
|
-
const opener = node.type === types.AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
3163
|
-
const closer = node.type === types.AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
3164
|
-
const childrenText = opener.type === types.AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
|
|
3165
|
-
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
3166
|
-
}
|
|
3167
3147
|
const initialScope = context.sourceCode.getScope(node);
|
|
3168
|
-
if (JSX8__namespace.
|
|
3148
|
+
if (JSX8__namespace.isJsxKeyedElement(node, initialScope)) {
|
|
3169
3149
|
return;
|
|
3170
3150
|
}
|
|
3171
|
-
if (JSX8__namespace.
|
|
3151
|
+
if (JSX8__namespace.isJsxBuiltInElement(node.parent)) {
|
|
3172
3152
|
context.report({
|
|
3173
3153
|
messageId: "uselessFragment",
|
|
3174
3154
|
node,
|
|
3175
3155
|
data: {
|
|
3176
3156
|
reason: "placed inside a built-in component"
|
|
3177
3157
|
},
|
|
3178
|
-
fix
|
|
3158
|
+
fix: getFix2(context, node)
|
|
3179
3159
|
});
|
|
3180
3160
|
}
|
|
3181
3161
|
if (node.children.length === 0) {
|
|
@@ -3185,14 +3165,14 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3185
3165
|
data: {
|
|
3186
3166
|
reason: "contains less than two children"
|
|
3187
3167
|
},
|
|
3188
|
-
fix
|
|
3168
|
+
fix: getFix2(context, node)
|
|
3189
3169
|
});
|
|
3190
3170
|
return;
|
|
3191
3171
|
}
|
|
3192
3172
|
const isChildElement = AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3193
3173
|
switch (true) {
|
|
3194
3174
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3195
|
-
case (allowExpressions && !isChildElement && node.children.length === 1 &&
|
|
3175
|
+
case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8__namespace.isJsxText(node.children.at(0))): {
|
|
3196
3176
|
return;
|
|
3197
3177
|
}
|
|
3198
3178
|
// <Foo><>hello, world</></Foo>
|
|
@@ -3203,7 +3183,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3203
3183
|
data: {
|
|
3204
3184
|
reason: "contains less than two children"
|
|
3205
3185
|
},
|
|
3206
|
-
fix
|
|
3186
|
+
fix: getFix2(context, node)
|
|
3207
3187
|
});
|
|
3208
3188
|
return;
|
|
3209
3189
|
}
|
|
@@ -3214,7 +3194,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3214
3194
|
data: {
|
|
3215
3195
|
reason: "contains less than two children"
|
|
3216
3196
|
},
|
|
3217
|
-
fix
|
|
3197
|
+
fix: getFix2(context, node)
|
|
3218
3198
|
});
|
|
3219
3199
|
return;
|
|
3220
3200
|
}
|
|
@@ -3230,13 +3210,34 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3230
3210
|
data: {
|
|
3231
3211
|
reason: "contains less than two children"
|
|
3232
3212
|
},
|
|
3233
|
-
fix
|
|
3213
|
+
fix: getFix2(context, node)
|
|
3234
3214
|
});
|
|
3235
3215
|
return;
|
|
3236
3216
|
}
|
|
3237
3217
|
}
|
|
3238
3218
|
return;
|
|
3239
3219
|
}
|
|
3220
|
+
function getFix2(context, node) {
|
|
3221
|
+
if (!canFix(node)) return null;
|
|
3222
|
+
return (fixer) => {
|
|
3223
|
+
const opener = node.type === types.AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
3224
|
+
const closer = node.type === types.AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
3225
|
+
const childrenText = opener.type === types.AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
|
|
3226
|
+
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
3227
|
+
};
|
|
3228
|
+
}
|
|
3229
|
+
function canFix(node) {
|
|
3230
|
+
if (node.parent.type === types.AST_NODE_TYPES.JSXElement || node.parent.type === types.AST_NODE_TYPES.JSXFragment) {
|
|
3231
|
+
return !JSX8__namespace.isJsxUserDefinedElement(node.parent);
|
|
3232
|
+
}
|
|
3233
|
+
if (node.children.length === 0) {
|
|
3234
|
+
return false;
|
|
3235
|
+
}
|
|
3236
|
+
if (node.children.some((child) => JSX8__namespace.isJsxText(child) && !isWhiteSpace(child) || AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(child))) {
|
|
3237
|
+
return false;
|
|
3238
|
+
}
|
|
3239
|
+
return true;
|
|
3240
|
+
}
|
|
3240
3241
|
var RULE_NAME50 = "prefer-destructuring-assignment";
|
|
3241
3242
|
var RULE_FEATURES49 = [];
|
|
3242
3243
|
function isMemberExpressionWithObjectName(node) {
|
|
@@ -3489,7 +3490,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3489
3490
|
function create54(context) {
|
|
3490
3491
|
return {
|
|
3491
3492
|
JSXElement(node) {
|
|
3492
|
-
if (!JSX8__namespace.
|
|
3493
|
+
if (!JSX8__namespace.isJsxFragmentElement(node)) return;
|
|
3493
3494
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3494
3495
|
if (hasAttributes) {
|
|
3495
3496
|
return;
|
package/dist/index.mjs
CHANGED
|
@@ -113,7 +113,7 @@ var settings3 = {
|
|
|
113
113
|
|
|
114
114
|
// package.json
|
|
115
115
|
var name4 = "eslint-plugin-react-x";
|
|
116
|
-
var version = "1.40.3-beta.
|
|
116
|
+
var version = "1.40.3-beta.1";
|
|
117
117
|
var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
|
|
118
118
|
|
|
119
119
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -1744,7 +1744,7 @@ function create30(context) {
|
|
|
1744
1744
|
{
|
|
1745
1745
|
collectDisplayName: true,
|
|
1746
1746
|
collectHookCalls: false,
|
|
1747
|
-
hint: ER21.
|
|
1747
|
+
hint: ER21.DEFAULT_COMPONENT_DETECTION_HINT
|
|
1748
1748
|
}
|
|
1749
1749
|
);
|
|
1750
1750
|
return {
|
|
@@ -1976,7 +1976,7 @@ var no_nested_component_definitions_default = createRule({
|
|
|
1976
1976
|
defaultOptions: []
|
|
1977
1977
|
});
|
|
1978
1978
|
function create33(context) {
|
|
1979
|
-
const hint = ER21.
|
|
1979
|
+
const hint = ER21.ComponentDetectionHint.SkipArrayMapArgument | ER21.ComponentDetectionHint.SkipNullLiteral | ER21.ComponentDetectionHint.SkipUndefined | ER21.ComponentDetectionHint.SkipBooleanLiteral | ER21.ComponentDetectionHint.SkipStringLiteral | ER21.ComponentDetectionHint.SkipNumberLiteral | ER21.ComponentDetectionHint.StrictLogical | ER21.ComponentDetectionHint.StrictConditional;
|
|
1980
1980
|
const collector = ER21.useComponentCollector(context, { hint });
|
|
1981
1981
|
const collectorLegacy = ER21.useComponentCollectorLegacy();
|
|
1982
1982
|
return {
|
|
@@ -3094,7 +3094,7 @@ function create49(context, [option]) {
|
|
|
3094
3094
|
const { allowExpressions = true } = option;
|
|
3095
3095
|
return {
|
|
3096
3096
|
JSXElement(node) {
|
|
3097
|
-
if (!JSX8.
|
|
3097
|
+
if (!JSX8.isJsxFragmentElement(node)) return;
|
|
3098
3098
|
checkNode(context, node, allowExpressions);
|
|
3099
3099
|
},
|
|
3100
3100
|
JSXFragment(node) {
|
|
@@ -3102,12 +3102,11 @@ function create49(context, [option]) {
|
|
|
3102
3102
|
}
|
|
3103
3103
|
};
|
|
3104
3104
|
}
|
|
3105
|
-
var isLiteral = AST11.isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText]);
|
|
3106
3105
|
function isWhiteSpace(node) {
|
|
3107
3106
|
return typeof node.value === "string" && node.raw.trim() === "";
|
|
3108
3107
|
}
|
|
3109
3108
|
function isPaddingSpaces(node) {
|
|
3110
|
-
return
|
|
3109
|
+
return JSX8.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
3111
3110
|
}
|
|
3112
3111
|
function trimLikeReact(text) {
|
|
3113
3112
|
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
@@ -3117,37 +3116,18 @@ function trimLikeReact(text) {
|
|
|
3117
3116
|
return text.slice(start, end);
|
|
3118
3117
|
}
|
|
3119
3118
|
function checkNode(context, node, allowExpressions) {
|
|
3120
|
-
function fix(fixer) {
|
|
3121
|
-
if (node.parent.type !== AST_NODE_TYPES.JSXElement && node.parent.type !== AST_NODE_TYPES.JSXFragment) {
|
|
3122
|
-
if (node.children.length === 0) {
|
|
3123
|
-
return null;
|
|
3124
|
-
}
|
|
3125
|
-
if (node.children.some(
|
|
3126
|
-
(child) => isLiteral(child) && !isWhiteSpace(child) || AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(child)
|
|
3127
|
-
)) {
|
|
3128
|
-
return null;
|
|
3129
|
-
}
|
|
3130
|
-
}
|
|
3131
|
-
if (JSX8.isUserDefinedElement(node.parent)) {
|
|
3132
|
-
return null;
|
|
3133
|
-
}
|
|
3134
|
-
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
3135
|
-
const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
3136
|
-
const childrenText = opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
|
|
3137
|
-
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
3138
|
-
}
|
|
3139
3119
|
const initialScope = context.sourceCode.getScope(node);
|
|
3140
|
-
if (JSX8.
|
|
3120
|
+
if (JSX8.isJsxKeyedElement(node, initialScope)) {
|
|
3141
3121
|
return;
|
|
3142
3122
|
}
|
|
3143
|
-
if (JSX8.
|
|
3123
|
+
if (JSX8.isJsxBuiltInElement(node.parent)) {
|
|
3144
3124
|
context.report({
|
|
3145
3125
|
messageId: "uselessFragment",
|
|
3146
3126
|
node,
|
|
3147
3127
|
data: {
|
|
3148
3128
|
reason: "placed inside a built-in component"
|
|
3149
3129
|
},
|
|
3150
|
-
fix
|
|
3130
|
+
fix: getFix2(context, node)
|
|
3151
3131
|
});
|
|
3152
3132
|
}
|
|
3153
3133
|
if (node.children.length === 0) {
|
|
@@ -3157,14 +3137,14 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3157
3137
|
data: {
|
|
3158
3138
|
reason: "contains less than two children"
|
|
3159
3139
|
},
|
|
3160
|
-
fix
|
|
3140
|
+
fix: getFix2(context, node)
|
|
3161
3141
|
});
|
|
3162
3142
|
return;
|
|
3163
3143
|
}
|
|
3164
3144
|
const isChildElement = AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3165
3145
|
switch (true) {
|
|
3166
3146
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3167
|
-
case (allowExpressions && !isChildElement && node.children.length === 1 &&
|
|
3147
|
+
case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8.isJsxText(node.children.at(0))): {
|
|
3168
3148
|
return;
|
|
3169
3149
|
}
|
|
3170
3150
|
// <Foo><>hello, world</></Foo>
|
|
@@ -3175,7 +3155,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3175
3155
|
data: {
|
|
3176
3156
|
reason: "contains less than two children"
|
|
3177
3157
|
},
|
|
3178
|
-
fix
|
|
3158
|
+
fix: getFix2(context, node)
|
|
3179
3159
|
});
|
|
3180
3160
|
return;
|
|
3181
3161
|
}
|
|
@@ -3186,7 +3166,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3186
3166
|
data: {
|
|
3187
3167
|
reason: "contains less than two children"
|
|
3188
3168
|
},
|
|
3189
|
-
fix
|
|
3169
|
+
fix: getFix2(context, node)
|
|
3190
3170
|
});
|
|
3191
3171
|
return;
|
|
3192
3172
|
}
|
|
@@ -3202,13 +3182,34 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3202
3182
|
data: {
|
|
3203
3183
|
reason: "contains less than two children"
|
|
3204
3184
|
},
|
|
3205
|
-
fix
|
|
3185
|
+
fix: getFix2(context, node)
|
|
3206
3186
|
});
|
|
3207
3187
|
return;
|
|
3208
3188
|
}
|
|
3209
3189
|
}
|
|
3210
3190
|
return;
|
|
3211
3191
|
}
|
|
3192
|
+
function getFix2(context, node) {
|
|
3193
|
+
if (!canFix(node)) return null;
|
|
3194
|
+
return (fixer) => {
|
|
3195
|
+
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
3196
|
+
const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
3197
|
+
const childrenText = opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
|
|
3198
|
+
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3201
|
+
function canFix(node) {
|
|
3202
|
+
if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) {
|
|
3203
|
+
return !JSX8.isJsxUserDefinedElement(node.parent);
|
|
3204
|
+
}
|
|
3205
|
+
if (node.children.length === 0) {
|
|
3206
|
+
return false;
|
|
3207
|
+
}
|
|
3208
|
+
if (node.children.some((child) => JSX8.isJsxText(child) && !isWhiteSpace(child) || AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(child))) {
|
|
3209
|
+
return false;
|
|
3210
|
+
}
|
|
3211
|
+
return true;
|
|
3212
|
+
}
|
|
3212
3213
|
var RULE_NAME50 = "prefer-destructuring-assignment";
|
|
3213
3214
|
var RULE_FEATURES49 = [];
|
|
3214
3215
|
function isMemberExpressionWithObjectName(node) {
|
|
@@ -3461,7 +3462,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3461
3462
|
function create54(context) {
|
|
3462
3463
|
return {
|
|
3463
3464
|
JSXElement(node) {
|
|
3464
|
-
if (!JSX8.
|
|
3465
|
+
if (!JSX8.isJsxFragmentElement(node)) return;
|
|
3465
3466
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3466
3467
|
if (hasAttributes) {
|
|
3467
3468
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.40.3-beta.
|
|
3
|
+
"version": "1.40.3-beta.1",
|
|
4
4
|
"description": "A set of composable linting rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"is-immutable-type": "^5.0.1",
|
|
51
51
|
"string-ts": "^2.2.1",
|
|
52
52
|
"ts-pattern": "^5.7.0",
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/core": "1.40.3-beta.
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/shared": "1.40.3-beta.
|
|
58
|
-
"@eslint-react/
|
|
59
|
-
"@eslint-react/
|
|
53
|
+
"@eslint-react/eff": "1.40.3-beta.1",
|
|
54
|
+
"@eslint-react/core": "1.40.3-beta.1",
|
|
55
|
+
"@eslint-react/ast": "1.40.3-beta.1",
|
|
56
|
+
"@eslint-react/jsx": "1.40.3-beta.1",
|
|
57
|
+
"@eslint-react/shared": "1.40.3-beta.1",
|
|
58
|
+
"@eslint-react/kit": "1.40.3-beta.1",
|
|
59
|
+
"@eslint-react/var": "1.40.3-beta.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/react": "^19.1.0",
|