pasika 0.5.10 → 0.5.12
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/eslint/pasika/index.js +81 -0
- package/package.json +1 -1
|
@@ -2276,6 +2276,81 @@ function isComponentReturn(node) {
|
|
|
2276
2276
|
if (parent.type === "ReturnStatement") return true;
|
|
2277
2277
|
return parent.type === "ArrowFunctionExpression" && parent.body === node;
|
|
2278
2278
|
}
|
|
2279
|
+
function isComponentRoot(node) {
|
|
2280
|
+
let current = node;
|
|
2281
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2282
|
+
while (!visited.has(current)) {
|
|
2283
|
+
visited.add(current);
|
|
2284
|
+
const parent = current.parent;
|
|
2285
|
+
if (!parent) return false;
|
|
2286
|
+
const parentType = parent.type;
|
|
2287
|
+
if (parentType === "ReturnStatement") return true;
|
|
2288
|
+
if (parentType === "ArrowFunctionExpression") return true;
|
|
2289
|
+
if (parentType === "ConditionalExpression" || parentType === "ParenthesizedExpression") {
|
|
2290
|
+
current = parent;
|
|
2291
|
+
continue;
|
|
2292
|
+
}
|
|
2293
|
+
return false;
|
|
2294
|
+
}
|
|
2295
|
+
return false;
|
|
2296
|
+
}
|
|
2297
|
+
function isJsxElementWithChildren(node) {
|
|
2298
|
+
return "children" in node && Array.isArray(node.children);
|
|
2299
|
+
}
|
|
2300
|
+
function isJsxElementChild(node) {
|
|
2301
|
+
return "openingElement" in node;
|
|
2302
|
+
}
|
|
2303
|
+
function decorativeTagName(node) {
|
|
2304
|
+
const name = node.openingElement.name;
|
|
2305
|
+
if (name && typeof name === "object" && "name" in name && typeof name.name === "string") return name.name;
|
|
2306
|
+
return void 0;
|
|
2307
|
+
}
|
|
2308
|
+
function isInteractiveChild(node) {
|
|
2309
|
+
const name = decorativeTagName(node);
|
|
2310
|
+
return name !== void 0 && INTERACTIVE_TAGS.has(name);
|
|
2311
|
+
}
|
|
2312
|
+
function isComponentChild(node) {
|
|
2313
|
+
const name = decorativeTagName(node);
|
|
2314
|
+
return name !== void 0 && /^[A-Z]/.test(name);
|
|
2315
|
+
}
|
|
2316
|
+
function isDecorative(node) {
|
|
2317
|
+
const name = decorativeTagName(node);
|
|
2318
|
+
if (name === void 0) return false;
|
|
2319
|
+
if (INTERACTIVE_TAGS.has(name)) return false;
|
|
2320
|
+
if (/^[A-Z]/.test(name)) return false;
|
|
2321
|
+
const children = node.children ?? [];
|
|
2322
|
+
const meaningfulText = children.some(
|
|
2323
|
+
(child) => child.type === "JSXText" && typeof child.value === "string" && child.value.trim().length > 0
|
|
2324
|
+
);
|
|
2325
|
+
return !meaningfulText && !isContentElement(name);
|
|
2326
|
+
}
|
|
2327
|
+
function isContentElement(name) {
|
|
2328
|
+
return /^(?:h[1-6]|p|li|dt|dd|blockquote|pre|code|figcaption|caption|th|td|form|fieldset|select|textarea)$/.test(name);
|
|
2329
|
+
}
|
|
2330
|
+
function isSoleContentOfWrapper(node) {
|
|
2331
|
+
const parent = node.parent;
|
|
2332
|
+
if (!isJsxElementChild(parent)) return false;
|
|
2333
|
+
let current = parent;
|
|
2334
|
+
while (current && isJsxElementWithChildren(current) && !isInteractiveChild(current) && !isComponentChild(current)) {
|
|
2335
|
+
const children = current.children ?? [];
|
|
2336
|
+
const siblings = children.filter(isJsxElementChild);
|
|
2337
|
+
const meaningful = siblings.filter((sibling) => !isDecorative(sibling));
|
|
2338
|
+
const textContent = children.some(
|
|
2339
|
+
(child) => child.type === "JSXText" && typeof child.value === "string" && child.value.trim().length > 0
|
|
2340
|
+
);
|
|
2341
|
+
const expressionContent = children.some((child) => {
|
|
2342
|
+
if (child.type !== "JSXExpressionContainer") return false;
|
|
2343
|
+
const expression = child.expression;
|
|
2344
|
+
return typeof expression === "object" && expression !== null && "type" in expression && expression.type !== "Literal";
|
|
2345
|
+
});
|
|
2346
|
+
if (meaningful.length <= 1 && !textContent && !expressionContent) {
|
|
2347
|
+
return true;
|
|
2348
|
+
}
|
|
2349
|
+
const nextParent = current.parent;
|
|
2350
|
+
current = nextParent !== void 0 && isJsxElementChild(nextParent) ? nextParent : void 0;
|
|
2351
|
+
}
|
|
2352
|
+
return false;
|
|
2353
|
+
}
|
|
2279
2354
|
var interactiveComponentRule = {
|
|
2280
2355
|
meta: {
|
|
2281
2356
|
schema: [],
|
|
@@ -2301,6 +2376,12 @@ var interactiveComponentRule = {
|
|
|
2301
2376
|
if (isComponentReturn(node)) {
|
|
2302
2377
|
return;
|
|
2303
2378
|
}
|
|
2379
|
+
if (isComponentRoot(node)) {
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2382
|
+
if (isSoleContentOfWrapper(node)) {
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2304
2385
|
const name = tagName(node);
|
|
2305
2386
|
if (name === void 0) return;
|
|
2306
2387
|
context.report({
|