@dloizides/frontend-devtools 2.3.0 → 2.4.0
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/CHANGELOG.md +192 -185
- package/dist/eslint/index.d.mts +4 -1
- package/dist/eslint/index.d.ts +4 -1
- package/dist/eslint/index.js +163 -8
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +162 -9
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -1444,6 +1444,151 @@ var noCommentsRule = {
|
|
|
1444
1444
|
}
|
|
1445
1445
|
};
|
|
1446
1446
|
var no_comments_default = { rules: { "no-comments": noCommentsRule } };
|
|
1447
|
+
|
|
1448
|
+
// src/rules/max-component-props.js
|
|
1449
|
+
var DEFAULT_MAX2 = 12;
|
|
1450
|
+
var PROPS_NAME = /Props$/;
|
|
1451
|
+
var COMPONENT_NAME = /^[A-Z]/;
|
|
1452
|
+
var COMPONENT_WRAPPERS = /* @__PURE__ */ new Set(["forwardRef", "memo"]);
|
|
1453
|
+
var MEMBER_TYPES = /* @__PURE__ */ new Set(["TSPropertySignature", "TSMethodSignature"]);
|
|
1454
|
+
var FUNCTION_TYPES = /* @__PURE__ */ new Set(["ArrowFunctionExpression", "FunctionExpression"]);
|
|
1455
|
+
function memberNames(members) {
|
|
1456
|
+
const names = /* @__PURE__ */ new Set();
|
|
1457
|
+
for (const member of members) {
|
|
1458
|
+
if (!MEMBER_TYPES.has(member.type)) continue;
|
|
1459
|
+
const name = member.key?.name ?? member.key?.value;
|
|
1460
|
+
if (name !== void 0) names.add(String(name));
|
|
1461
|
+
}
|
|
1462
|
+
return names;
|
|
1463
|
+
}
|
|
1464
|
+
function mergeInto(target, source) {
|
|
1465
|
+
for (const name of source) target.add(name);
|
|
1466
|
+
return target;
|
|
1467
|
+
}
|
|
1468
|
+
function namesOfReference(name, declarations, seen) {
|
|
1469
|
+
const declaration = declarations.get(name);
|
|
1470
|
+
if (!declaration || seen.has(name)) return /* @__PURE__ */ new Set();
|
|
1471
|
+
seen.add(name);
|
|
1472
|
+
return namesOfDeclaration(declaration, declarations, seen);
|
|
1473
|
+
}
|
|
1474
|
+
function namesOfType(type, declarations, seen) {
|
|
1475
|
+
if (type.type === "TSTypeLiteral") return memberNames(type.members);
|
|
1476
|
+
if (type.type === "TSIntersectionType") {
|
|
1477
|
+
return type.types.reduce(
|
|
1478
|
+
(all, part) => mergeInto(all, namesOfType(part, declarations, seen)),
|
|
1479
|
+
/* @__PURE__ */ new Set()
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
if (type.type === "TSUnionType") {
|
|
1483
|
+
return type.types.reduce((largest, part) => {
|
|
1484
|
+
const names = namesOfType(part, declarations, new Set(seen));
|
|
1485
|
+
return names.size > largest.size ? names : largest;
|
|
1486
|
+
}, /* @__PURE__ */ new Set());
|
|
1487
|
+
}
|
|
1488
|
+
if (type.type === "TSTypeReference" && type.typeName.type === "Identifier") {
|
|
1489
|
+
return namesOfReference(type.typeName.name, declarations, seen);
|
|
1490
|
+
}
|
|
1491
|
+
return /* @__PURE__ */ new Set();
|
|
1492
|
+
}
|
|
1493
|
+
function namesOfDeclaration(declaration, declarations, seen) {
|
|
1494
|
+
if (declaration.type === "TSTypeAliasDeclaration") {
|
|
1495
|
+
return namesOfType(declaration.typeAnnotation, declarations, seen);
|
|
1496
|
+
}
|
|
1497
|
+
const names = memberNames(declaration.body.body);
|
|
1498
|
+
for (const parent of declaration.extends ?? []) {
|
|
1499
|
+
if (parent.expression.type === "Identifier") {
|
|
1500
|
+
mergeInto(names, namesOfReference(parent.expression.name, declarations, seen));
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return names;
|
|
1504
|
+
}
|
|
1505
|
+
function collectDeclarations(program) {
|
|
1506
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
1507
|
+
for (const statement of program.body) {
|
|
1508
|
+
const node = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
1509
|
+
if (node?.type === "TSInterfaceDeclaration" || node?.type === "TSTypeAliasDeclaration") {
|
|
1510
|
+
declarations.set(node.id.name, node);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
return declarations;
|
|
1514
|
+
}
|
|
1515
|
+
function wrappedFunction(init) {
|
|
1516
|
+
if (!init) return void 0;
|
|
1517
|
+
if (FUNCTION_TYPES.has(init.type)) return init;
|
|
1518
|
+
if (init.type !== "CallExpression") return void 0;
|
|
1519
|
+
const callee = init.callee.type === "MemberExpression" ? init.callee.property : init.callee;
|
|
1520
|
+
return COMPONENT_WRAPPERS.has(callee.name) ? wrappedFunction(init.arguments[0]) : void 0;
|
|
1521
|
+
}
|
|
1522
|
+
function propsAnnotation(fn) {
|
|
1523
|
+
return fn?.params[0]?.typeAnnotation?.typeAnnotation;
|
|
1524
|
+
}
|
|
1525
|
+
var rule5 = {
|
|
1526
|
+
meta: {
|
|
1527
|
+
type: "problem",
|
|
1528
|
+
docs: {
|
|
1529
|
+
description: "UI-COMPOSE-1: a component declares at most the capped number of props; split it or compose with slots. Frozen names may only shrink."
|
|
1530
|
+
},
|
|
1531
|
+
schema: [
|
|
1532
|
+
{
|
|
1533
|
+
type: "object",
|
|
1534
|
+
properties: {
|
|
1535
|
+
max: { type: "integer", minimum: 0 },
|
|
1536
|
+
frozen: { type: "object", additionalProperties: { type: "integer", minimum: 0 } }
|
|
1537
|
+
},
|
|
1538
|
+
additionalProperties: false
|
|
1539
|
+
}
|
|
1540
|
+
],
|
|
1541
|
+
messages: {
|
|
1542
|
+
tooMany: "{{name}} declares {{count}} props; the cap is {{max}}. Split it or compose with slots (UI-COMPOSE-1).",
|
|
1543
|
+
frozenGrew: "{{name}} is frozen at {{max}} props and now declares {{count}}. A frozen component may only shrink (UI-COMPOSE-1)."
|
|
1544
|
+
}
|
|
1545
|
+
},
|
|
1546
|
+
create(context) {
|
|
1547
|
+
const options = context.options[0] ?? {};
|
|
1548
|
+
const max = options.max ?? DEFAULT_MAX2;
|
|
1549
|
+
const frozen = options.frozen ?? {};
|
|
1550
|
+
let declarations = /* @__PURE__ */ new Map();
|
|
1551
|
+
const reported = /* @__PURE__ */ new Set();
|
|
1552
|
+
function check(node, name, names) {
|
|
1553
|
+
if (reported.has(name)) return;
|
|
1554
|
+
reported.add(name);
|
|
1555
|
+
const allowed = frozen[name] ?? max;
|
|
1556
|
+
if (names.size <= allowed) return;
|
|
1557
|
+
const messageId = frozen[name] === void 0 ? "tooMany" : "frozenGrew";
|
|
1558
|
+
context.report({ node, messageId, data: { name, count: names.size, max: allowed } });
|
|
1559
|
+
}
|
|
1560
|
+
function checkDeclaration(declaration) {
|
|
1561
|
+
const name = declaration.id.name;
|
|
1562
|
+
check(declaration, name, namesOfDeclaration(declaration, declarations, /* @__PURE__ */ new Set([name])));
|
|
1563
|
+
}
|
|
1564
|
+
function checkComponent(id, fn) {
|
|
1565
|
+
if (!id || !COMPONENT_NAME.test(id.name)) return;
|
|
1566
|
+
const annotation = propsAnnotation(fn);
|
|
1567
|
+
if (annotation?.type === "TSTypeLiteral") {
|
|
1568
|
+
check(annotation, id.name, memberNames(annotation.members));
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
if (annotation?.type !== "TSTypeReference" || annotation.typeName.type !== "Identifier") return;
|
|
1572
|
+
const declaration = declarations.get(annotation.typeName.name);
|
|
1573
|
+
if (declaration) checkDeclaration(declaration);
|
|
1574
|
+
}
|
|
1575
|
+
return {
|
|
1576
|
+
Program(program) {
|
|
1577
|
+
declarations = collectDeclarations(program);
|
|
1578
|
+
for (const [name, declaration] of declarations) {
|
|
1579
|
+
if (PROPS_NAME.test(name)) checkDeclaration(declaration);
|
|
1580
|
+
}
|
|
1581
|
+
},
|
|
1582
|
+
FunctionDeclaration(node) {
|
|
1583
|
+
checkComponent(node.id, node);
|
|
1584
|
+
},
|
|
1585
|
+
VariableDeclarator(node) {
|
|
1586
|
+
if (node.id.type === "Identifier") checkComponent(node.id, wrappedFunction(node.init));
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
var max_component_props_default = { rules: { "max-component-props": rule5 } };
|
|
1447
1592
|
function isPureReExportFile(programNode) {
|
|
1448
1593
|
const { body } = programNode;
|
|
1449
1594
|
if (body.length === 0) return false;
|
|
@@ -2458,7 +2603,7 @@ function isQueryKeyProperty(node) {
|
|
|
2458
2603
|
if (node.key.type === "Identifier") return node.key.name === QUERY_KEY;
|
|
2459
2604
|
return node.key.type === "Literal" && node.key.value === QUERY_KEY;
|
|
2460
2605
|
}
|
|
2461
|
-
var
|
|
2606
|
+
var rule6 = {
|
|
2462
2607
|
meta: {
|
|
2463
2608
|
type: "suggestion",
|
|
2464
2609
|
docs: {
|
|
@@ -2489,7 +2634,7 @@ var rule5 = {
|
|
|
2489
2634
|
};
|
|
2490
2635
|
}
|
|
2491
2636
|
};
|
|
2492
|
-
var query_key_factory_default = { rules: { "query-key-factory":
|
|
2637
|
+
var query_key_factory_default = { rules: { "query-key-factory": rule6 } };
|
|
2493
2638
|
|
|
2494
2639
|
// src/rules/require-stable-hook-args.js
|
|
2495
2640
|
var STABLE_INIT_CALLS = /* @__PURE__ */ new Set([
|
|
@@ -3164,6 +3309,7 @@ var ruleModules = [
|
|
|
3164
3309
|
game_menu_focusable_default,
|
|
3165
3310
|
i18n_interpolation_default,
|
|
3166
3311
|
i18n_param_names_default,
|
|
3312
|
+
max_component_props_default,
|
|
3167
3313
|
no_barrel_companion_file_default,
|
|
3168
3314
|
no_comments_default,
|
|
3169
3315
|
no_duplicate_nav_prefix_default,
|
|
@@ -3184,11 +3330,11 @@ var ruleModules = [
|
|
|
3184
3330
|
function mergeRules(modules) {
|
|
3185
3331
|
const merged = {};
|
|
3186
3332
|
for (const mod of modules) {
|
|
3187
|
-
for (const [name,
|
|
3333
|
+
for (const [name, rule7] of Object.entries(mod.rules)) {
|
|
3188
3334
|
if (merged[name] !== void 0) {
|
|
3189
3335
|
throw new Error(`Duplicate ESLint rule name: "${name}"`);
|
|
3190
3336
|
}
|
|
3191
|
-
merged[name] =
|
|
3337
|
+
merged[name] = rule7;
|
|
3192
3338
|
}
|
|
3193
3339
|
}
|
|
3194
3340
|
return merged;
|
|
@@ -3204,15 +3350,15 @@ var ruleNames = Object.keys(plugin.rules).sort();
|
|
|
3204
3350
|
var legacyPlugins = buildLegacyPlugins();
|
|
3205
3351
|
function buildLegacyPlugins() {
|
|
3206
3352
|
const out = {};
|
|
3207
|
-
for (const [name,
|
|
3208
|
-
out[name] = oneRulePlugin(name,
|
|
3353
|
+
for (const [name, rule7] of Object.entries(rules)) {
|
|
3354
|
+
out[name] = oneRulePlugin(name, rule7);
|
|
3209
3355
|
}
|
|
3210
3356
|
return out;
|
|
3211
3357
|
}
|
|
3212
|
-
function oneRulePlugin(name,
|
|
3358
|
+
function oneRulePlugin(name, rule7) {
|
|
3213
3359
|
return {
|
|
3214
3360
|
meta: { name, version: "1.0.0" },
|
|
3215
|
-
rules: { [name]:
|
|
3361
|
+
rules: { [name]: rule7 }
|
|
3216
3362
|
};
|
|
3217
3363
|
}
|
|
3218
3364
|
var OFF_LEVELS = ["off", 0];
|
|
@@ -3311,7 +3457,14 @@ var focusConfig = {
|
|
|
3311
3457
|
"@dloizides/explicit-initial-focus": "error"
|
|
3312
3458
|
}
|
|
3313
3459
|
};
|
|
3460
|
+
var COMPOSE_RULE_NAMES = ["max-component-props"];
|
|
3461
|
+
var composeConfig = {
|
|
3462
|
+
plugins: commentsConfig.plugins,
|
|
3463
|
+
rules: {
|
|
3464
|
+
"@dloizides/max-component-props": "error"
|
|
3465
|
+
}
|
|
3466
|
+
};
|
|
3314
3467
|
|
|
3315
|
-
export { API_RULE_NAMES, COMMENT_RULE_NAMES, FOCUS_RULE_NAMES, GAME_RULE_NAMES, HOUSE_PATTERN_RULE_NAMES, REUSE_RULE_NAMES, ROW_ACTION_RULE_NAMES, apiConfig, commentsConfig, focusConfig, gameConfig, legacyPlugins, patternPacksConfig, plugin, recommendedConfig, reuseConfig, rowActionsConfig, ruleNames, rules };
|
|
3468
|
+
export { API_RULE_NAMES, COMMENT_RULE_NAMES, COMPOSE_RULE_NAMES, FOCUS_RULE_NAMES, GAME_RULE_NAMES, HOUSE_PATTERN_RULE_NAMES, REUSE_RULE_NAMES, ROW_ACTION_RULE_NAMES, apiConfig, commentsConfig, composeConfig, focusConfig, gameConfig, legacyPlugins, patternPacksConfig, plugin, recommendedConfig, reuseConfig, rowActionsConfig, ruleNames, rules };
|
|
3316
3469
|
//# sourceMappingURL=index.mjs.map
|
|
3317
3470
|
//# sourceMappingURL=index.mjs.map
|