@dloizides/frontend-devtools 2.3.0 → 2.5.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 +199 -185
- package/README.md +15 -0
- package/dist/eslint/index.d.mts +4 -1
- package/dist/eslint/index.d.ts +4 -1
- package/dist/eslint/index.js +185 -12
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +184 -13
- 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;
|
|
@@ -2036,6 +2181,8 @@ var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
|
|
|
2036
2181
|
var EXEMPT_URL_SCHEME = /^\s*(?:data|blob):/i;
|
|
2037
2182
|
var ABSOLUTE_HTTP_URL = /^https?:\/\/[^/\s]+\//i;
|
|
2038
2183
|
var ABSOLUTE_HTTP_LITERAL = /^https?:\/\/[^/\s]+(?:[/?#]|$)/i;
|
|
2184
|
+
var URL_HOST = /^https?:\/\/([^/\s?#:@]+)/i;
|
|
2185
|
+
var WILDCARD_PREFIX = "*.";
|
|
2039
2186
|
var URL_OBJECTS = /* @__PURE__ */ new Set(["URL", "webkitURL"]);
|
|
2040
2187
|
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
2041
2188
|
var AXIOS_MODULE = "axios";
|
|
@@ -2072,6 +2219,19 @@ function isThirdPartyLiteralUrl(node) {
|
|
|
2072
2219
|
const head = node.quasis[0].value.cooked ?? "";
|
|
2073
2220
|
return node.expressions.length === 0 ? ABSOLUTE_HTTP_LITERAL.test(head) : ABSOLUTE_HTTP_URL.test(head);
|
|
2074
2221
|
}
|
|
2222
|
+
function literalUrlHost(node) {
|
|
2223
|
+
const match = URL_HOST.exec(leadingText(node));
|
|
2224
|
+
return match === null ? "" : match[1].toLowerCase();
|
|
2225
|
+
}
|
|
2226
|
+
function hostMatches(host, pattern) {
|
|
2227
|
+
const wanted = pattern.toLowerCase();
|
|
2228
|
+
if (!wanted.startsWith(WILDCARD_PREFIX)) return host === wanted;
|
|
2229
|
+
return host.endsWith(wanted.slice(1));
|
|
2230
|
+
}
|
|
2231
|
+
function isBackendHostUrl(node, backendHosts) {
|
|
2232
|
+
const host = literalUrlHost(node);
|
|
2233
|
+
return host !== "" && backendHosts.some((pattern) => hostMatches(host, pattern));
|
|
2234
|
+
}
|
|
2075
2235
|
function unwrapExpression(node) {
|
|
2076
2236
|
let current = node;
|
|
2077
2237
|
while (current !== void 0 && current !== null && ["TSAsExpression", "TSNonNullExpression", "TSTypeAssertion", "TSSatisfiesExpression"].includes(current.type))
|
|
@@ -2123,9 +2283,10 @@ function scopeOf(context, node) {
|
|
|
2123
2283
|
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
2124
2284
|
return typeof sourceCode.getScope === "function" ? sourceCode.getScope(node) : context.getScope();
|
|
2125
2285
|
}
|
|
2126
|
-
function isExemptFetchTarget(context, node) {
|
|
2286
|
+
function isExemptFetchTarget(context, node, backendHosts) {
|
|
2127
2287
|
const target = node.arguments[0];
|
|
2128
|
-
if (isDataOrBlobUrl(target)
|
|
2288
|
+
if (isDataOrBlobUrl(target)) return true;
|
|
2289
|
+
if (isThirdPartyLiteralUrl(target)) return !isBackendHostUrl(target, backendHosts);
|
|
2129
2290
|
return isLocalObjectUrl(target, scopeOf(context, node));
|
|
2130
2291
|
}
|
|
2131
2292
|
function isAxiosSource(node) {
|
|
@@ -2148,7 +2309,8 @@ var noRawBackendFetchRule = {
|
|
|
2148
2309
|
{
|
|
2149
2310
|
type: "object",
|
|
2150
2311
|
properties: {
|
|
2151
|
-
allow: { type: "array", items: { type: "string" } }
|
|
2312
|
+
allow: { type: "array", items: { type: "string" } },
|
|
2313
|
+
backendHosts: { type: "array", items: { type: "string" } }
|
|
2152
2314
|
},
|
|
2153
2315
|
additionalProperties: false
|
|
2154
2316
|
}
|
|
@@ -2161,6 +2323,7 @@ var noRawBackendFetchRule = {
|
|
|
2161
2323
|
create(context) {
|
|
2162
2324
|
const options = context.options[0] ?? {};
|
|
2163
2325
|
const allow = Array.isArray(options.allow) ? options.allow : [];
|
|
2326
|
+
const backendHosts = Array.isArray(options.backendHosts) ? options.backendHosts : [];
|
|
2164
2327
|
const filename = context.filename ?? context.getFilename();
|
|
2165
2328
|
if (isExemptFile(filename, allow)) return {};
|
|
2166
2329
|
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
@@ -2168,7 +2331,7 @@ var noRawBackendFetchRule = {
|
|
|
2168
2331
|
return {
|
|
2169
2332
|
CallExpression(node) {
|
|
2170
2333
|
if (isFetchCallee(node.callee)) {
|
|
2171
|
-
if (!isExemptFetchTarget(context, node)) context.report({ node, messageId: "rawFetch" });
|
|
2334
|
+
if (!isExemptFetchTarget(context, node, backendHosts)) context.report({ node, messageId: "rawFetch" });
|
|
2172
2335
|
return;
|
|
2173
2336
|
}
|
|
2174
2337
|
const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
|
|
@@ -2458,7 +2621,7 @@ function isQueryKeyProperty(node) {
|
|
|
2458
2621
|
if (node.key.type === "Identifier") return node.key.name === QUERY_KEY;
|
|
2459
2622
|
return node.key.type === "Literal" && node.key.value === QUERY_KEY;
|
|
2460
2623
|
}
|
|
2461
|
-
var
|
|
2624
|
+
var rule6 = {
|
|
2462
2625
|
meta: {
|
|
2463
2626
|
type: "suggestion",
|
|
2464
2627
|
docs: {
|
|
@@ -2489,7 +2652,7 @@ var rule5 = {
|
|
|
2489
2652
|
};
|
|
2490
2653
|
}
|
|
2491
2654
|
};
|
|
2492
|
-
var query_key_factory_default = { rules: { "query-key-factory":
|
|
2655
|
+
var query_key_factory_default = { rules: { "query-key-factory": rule6 } };
|
|
2493
2656
|
|
|
2494
2657
|
// src/rules/require-stable-hook-args.js
|
|
2495
2658
|
var STABLE_INIT_CALLS = /* @__PURE__ */ new Set([
|
|
@@ -3164,6 +3327,7 @@ var ruleModules = [
|
|
|
3164
3327
|
game_menu_focusable_default,
|
|
3165
3328
|
i18n_interpolation_default,
|
|
3166
3329
|
i18n_param_names_default,
|
|
3330
|
+
max_component_props_default,
|
|
3167
3331
|
no_barrel_companion_file_default,
|
|
3168
3332
|
no_comments_default,
|
|
3169
3333
|
no_duplicate_nav_prefix_default,
|
|
@@ -3184,11 +3348,11 @@ var ruleModules = [
|
|
|
3184
3348
|
function mergeRules(modules) {
|
|
3185
3349
|
const merged = {};
|
|
3186
3350
|
for (const mod of modules) {
|
|
3187
|
-
for (const [name,
|
|
3351
|
+
for (const [name, rule7] of Object.entries(mod.rules)) {
|
|
3188
3352
|
if (merged[name] !== void 0) {
|
|
3189
3353
|
throw new Error(`Duplicate ESLint rule name: "${name}"`);
|
|
3190
3354
|
}
|
|
3191
|
-
merged[name] =
|
|
3355
|
+
merged[name] = rule7;
|
|
3192
3356
|
}
|
|
3193
3357
|
}
|
|
3194
3358
|
return merged;
|
|
@@ -3204,15 +3368,15 @@ var ruleNames = Object.keys(plugin.rules).sort();
|
|
|
3204
3368
|
var legacyPlugins = buildLegacyPlugins();
|
|
3205
3369
|
function buildLegacyPlugins() {
|
|
3206
3370
|
const out = {};
|
|
3207
|
-
for (const [name,
|
|
3208
|
-
out[name] = oneRulePlugin(name,
|
|
3371
|
+
for (const [name, rule7] of Object.entries(rules)) {
|
|
3372
|
+
out[name] = oneRulePlugin(name, rule7);
|
|
3209
3373
|
}
|
|
3210
3374
|
return out;
|
|
3211
3375
|
}
|
|
3212
|
-
function oneRulePlugin(name,
|
|
3376
|
+
function oneRulePlugin(name, rule7) {
|
|
3213
3377
|
return {
|
|
3214
3378
|
meta: { name, version: "1.0.0" },
|
|
3215
|
-
rules: { [name]:
|
|
3379
|
+
rules: { [name]: rule7 }
|
|
3216
3380
|
};
|
|
3217
3381
|
}
|
|
3218
3382
|
var OFF_LEVELS = ["off", 0];
|
|
@@ -3311,7 +3475,14 @@ var focusConfig = {
|
|
|
3311
3475
|
"@dloizides/explicit-initial-focus": "error"
|
|
3312
3476
|
}
|
|
3313
3477
|
};
|
|
3478
|
+
var COMPOSE_RULE_NAMES = ["max-component-props"];
|
|
3479
|
+
var composeConfig = {
|
|
3480
|
+
plugins: commentsConfig.plugins,
|
|
3481
|
+
rules: {
|
|
3482
|
+
"@dloizides/max-component-props": "error"
|
|
3483
|
+
}
|
|
3484
|
+
};
|
|
3314
3485
|
|
|
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 };
|
|
3486
|
+
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
3487
|
//# sourceMappingURL=index.mjs.map
|
|
3317
3488
|
//# sourceMappingURL=index.mjs.map
|