@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.js
CHANGED
|
@@ -1455,6 +1455,151 @@ var noCommentsRule = {
|
|
|
1455
1455
|
}
|
|
1456
1456
|
};
|
|
1457
1457
|
var no_comments_default = { rules: { "no-comments": noCommentsRule } };
|
|
1458
|
+
|
|
1459
|
+
// src/rules/max-component-props.js
|
|
1460
|
+
var DEFAULT_MAX2 = 12;
|
|
1461
|
+
var PROPS_NAME = /Props$/;
|
|
1462
|
+
var COMPONENT_NAME = /^[A-Z]/;
|
|
1463
|
+
var COMPONENT_WRAPPERS = /* @__PURE__ */ new Set(["forwardRef", "memo"]);
|
|
1464
|
+
var MEMBER_TYPES = /* @__PURE__ */ new Set(["TSPropertySignature", "TSMethodSignature"]);
|
|
1465
|
+
var FUNCTION_TYPES = /* @__PURE__ */ new Set(["ArrowFunctionExpression", "FunctionExpression"]);
|
|
1466
|
+
function memberNames(members) {
|
|
1467
|
+
const names = /* @__PURE__ */ new Set();
|
|
1468
|
+
for (const member of members) {
|
|
1469
|
+
if (!MEMBER_TYPES.has(member.type)) continue;
|
|
1470
|
+
const name = member.key?.name ?? member.key?.value;
|
|
1471
|
+
if (name !== void 0) names.add(String(name));
|
|
1472
|
+
}
|
|
1473
|
+
return names;
|
|
1474
|
+
}
|
|
1475
|
+
function mergeInto(target, source) {
|
|
1476
|
+
for (const name of source) target.add(name);
|
|
1477
|
+
return target;
|
|
1478
|
+
}
|
|
1479
|
+
function namesOfReference(name, declarations, seen) {
|
|
1480
|
+
const declaration = declarations.get(name);
|
|
1481
|
+
if (!declaration || seen.has(name)) return /* @__PURE__ */ new Set();
|
|
1482
|
+
seen.add(name);
|
|
1483
|
+
return namesOfDeclaration(declaration, declarations, seen);
|
|
1484
|
+
}
|
|
1485
|
+
function namesOfType(type, declarations, seen) {
|
|
1486
|
+
if (type.type === "TSTypeLiteral") return memberNames(type.members);
|
|
1487
|
+
if (type.type === "TSIntersectionType") {
|
|
1488
|
+
return type.types.reduce(
|
|
1489
|
+
(all, part) => mergeInto(all, namesOfType(part, declarations, seen)),
|
|
1490
|
+
/* @__PURE__ */ new Set()
|
|
1491
|
+
);
|
|
1492
|
+
}
|
|
1493
|
+
if (type.type === "TSUnionType") {
|
|
1494
|
+
return type.types.reduce((largest, part) => {
|
|
1495
|
+
const names = namesOfType(part, declarations, new Set(seen));
|
|
1496
|
+
return names.size > largest.size ? names : largest;
|
|
1497
|
+
}, /* @__PURE__ */ new Set());
|
|
1498
|
+
}
|
|
1499
|
+
if (type.type === "TSTypeReference" && type.typeName.type === "Identifier") {
|
|
1500
|
+
return namesOfReference(type.typeName.name, declarations, seen);
|
|
1501
|
+
}
|
|
1502
|
+
return /* @__PURE__ */ new Set();
|
|
1503
|
+
}
|
|
1504
|
+
function namesOfDeclaration(declaration, declarations, seen) {
|
|
1505
|
+
if (declaration.type === "TSTypeAliasDeclaration") {
|
|
1506
|
+
return namesOfType(declaration.typeAnnotation, declarations, seen);
|
|
1507
|
+
}
|
|
1508
|
+
const names = memberNames(declaration.body.body);
|
|
1509
|
+
for (const parent of declaration.extends ?? []) {
|
|
1510
|
+
if (parent.expression.type === "Identifier") {
|
|
1511
|
+
mergeInto(names, namesOfReference(parent.expression.name, declarations, seen));
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return names;
|
|
1515
|
+
}
|
|
1516
|
+
function collectDeclarations(program) {
|
|
1517
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
1518
|
+
for (const statement of program.body) {
|
|
1519
|
+
const node = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
1520
|
+
if (node?.type === "TSInterfaceDeclaration" || node?.type === "TSTypeAliasDeclaration") {
|
|
1521
|
+
declarations.set(node.id.name, node);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return declarations;
|
|
1525
|
+
}
|
|
1526
|
+
function wrappedFunction(init) {
|
|
1527
|
+
if (!init) return void 0;
|
|
1528
|
+
if (FUNCTION_TYPES.has(init.type)) return init;
|
|
1529
|
+
if (init.type !== "CallExpression") return void 0;
|
|
1530
|
+
const callee = init.callee.type === "MemberExpression" ? init.callee.property : init.callee;
|
|
1531
|
+
return COMPONENT_WRAPPERS.has(callee.name) ? wrappedFunction(init.arguments[0]) : void 0;
|
|
1532
|
+
}
|
|
1533
|
+
function propsAnnotation(fn) {
|
|
1534
|
+
return fn?.params[0]?.typeAnnotation?.typeAnnotation;
|
|
1535
|
+
}
|
|
1536
|
+
var rule5 = {
|
|
1537
|
+
meta: {
|
|
1538
|
+
type: "problem",
|
|
1539
|
+
docs: {
|
|
1540
|
+
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."
|
|
1541
|
+
},
|
|
1542
|
+
schema: [
|
|
1543
|
+
{
|
|
1544
|
+
type: "object",
|
|
1545
|
+
properties: {
|
|
1546
|
+
max: { type: "integer", minimum: 0 },
|
|
1547
|
+
frozen: { type: "object", additionalProperties: { type: "integer", minimum: 0 } }
|
|
1548
|
+
},
|
|
1549
|
+
additionalProperties: false
|
|
1550
|
+
}
|
|
1551
|
+
],
|
|
1552
|
+
messages: {
|
|
1553
|
+
tooMany: "{{name}} declares {{count}} props; the cap is {{max}}. Split it or compose with slots (UI-COMPOSE-1).",
|
|
1554
|
+
frozenGrew: "{{name}} is frozen at {{max}} props and now declares {{count}}. A frozen component may only shrink (UI-COMPOSE-1)."
|
|
1555
|
+
}
|
|
1556
|
+
},
|
|
1557
|
+
create(context) {
|
|
1558
|
+
const options = context.options[0] ?? {};
|
|
1559
|
+
const max = options.max ?? DEFAULT_MAX2;
|
|
1560
|
+
const frozen = options.frozen ?? {};
|
|
1561
|
+
let declarations = /* @__PURE__ */ new Map();
|
|
1562
|
+
const reported = /* @__PURE__ */ new Set();
|
|
1563
|
+
function check(node, name, names) {
|
|
1564
|
+
if (reported.has(name)) return;
|
|
1565
|
+
reported.add(name);
|
|
1566
|
+
const allowed = frozen[name] ?? max;
|
|
1567
|
+
if (names.size <= allowed) return;
|
|
1568
|
+
const messageId = frozen[name] === void 0 ? "tooMany" : "frozenGrew";
|
|
1569
|
+
context.report({ node, messageId, data: { name, count: names.size, max: allowed } });
|
|
1570
|
+
}
|
|
1571
|
+
function checkDeclaration(declaration) {
|
|
1572
|
+
const name = declaration.id.name;
|
|
1573
|
+
check(declaration, name, namesOfDeclaration(declaration, declarations, /* @__PURE__ */ new Set([name])));
|
|
1574
|
+
}
|
|
1575
|
+
function checkComponent(id, fn) {
|
|
1576
|
+
if (!id || !COMPONENT_NAME.test(id.name)) return;
|
|
1577
|
+
const annotation = propsAnnotation(fn);
|
|
1578
|
+
if (annotation?.type === "TSTypeLiteral") {
|
|
1579
|
+
check(annotation, id.name, memberNames(annotation.members));
|
|
1580
|
+
return;
|
|
1581
|
+
}
|
|
1582
|
+
if (annotation?.type !== "TSTypeReference" || annotation.typeName.type !== "Identifier") return;
|
|
1583
|
+
const declaration = declarations.get(annotation.typeName.name);
|
|
1584
|
+
if (declaration) checkDeclaration(declaration);
|
|
1585
|
+
}
|
|
1586
|
+
return {
|
|
1587
|
+
Program(program) {
|
|
1588
|
+
declarations = collectDeclarations(program);
|
|
1589
|
+
for (const [name, declaration] of declarations) {
|
|
1590
|
+
if (PROPS_NAME.test(name)) checkDeclaration(declaration);
|
|
1591
|
+
}
|
|
1592
|
+
},
|
|
1593
|
+
FunctionDeclaration(node) {
|
|
1594
|
+
checkComponent(node.id, node);
|
|
1595
|
+
},
|
|
1596
|
+
VariableDeclarator(node) {
|
|
1597
|
+
if (node.id.type === "Identifier") checkComponent(node.id, wrappedFunction(node.init));
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
var max_component_props_default = { rules: { "max-component-props": rule5 } };
|
|
1458
1603
|
function isPureReExportFile(programNode) {
|
|
1459
1604
|
const { body } = programNode;
|
|
1460
1605
|
if (body.length === 0) return false;
|
|
@@ -2047,6 +2192,8 @@ var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
|
|
|
2047
2192
|
var EXEMPT_URL_SCHEME = /^\s*(?:data|blob):/i;
|
|
2048
2193
|
var ABSOLUTE_HTTP_URL = /^https?:\/\/[^/\s]+\//i;
|
|
2049
2194
|
var ABSOLUTE_HTTP_LITERAL = /^https?:\/\/[^/\s]+(?:[/?#]|$)/i;
|
|
2195
|
+
var URL_HOST = /^https?:\/\/([^/\s?#:@]+)/i;
|
|
2196
|
+
var WILDCARD_PREFIX = "*.";
|
|
2050
2197
|
var URL_OBJECTS = /* @__PURE__ */ new Set(["URL", "webkitURL"]);
|
|
2051
2198
|
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
2052
2199
|
var AXIOS_MODULE = "axios";
|
|
@@ -2083,6 +2230,19 @@ function isThirdPartyLiteralUrl(node) {
|
|
|
2083
2230
|
const head = node.quasis[0].value.cooked ?? "";
|
|
2084
2231
|
return node.expressions.length === 0 ? ABSOLUTE_HTTP_LITERAL.test(head) : ABSOLUTE_HTTP_URL.test(head);
|
|
2085
2232
|
}
|
|
2233
|
+
function literalUrlHost(node) {
|
|
2234
|
+
const match = URL_HOST.exec(leadingText(node));
|
|
2235
|
+
return match === null ? "" : match[1].toLowerCase();
|
|
2236
|
+
}
|
|
2237
|
+
function hostMatches(host, pattern) {
|
|
2238
|
+
const wanted = pattern.toLowerCase();
|
|
2239
|
+
if (!wanted.startsWith(WILDCARD_PREFIX)) return host === wanted;
|
|
2240
|
+
return host.endsWith(wanted.slice(1));
|
|
2241
|
+
}
|
|
2242
|
+
function isBackendHostUrl(node, backendHosts) {
|
|
2243
|
+
const host = literalUrlHost(node);
|
|
2244
|
+
return host !== "" && backendHosts.some((pattern) => hostMatches(host, pattern));
|
|
2245
|
+
}
|
|
2086
2246
|
function unwrapExpression(node) {
|
|
2087
2247
|
let current = node;
|
|
2088
2248
|
while (current !== void 0 && current !== null && ["TSAsExpression", "TSNonNullExpression", "TSTypeAssertion", "TSSatisfiesExpression"].includes(current.type))
|
|
@@ -2134,9 +2294,10 @@ function scopeOf(context, node) {
|
|
|
2134
2294
|
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
2135
2295
|
return typeof sourceCode.getScope === "function" ? sourceCode.getScope(node) : context.getScope();
|
|
2136
2296
|
}
|
|
2137
|
-
function isExemptFetchTarget(context, node) {
|
|
2297
|
+
function isExemptFetchTarget(context, node, backendHosts) {
|
|
2138
2298
|
const target = node.arguments[0];
|
|
2139
|
-
if (isDataOrBlobUrl(target)
|
|
2299
|
+
if (isDataOrBlobUrl(target)) return true;
|
|
2300
|
+
if (isThirdPartyLiteralUrl(target)) return !isBackendHostUrl(target, backendHosts);
|
|
2140
2301
|
return isLocalObjectUrl(target, scopeOf(context, node));
|
|
2141
2302
|
}
|
|
2142
2303
|
function isAxiosSource(node) {
|
|
@@ -2159,7 +2320,8 @@ var noRawBackendFetchRule = {
|
|
|
2159
2320
|
{
|
|
2160
2321
|
type: "object",
|
|
2161
2322
|
properties: {
|
|
2162
|
-
allow: { type: "array", items: { type: "string" } }
|
|
2323
|
+
allow: { type: "array", items: { type: "string" } },
|
|
2324
|
+
backendHosts: { type: "array", items: { type: "string" } }
|
|
2163
2325
|
},
|
|
2164
2326
|
additionalProperties: false
|
|
2165
2327
|
}
|
|
@@ -2172,6 +2334,7 @@ var noRawBackendFetchRule = {
|
|
|
2172
2334
|
create(context) {
|
|
2173
2335
|
const options = context.options[0] ?? {};
|
|
2174
2336
|
const allow = Array.isArray(options.allow) ? options.allow : [];
|
|
2337
|
+
const backendHosts = Array.isArray(options.backendHosts) ? options.backendHosts : [];
|
|
2175
2338
|
const filename = context.filename ?? context.getFilename();
|
|
2176
2339
|
if (isExemptFile(filename, allow)) return {};
|
|
2177
2340
|
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
@@ -2179,7 +2342,7 @@ var noRawBackendFetchRule = {
|
|
|
2179
2342
|
return {
|
|
2180
2343
|
CallExpression(node) {
|
|
2181
2344
|
if (isFetchCallee(node.callee)) {
|
|
2182
|
-
if (!isExemptFetchTarget(context, node)) context.report({ node, messageId: "rawFetch" });
|
|
2345
|
+
if (!isExemptFetchTarget(context, node, backendHosts)) context.report({ node, messageId: "rawFetch" });
|
|
2183
2346
|
return;
|
|
2184
2347
|
}
|
|
2185
2348
|
const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
|
|
@@ -2469,7 +2632,7 @@ function isQueryKeyProperty(node) {
|
|
|
2469
2632
|
if (node.key.type === "Identifier") return node.key.name === QUERY_KEY;
|
|
2470
2633
|
return node.key.type === "Literal" && node.key.value === QUERY_KEY;
|
|
2471
2634
|
}
|
|
2472
|
-
var
|
|
2635
|
+
var rule6 = {
|
|
2473
2636
|
meta: {
|
|
2474
2637
|
type: "suggestion",
|
|
2475
2638
|
docs: {
|
|
@@ -2500,7 +2663,7 @@ var rule5 = {
|
|
|
2500
2663
|
};
|
|
2501
2664
|
}
|
|
2502
2665
|
};
|
|
2503
|
-
var query_key_factory_default = { rules: { "query-key-factory":
|
|
2666
|
+
var query_key_factory_default = { rules: { "query-key-factory": rule6 } };
|
|
2504
2667
|
|
|
2505
2668
|
// src/rules/require-stable-hook-args.js
|
|
2506
2669
|
var STABLE_INIT_CALLS = /* @__PURE__ */ new Set([
|
|
@@ -3175,6 +3338,7 @@ var ruleModules = [
|
|
|
3175
3338
|
game_menu_focusable_default,
|
|
3176
3339
|
i18n_interpolation_default,
|
|
3177
3340
|
i18n_param_names_default,
|
|
3341
|
+
max_component_props_default,
|
|
3178
3342
|
no_barrel_companion_file_default,
|
|
3179
3343
|
no_comments_default,
|
|
3180
3344
|
no_duplicate_nav_prefix_default,
|
|
@@ -3195,11 +3359,11 @@ var ruleModules = [
|
|
|
3195
3359
|
function mergeRules(modules) {
|
|
3196
3360
|
const merged = {};
|
|
3197
3361
|
for (const mod of modules) {
|
|
3198
|
-
for (const [name,
|
|
3362
|
+
for (const [name, rule7] of Object.entries(mod.rules)) {
|
|
3199
3363
|
if (merged[name] !== void 0) {
|
|
3200
3364
|
throw new Error(`Duplicate ESLint rule name: "${name}"`);
|
|
3201
3365
|
}
|
|
3202
|
-
merged[name] =
|
|
3366
|
+
merged[name] = rule7;
|
|
3203
3367
|
}
|
|
3204
3368
|
}
|
|
3205
3369
|
return merged;
|
|
@@ -3215,15 +3379,15 @@ var ruleNames = Object.keys(plugin.rules).sort();
|
|
|
3215
3379
|
var legacyPlugins = buildLegacyPlugins();
|
|
3216
3380
|
function buildLegacyPlugins() {
|
|
3217
3381
|
const out = {};
|
|
3218
|
-
for (const [name,
|
|
3219
|
-
out[name] = oneRulePlugin(name,
|
|
3382
|
+
for (const [name, rule7] of Object.entries(rules)) {
|
|
3383
|
+
out[name] = oneRulePlugin(name, rule7);
|
|
3220
3384
|
}
|
|
3221
3385
|
return out;
|
|
3222
3386
|
}
|
|
3223
|
-
function oneRulePlugin(name,
|
|
3387
|
+
function oneRulePlugin(name, rule7) {
|
|
3224
3388
|
return {
|
|
3225
3389
|
meta: { name, version: "1.0.0" },
|
|
3226
|
-
rules: { [name]:
|
|
3390
|
+
rules: { [name]: rule7 }
|
|
3227
3391
|
};
|
|
3228
3392
|
}
|
|
3229
3393
|
var OFF_LEVELS = ["off", 0];
|
|
@@ -3322,9 +3486,17 @@ var focusConfig = {
|
|
|
3322
3486
|
"@dloizides/explicit-initial-focus": "error"
|
|
3323
3487
|
}
|
|
3324
3488
|
};
|
|
3489
|
+
var COMPOSE_RULE_NAMES = ["max-component-props"];
|
|
3490
|
+
var composeConfig = {
|
|
3491
|
+
plugins: commentsConfig.plugins,
|
|
3492
|
+
rules: {
|
|
3493
|
+
"@dloizides/max-component-props": "error"
|
|
3494
|
+
}
|
|
3495
|
+
};
|
|
3325
3496
|
|
|
3326
3497
|
exports.API_RULE_NAMES = API_RULE_NAMES;
|
|
3327
3498
|
exports.COMMENT_RULE_NAMES = COMMENT_RULE_NAMES;
|
|
3499
|
+
exports.COMPOSE_RULE_NAMES = COMPOSE_RULE_NAMES;
|
|
3328
3500
|
exports.FOCUS_RULE_NAMES = FOCUS_RULE_NAMES;
|
|
3329
3501
|
exports.GAME_RULE_NAMES = GAME_RULE_NAMES;
|
|
3330
3502
|
exports.HOUSE_PATTERN_RULE_NAMES = HOUSE_PATTERN_RULE_NAMES;
|
|
@@ -3332,6 +3504,7 @@ exports.REUSE_RULE_NAMES = REUSE_RULE_NAMES;
|
|
|
3332
3504
|
exports.ROW_ACTION_RULE_NAMES = ROW_ACTION_RULE_NAMES;
|
|
3333
3505
|
exports.apiConfig = apiConfig;
|
|
3334
3506
|
exports.commentsConfig = commentsConfig;
|
|
3507
|
+
exports.composeConfig = composeConfig;
|
|
3335
3508
|
exports.focusConfig = focusConfig;
|
|
3336
3509
|
exports.gameConfig = gameConfig;
|
|
3337
3510
|
exports.legacyPlugins = legacyPlugins;
|