@dloizides/frontend-devtools 1.5.0 → 1.7.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.
@@ -950,12 +950,147 @@ var enum_file_isolation_default = {
950
950
  }
951
951
  };
952
952
 
953
+ // src/rules/game-menu-focusable.js
954
+ var POINTER_EVENTS = /* @__PURE__ */ new Set(["click", "pointerdown", "pointerup"]);
955
+ var NON_FOCUSABLE_TAGS = /* @__PURE__ */ new Set(["div", "span", "li", "img"]);
956
+ var FOCUS_ATTRIBUTES = /* @__PURE__ */ new Set(["tabindex", "role"]);
957
+ var FOCUS_PROPERTIES = /* @__PURE__ */ new Set(["tabIndex", "role"]);
958
+ var KEYDOWN = "keydown";
959
+ function getScopeFor(context, node) {
960
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
961
+ if (typeof sourceCode.getScope === "function") return sourceCode.getScope(node);
962
+ return context.getScope();
963
+ }
964
+ function findVariable(scope, name) {
965
+ let current = scope;
966
+ while (current) {
967
+ const found = current.set.get(name);
968
+ if (found) return found;
969
+ current = current.upper;
970
+ }
971
+ return void 0;
972
+ }
973
+ function unwrap(node) {
974
+ let current = node;
975
+ while (current && (current.type === "TSAsExpression" || current.type === "TSNonNullExpression" || current.type === "TSTypeAssertion")) {
976
+ current = current.expression;
977
+ }
978
+ return current;
979
+ }
980
+ function stringValue(node) {
981
+ const target = unwrap(node);
982
+ if (!target) return void 0;
983
+ if (target.type === "Literal" && typeof target.value === "string") return target.value;
984
+ if (target.type === "TemplateLiteral" && target.expressions.length === 0) return target.quasis[0].value.cooked;
985
+ return void 0;
986
+ }
987
+ function propertyName(member) {
988
+ if (member.computed) return stringValue(member.property);
989
+ return member.property.type === "Identifier" ? member.property.name : void 0;
990
+ }
991
+ function createdTag(init) {
992
+ const call = unwrap(init);
993
+ if (!call || call.type !== "CallExpression") return void 0;
994
+ if (call.callee.type !== "MemberExpression" || propertyName(call.callee) !== "createElement") return void 0;
995
+ const tag = stringValue(call.arguments[0]);
996
+ return tag === void 0 ? void 0 : tag.toLowerCase();
997
+ }
998
+ function nonFocusableTag(variable) {
999
+ const initializers = variable.defs.filter((def) => def.node.type === "VariableDeclarator").map((def) => def.node.init);
1000
+ const assigned = variable.references.filter((ref) => ref.isWrite() && ref.writeExpr).map((ref) => ref.writeExpr);
1001
+ return [...initializers, ...assigned].map(createdTag).find((tag) => NON_FOCUSABLE_TAGS.has(tag ?? ""));
1002
+ }
1003
+ function setsFocusAttribute(reference) {
1004
+ const member = reference.identifier.parent;
1005
+ if (!member || member.type !== "MemberExpression" || member.object !== reference.identifier) return false;
1006
+ const name = propertyName(member);
1007
+ const outer = member.parent;
1008
+ if (FOCUS_PROPERTIES.has(name ?? "")) return outer.type === "AssignmentExpression" && outer.left === member;
1009
+ if (name !== "setAttribute" || outer.type !== "CallExpression" || outer.callee !== member) return false;
1010
+ return FOCUS_ATTRIBUTES.has((stringValue(outer.arguments[0]) ?? "").toLowerCase());
1011
+ }
1012
+ function unfocusableTag(context, node, identifier) {
1013
+ if (!identifier || identifier.type !== "Identifier") return void 0;
1014
+ const variable = findVariable(getScopeFor(context, node), identifier.name);
1015
+ if (!variable || variable.references.some(setsFocusAttribute)) return void 0;
1016
+ return nonFocusableTag(variable);
1017
+ }
1018
+ function resolveHandler(context, node, handler) {
1019
+ const target = unwrap(handler);
1020
+ if (!target) return void 0;
1021
+ if (target.type === "ArrowFunctionExpression" || target.type === "FunctionExpression") return target;
1022
+ if (target.type !== "Identifier") return void 0;
1023
+ const variable = findVariable(getScopeFor(context, node), target.name);
1024
+ const def = variable && variable.defs[0];
1025
+ if (!def) return void 0;
1026
+ if (def.node.type === "FunctionDeclaration") return def.node;
1027
+ if (def.node.type === "VariableDeclarator") return resolveHandler(context, node, def.node.init);
1028
+ return void 0;
1029
+ }
1030
+ function stopPropagationCalls(fn) {
1031
+ const found = [];
1032
+ const visit = (node) => {
1033
+ if (!node || typeof node.type !== "string") return;
1034
+ if (node !== fn && node.type.includes("Function")) return;
1035
+ const isStop = node.type === "CallExpression" && node.callee.type === "MemberExpression" && propertyName(node.callee) === "stopPropagation";
1036
+ if (isStop) found.push(node);
1037
+ for (const key of Object.keys(node)) {
1038
+ if (key === "parent") continue;
1039
+ const child = node[key];
1040
+ if (Array.isArray(child)) child.forEach(visit);
1041
+ else if (child && typeof child === "object") visit(child);
1042
+ }
1043
+ };
1044
+ visit(fn.body);
1045
+ return found;
1046
+ }
1047
+ var rule = {
1048
+ meta: {
1049
+ type: "problem",
1050
+ docs: {
1051
+ description: "Game menus stay walkable with arrow keys and a controller: no pointer-only div/span/li/img items, no keydown stopPropagation."
1052
+ },
1053
+ schema: [],
1054
+ messages: {
1055
+ pointerOnlyItem: "'{{name}}' is a <{{tag}}> with a {{event}} handler but no tabindex or role: keyboard and controller users cannot reach it. Use a <button>, or set tabIndex and role.",
1056
+ keydownStopPropagation: "A keydown handler calls stopPropagation(), which hides keys from every other listener. If it is needed, disable this line with the reason."
1057
+ }
1058
+ },
1059
+ create(context) {
1060
+ const reportPointerOnly = (node, identifier, event) => {
1061
+ const tag = unfocusableTag(context, node, identifier);
1062
+ if (tag === void 0) return;
1063
+ context.report({ node, messageId: "pointerOnlyItem", data: { name: identifier.name, tag, event } });
1064
+ };
1065
+ const reportKeydown = (node, handler) => {
1066
+ const fn = resolveHandler(context, node, handler);
1067
+ if (!fn) return;
1068
+ stopPropagationCalls(fn).forEach((call) => context.report({ node: call, messageId: "keydownStopPropagation" }));
1069
+ };
1070
+ return {
1071
+ CallExpression(node) {
1072
+ if (node.callee.type !== "MemberExpression" || propertyName(node.callee) !== "addEventListener") return;
1073
+ const event = stringValue(node.arguments[0]);
1074
+ if (event === KEYDOWN) reportKeydown(node, node.arguments[1]);
1075
+ else if (POINTER_EVENTS.has(event ?? "")) reportPointerOnly(node, node.callee.object, event);
1076
+ },
1077
+ AssignmentExpression(node) {
1078
+ if (node.left.type !== "MemberExpression") return;
1079
+ const name = propertyName(node.left);
1080
+ if (name === "onclick") reportPointerOnly(node, node.left.object, "onclick");
1081
+ else if (name === "onkeydown") reportKeydown(node, node.right);
1082
+ }
1083
+ };
1084
+ }
1085
+ };
1086
+ var game_menu_focusable_default = { rules: { "game-menu-focusable": rule } };
1087
+
953
1088
  // src/rules/i18n-interpolation.js
954
1089
  var DOUBLE_BRACE_REGEX = /\{\{(\w+)\}\}/g;
955
1090
  var SINGLE_BRACE_REGEX = /(?<!\{)\{(\w+)\}(?!\})/g;
956
1091
  var ALLOWED_NAMES = /* @__PURE__ */ new Set(["p1", "p2", "p3"]);
957
1092
  var MAX_POSITIONAL_PARAMS = 3;
958
- var rule = {
1093
+ var rule2 = {
959
1094
  meta: {
960
1095
  type: "problem",
961
1096
  docs: {
@@ -1074,7 +1209,7 @@ var rule = {
1074
1209
  };
1075
1210
  var i18n_interpolation_default = {
1076
1211
  rules: {
1077
- "i18n-interpolation": rule
1212
+ "i18n-interpolation": rule2
1078
1213
  }
1079
1214
  };
1080
1215
 
@@ -1096,7 +1231,7 @@ var I18NEXT_CONFIG_KEYS = /* @__PURE__ */ new Set([
1096
1231
  "formatParams",
1097
1232
  "missingInterpolationHandler"
1098
1233
  ]);
1099
- var rule2 = {
1234
+ var rule3 = {
1100
1235
  meta: {
1101
1236
  type: "problem",
1102
1237
  docs: {
@@ -1137,7 +1272,7 @@ var rule2 = {
1137
1272
  };
1138
1273
  var i18n_param_names_default = {
1139
1274
  rules: {
1140
- "i18n-param-names": rule2
1275
+ "i18n-param-names": rule3
1141
1276
  }
1142
1277
  };
1143
1278
 
@@ -2147,12 +2282,12 @@ var SPEC_TYPE = "RowActionSpec";
2147
2282
  var MEMO_HOOKS = /* @__PURE__ */ new Set(["useMemo", "useCallback"]);
2148
2283
  var MAX_DEPTH = 8;
2149
2284
  var Source = Object.freeze({ LOCAL: "local", EXTERNAL: "external" });
2150
- function getScopeFor(context, node) {
2285
+ function getScopeFor2(context, node) {
2151
2286
  const sourceCode = context.sourceCode ?? context.getSourceCode();
2152
2287
  if (typeof sourceCode.getScope === "function") return sourceCode.getScope(node);
2153
2288
  return context.getScope();
2154
2289
  }
2155
- function findVariable(scope, name) {
2290
+ function findVariable2(scope, name) {
2156
2291
  let current = scope;
2157
2292
  while (current) {
2158
2293
  const found = current.set.get(name);
@@ -2224,7 +2359,7 @@ function createClassifier(context) {
2224
2359
  }
2225
2360
  const root = rootIdentifier(node.callee);
2226
2361
  if (!root) return Source.EXTERNAL;
2227
- const variable = findVariable(getScopeFor(context, node), root.name);
2362
+ const variable = findVariable2(getScopeFor2(context, node), root.name);
2228
2363
  if (!variable || variable.defs.length === 0) return Source.EXTERNAL;
2229
2364
  const def = variable.defs[0];
2230
2365
  if (def.type === "ImportBinding" || def.type === "Parameter") return Source.EXTERNAL;
@@ -2249,7 +2384,7 @@ function createClassifier(context) {
2249
2384
  case "CallExpression":
2250
2385
  return classifyCall(node, depth, seen);
2251
2386
  case "Identifier": {
2252
- const variable = findVariable(getScopeFor(context, node), node.name);
2387
+ const variable = findVariable2(getScopeFor2(context, node), node.name);
2253
2388
  return variable ? classifyVariable(variable, depth, seen) : Source.EXTERNAL;
2254
2389
  }
2255
2390
  default:
@@ -2562,6 +2697,7 @@ var ruleModules = [
2562
2697
  enforce_route_preload_default,
2563
2698
  enforce_test_colocation_default,
2564
2699
  enum_file_isolation_default,
2700
+ game_menu_focusable_default,
2565
2701
  i18n_interpolation_default,
2566
2702
  i18n_param_names_default,
2567
2703
  no_barrel_companion_file_default,
@@ -2581,11 +2717,11 @@ var ruleModules = [
2581
2717
  function mergeRules(modules) {
2582
2718
  const merged = {};
2583
2719
  for (const mod of modules) {
2584
- for (const [name, rule3] of Object.entries(mod.rules)) {
2720
+ for (const [name, rule4] of Object.entries(mod.rules)) {
2585
2721
  if (merged[name] !== void 0) {
2586
2722
  throw new Error(`Duplicate ESLint rule name: "${name}"`);
2587
2723
  }
2588
- merged[name] = rule3;
2724
+ merged[name] = rule4;
2589
2725
  }
2590
2726
  }
2591
2727
  return merged;
@@ -2601,15 +2737,15 @@ var ruleNames = Object.keys(plugin.rules).sort();
2601
2737
  var legacyPlugins = buildLegacyPlugins();
2602
2738
  function buildLegacyPlugins() {
2603
2739
  const out = {};
2604
- for (const [name, rule3] of Object.entries(rules)) {
2605
- out[name] = oneRulePlugin(name, rule3);
2740
+ for (const [name, rule4] of Object.entries(rules)) {
2741
+ out[name] = oneRulePlugin(name, rule4);
2606
2742
  }
2607
2743
  return out;
2608
2744
  }
2609
- function oneRulePlugin(name, rule3) {
2745
+ function oneRulePlugin(name, rule4) {
2610
2746
  return {
2611
2747
  meta: { name, version: "1.0.0" },
2612
- rules: { [name]: rule3 }
2748
+ rules: { [name]: rule4 }
2613
2749
  };
2614
2750
  }
2615
2751
 
@@ -2635,11 +2771,18 @@ var rowActionsConfig = {
2635
2771
  "@dloizides/single-row-action-source": "error"
2636
2772
  }
2637
2773
  };
2774
+ var GAME_RULE_NAMES = ["game-menu-focusable"];
2775
+ var gameConfig = {
2776
+ plugins: commentsConfig.plugins,
2777
+ rules: {
2778
+ "@dloizides/game-menu-focusable": "error"
2779
+ }
2780
+ };
2638
2781
  var recommendedConfig = {
2639
2782
  plugins: commentsConfig.plugins,
2640
2783
  rules: { ...commentsConfig.rules, ...rowActionsConfig.rules }
2641
2784
  };
2642
2785
 
2643
- export { COMMENT_RULE_NAMES, ROW_ACTION_RULE_NAMES, commentsConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
2786
+ export { COMMENT_RULE_NAMES, GAME_RULE_NAMES, ROW_ACTION_RULE_NAMES, commentsConfig, gameConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
2644
2787
  //# sourceMappingURL=index.mjs.map
2645
2788
  //# sourceMappingURL=index.mjs.map