@dloizides/frontend-devtools 1.6.0 → 1.8.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.
@@ -957,12 +957,147 @@ var enum_file_isolation_default = {
957
957
  }
958
958
  };
959
959
 
960
+ // src/rules/game-menu-focusable.js
961
+ var POINTER_EVENTS = /* @__PURE__ */ new Set(["click", "pointerdown", "pointerup"]);
962
+ var NON_FOCUSABLE_TAGS = /* @__PURE__ */ new Set(["div", "span", "li", "img"]);
963
+ var FOCUS_ATTRIBUTES = /* @__PURE__ */ new Set(["tabindex", "role"]);
964
+ var FOCUS_PROPERTIES = /* @__PURE__ */ new Set(["tabIndex", "role"]);
965
+ var KEYDOWN = "keydown";
966
+ function getScopeFor(context, node) {
967
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
968
+ if (typeof sourceCode.getScope === "function") return sourceCode.getScope(node);
969
+ return context.getScope();
970
+ }
971
+ function findVariable(scope, name) {
972
+ let current = scope;
973
+ while (current) {
974
+ const found = current.set.get(name);
975
+ if (found) return found;
976
+ current = current.upper;
977
+ }
978
+ return void 0;
979
+ }
980
+ function unwrap(node) {
981
+ let current = node;
982
+ while (current && (current.type === "TSAsExpression" || current.type === "TSNonNullExpression" || current.type === "TSTypeAssertion")) {
983
+ current = current.expression;
984
+ }
985
+ return current;
986
+ }
987
+ function stringValue(node) {
988
+ const target = unwrap(node);
989
+ if (!target) return void 0;
990
+ if (target.type === "Literal" && typeof target.value === "string") return target.value;
991
+ if (target.type === "TemplateLiteral" && target.expressions.length === 0) return target.quasis[0].value.cooked;
992
+ return void 0;
993
+ }
994
+ function propertyName(member) {
995
+ if (member.computed) return stringValue(member.property);
996
+ return member.property.type === "Identifier" ? member.property.name : void 0;
997
+ }
998
+ function createdTag(init) {
999
+ const call = unwrap(init);
1000
+ if (!call || call.type !== "CallExpression") return void 0;
1001
+ if (call.callee.type !== "MemberExpression" || propertyName(call.callee) !== "createElement") return void 0;
1002
+ const tag = stringValue(call.arguments[0]);
1003
+ return tag === void 0 ? void 0 : tag.toLowerCase();
1004
+ }
1005
+ function nonFocusableTag(variable) {
1006
+ const initializers = variable.defs.filter((def) => def.node.type === "VariableDeclarator").map((def) => def.node.init);
1007
+ const assigned = variable.references.filter((ref) => ref.isWrite() && ref.writeExpr).map((ref) => ref.writeExpr);
1008
+ return [...initializers, ...assigned].map(createdTag).find((tag) => NON_FOCUSABLE_TAGS.has(tag ?? ""));
1009
+ }
1010
+ function setsFocusAttribute(reference) {
1011
+ const member = reference.identifier.parent;
1012
+ if (!member || member.type !== "MemberExpression" || member.object !== reference.identifier) return false;
1013
+ const name = propertyName(member);
1014
+ const outer = member.parent;
1015
+ if (FOCUS_PROPERTIES.has(name ?? "")) return outer.type === "AssignmentExpression" && outer.left === member;
1016
+ if (name !== "setAttribute" || outer.type !== "CallExpression" || outer.callee !== member) return false;
1017
+ return FOCUS_ATTRIBUTES.has((stringValue(outer.arguments[0]) ?? "").toLowerCase());
1018
+ }
1019
+ function unfocusableTag(context, node, identifier) {
1020
+ if (!identifier || identifier.type !== "Identifier") return void 0;
1021
+ const variable = findVariable(getScopeFor(context, node), identifier.name);
1022
+ if (!variable || variable.references.some(setsFocusAttribute)) return void 0;
1023
+ return nonFocusableTag(variable);
1024
+ }
1025
+ function resolveHandler(context, node, handler) {
1026
+ const target = unwrap(handler);
1027
+ if (!target) return void 0;
1028
+ if (target.type === "ArrowFunctionExpression" || target.type === "FunctionExpression") return target;
1029
+ if (target.type !== "Identifier") return void 0;
1030
+ const variable = findVariable(getScopeFor(context, node), target.name);
1031
+ const def = variable && variable.defs[0];
1032
+ if (!def) return void 0;
1033
+ if (def.node.type === "FunctionDeclaration") return def.node;
1034
+ if (def.node.type === "VariableDeclarator") return resolveHandler(context, node, def.node.init);
1035
+ return void 0;
1036
+ }
1037
+ function stopPropagationCalls(fn) {
1038
+ const found = [];
1039
+ const visit = (node) => {
1040
+ if (!node || typeof node.type !== "string") return;
1041
+ if (node !== fn && node.type.includes("Function")) return;
1042
+ const isStop = node.type === "CallExpression" && node.callee.type === "MemberExpression" && propertyName(node.callee) === "stopPropagation";
1043
+ if (isStop) found.push(node);
1044
+ for (const key of Object.keys(node)) {
1045
+ if (key === "parent") continue;
1046
+ const child = node[key];
1047
+ if (Array.isArray(child)) child.forEach(visit);
1048
+ else if (child && typeof child === "object") visit(child);
1049
+ }
1050
+ };
1051
+ visit(fn.body);
1052
+ return found;
1053
+ }
1054
+ var rule = {
1055
+ meta: {
1056
+ type: "problem",
1057
+ docs: {
1058
+ description: "Game menus stay walkable with arrow keys and a controller: no pointer-only div/span/li/img items, no keydown stopPropagation."
1059
+ },
1060
+ schema: [],
1061
+ messages: {
1062
+ 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.",
1063
+ keydownStopPropagation: "A keydown handler calls stopPropagation(), which hides keys from every other listener. If it is needed, disable this line with the reason."
1064
+ }
1065
+ },
1066
+ create(context) {
1067
+ const reportPointerOnly = (node, identifier, event) => {
1068
+ const tag = unfocusableTag(context, node, identifier);
1069
+ if (tag === void 0) return;
1070
+ context.report({ node, messageId: "pointerOnlyItem", data: { name: identifier.name, tag, event } });
1071
+ };
1072
+ const reportKeydown = (node, handler) => {
1073
+ const fn = resolveHandler(context, node, handler);
1074
+ if (!fn) return;
1075
+ stopPropagationCalls(fn).forEach((call) => context.report({ node: call, messageId: "keydownStopPropagation" }));
1076
+ };
1077
+ return {
1078
+ CallExpression(node) {
1079
+ if (node.callee.type !== "MemberExpression" || propertyName(node.callee) !== "addEventListener") return;
1080
+ const event = stringValue(node.arguments[0]);
1081
+ if (event === KEYDOWN) reportKeydown(node, node.arguments[1]);
1082
+ else if (POINTER_EVENTS.has(event ?? "")) reportPointerOnly(node, node.callee.object, event);
1083
+ },
1084
+ AssignmentExpression(node) {
1085
+ if (node.left.type !== "MemberExpression") return;
1086
+ const name = propertyName(node.left);
1087
+ if (name === "onclick") reportPointerOnly(node, node.left.object, "onclick");
1088
+ else if (name === "onkeydown") reportKeydown(node, node.right);
1089
+ }
1090
+ };
1091
+ }
1092
+ };
1093
+ var game_menu_focusable_default = { rules: { "game-menu-focusable": rule } };
1094
+
960
1095
  // src/rules/i18n-interpolation.js
961
1096
  var DOUBLE_BRACE_REGEX = /\{\{(\w+)\}\}/g;
962
1097
  var SINGLE_BRACE_REGEX = /(?<!\{)\{(\w+)\}(?!\})/g;
963
1098
  var ALLOWED_NAMES = /* @__PURE__ */ new Set(["p1", "p2", "p3"]);
964
1099
  var MAX_POSITIONAL_PARAMS = 3;
965
- var rule = {
1100
+ var rule2 = {
966
1101
  meta: {
967
1102
  type: "problem",
968
1103
  docs: {
@@ -1081,7 +1216,7 @@ var rule = {
1081
1216
  };
1082
1217
  var i18n_interpolation_default = {
1083
1218
  rules: {
1084
- "i18n-interpolation": rule
1219
+ "i18n-interpolation": rule2
1085
1220
  }
1086
1221
  };
1087
1222
 
@@ -1103,7 +1238,7 @@ var I18NEXT_CONFIG_KEYS = /* @__PURE__ */ new Set([
1103
1238
  "formatParams",
1104
1239
  "missingInterpolationHandler"
1105
1240
  ]);
1106
- var rule2 = {
1241
+ var rule3 = {
1107
1242
  meta: {
1108
1243
  type: "problem",
1109
1244
  docs: {
@@ -1144,7 +1279,7 @@ var rule2 = {
1144
1279
  };
1145
1280
  var i18n_param_names_default = {
1146
1281
  rules: {
1147
- "i18n-param-names": rule2
1282
+ "i18n-param-names": rule3
1148
1283
  }
1149
1284
  };
1150
1285
 
@@ -1762,6 +1897,107 @@ var no_product_imports_in_shared_default = {
1762
1897
  }
1763
1898
  };
1764
1899
 
1900
+ // src/rules/no-raw-backend-fetch.js
1901
+ var DEFAULT_ALLOWED_PATH_FRAGMENTS = [
1902
+ "/src/server/",
1903
+ "/src/http/",
1904
+ "/src/lib/http/",
1905
+ "/generated/",
1906
+ "/app/+html.",
1907
+ "service-worker",
1908
+ "serviceWorker",
1909
+ "/sw."
1910
+ ];
1911
+ var CLIENT_PACKAGE_PATH = /\/packages\/[^/]+-client\//;
1912
+ var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
1913
+ var EXEMPT_URL_SCHEME = /^\s*(?:data|blob):/i;
1914
+ var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
1915
+ var AXIOS_MODULE = "axios";
1916
+ function normalisePath(filename) {
1917
+ return typeof filename === "string" ? filename.split("\\").join("/") : "";
1918
+ }
1919
+ function isExemptFile(filename, allow) {
1920
+ const path2 = normalisePath(filename);
1921
+ if (!path2.includes("/src/")) return true;
1922
+ if (TEST_FILE.test(path2)) return true;
1923
+ if (CLIENT_PACKAGE_PATH.test(path2)) return true;
1924
+ return [...DEFAULT_ALLOWED_PATH_FRAGMENTS, ...allow].some((fragment) => path2.includes(fragment));
1925
+ }
1926
+ function isFetchCallee(callee) {
1927
+ if (callee.type === "Identifier") return callee.name === "fetch";
1928
+ if (callee.type !== "MemberExpression" || callee.computed) return false;
1929
+ const isFetchProperty = callee.property.type === "Identifier" && callee.property.name === "fetch";
1930
+ const isGlobalObject = callee.object.type === "Identifier" && GLOBAL_OBJECTS.has(callee.object.name);
1931
+ return isFetchProperty && isGlobalObject;
1932
+ }
1933
+ function leadingText(node) {
1934
+ if (node === void 0) return "";
1935
+ if (node.type === "Literal" && typeof node.value === "string") return node.value;
1936
+ if (node.type === "TemplateLiteral") return node.quasis[0].value.cooked ?? "";
1937
+ return "";
1938
+ }
1939
+ function isDataOrBlobUrl(node) {
1940
+ return EXEMPT_URL_SCHEME.test(leadingText(node));
1941
+ }
1942
+ function isAxiosSource(node) {
1943
+ return node !== void 0 && node.type === "Literal" && node.value === AXIOS_MODULE;
1944
+ }
1945
+ function isTypeOnlyImport2(node) {
1946
+ if (node.importKind === "type") return true;
1947
+ const hasSpecifiers = node.specifiers.length > 0;
1948
+ return hasSpecifiers && node.specifiers.every((specifier) => specifier.importKind === "type");
1949
+ }
1950
+ var noRawBackendFetchRule = {
1951
+ meta: {
1952
+ type: "problem",
1953
+ docs: {
1954
+ description: "PAT-API-1: web apps call the backend only through the shared client or generated hooks, never raw fetch() or axios in app code.",
1955
+ category: "Best Practices",
1956
+ recommended: true
1957
+ },
1958
+ schema: [
1959
+ {
1960
+ type: "object",
1961
+ properties: {
1962
+ allow: { type: "array", items: { type: "string" } }
1963
+ },
1964
+ additionalProperties: false
1965
+ }
1966
+ ],
1967
+ messages: {
1968
+ rawFetch: "Raw fetch() in app code (PAT-API-1). Call the backend through the shared client or a generated API hook; only src/server/, src/http/, *-client packages, generated code and the service worker may call fetch.",
1969
+ rawAxios: "axios imported in app code (PAT-API-1). Use the shared client or a generated API hook; only src/server/, src/http/, *-client packages and generated code may import axios."
1970
+ }
1971
+ },
1972
+ create(context) {
1973
+ const options = context.options[0] ?? {};
1974
+ const allow = Array.isArray(options.allow) ? options.allow : [];
1975
+ const filename = context.filename ?? context.getFilename();
1976
+ if (isExemptFile(filename, allow)) return {};
1977
+ return {
1978
+ CallExpression(node) {
1979
+ if (isFetchCallee(node.callee)) {
1980
+ if (!isDataOrBlobUrl(node.arguments[0])) context.report({ node, messageId: "rawFetch" });
1981
+ return;
1982
+ }
1983
+ const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
1984
+ if (isRequire && isAxiosSource(node.arguments[0])) context.report({ node, messageId: "rawAxios" });
1985
+ },
1986
+ ImportExpression(node) {
1987
+ if (isAxiosSource(node.source)) context.report({ node, messageId: "rawAxios" });
1988
+ },
1989
+ ImportDeclaration(node) {
1990
+ if (isAxiosSource(node.source) && !isTypeOnlyImport2(node)) context.report({ node, messageId: "rawAxios" });
1991
+ }
1992
+ };
1993
+ }
1994
+ };
1995
+ var no_raw_backend_fetch_default = {
1996
+ rules: {
1997
+ "no-raw-backend-fetch": noRawBackendFetchRule
1998
+ }
1999
+ };
2000
+
1765
2001
  // src/rules/no-raw-color-literal.js
1766
2002
  var FULL_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
1767
2003
  var FUNCTIONAL_COLOR = /\b(?:rgba?|hsla?)\s*\(/;
@@ -2154,12 +2390,12 @@ var SPEC_TYPE = "RowActionSpec";
2154
2390
  var MEMO_HOOKS = /* @__PURE__ */ new Set(["useMemo", "useCallback"]);
2155
2391
  var MAX_DEPTH = 8;
2156
2392
  var Source = Object.freeze({ LOCAL: "local", EXTERNAL: "external" });
2157
- function getScopeFor(context, node) {
2393
+ function getScopeFor2(context, node) {
2158
2394
  const sourceCode = context.sourceCode ?? context.getSourceCode();
2159
2395
  if (typeof sourceCode.getScope === "function") return sourceCode.getScope(node);
2160
2396
  return context.getScope();
2161
2397
  }
2162
- function findVariable(scope, name) {
2398
+ function findVariable2(scope, name) {
2163
2399
  let current = scope;
2164
2400
  while (current) {
2165
2401
  const found = current.set.get(name);
@@ -2231,7 +2467,7 @@ function createClassifier(context) {
2231
2467
  }
2232
2468
  const root = rootIdentifier(node.callee);
2233
2469
  if (!root) return Source.EXTERNAL;
2234
- const variable = findVariable(getScopeFor(context, node), root.name);
2470
+ const variable = findVariable2(getScopeFor2(context, node), root.name);
2235
2471
  if (!variable || variable.defs.length === 0) return Source.EXTERNAL;
2236
2472
  const def = variable.defs[0];
2237
2473
  if (def.type === "ImportBinding" || def.type === "Parameter") return Source.EXTERNAL;
@@ -2256,7 +2492,7 @@ function createClassifier(context) {
2256
2492
  case "CallExpression":
2257
2493
  return classifyCall(node, depth, seen);
2258
2494
  case "Identifier": {
2259
- const variable = findVariable(getScopeFor(context, node), node.name);
2495
+ const variable = findVariable2(getScopeFor2(context, node), node.name);
2260
2496
  return variable ? classifyVariable(variable, depth, seen) : Source.EXTERNAL;
2261
2497
  }
2262
2498
  default:
@@ -2569,6 +2805,7 @@ var ruleModules = [
2569
2805
  enforce_route_preload_default,
2570
2806
  enforce_test_colocation_default,
2571
2807
  enum_file_isolation_default,
2808
+ game_menu_focusable_default,
2572
2809
  i18n_interpolation_default,
2573
2810
  i18n_param_names_default,
2574
2811
  no_barrel_companion_file_default,
@@ -2579,6 +2816,7 @@ var ruleModules = [
2579
2816
  no_null_check_default,
2580
2817
  no_optional_undefined_default,
2581
2818
  no_product_imports_in_shared_default,
2819
+ no_raw_backend_fetch_default,
2582
2820
  no_raw_color_literal_default,
2583
2821
  prefer_const_enum_default,
2584
2822
  require_stable_hook_args_default,
@@ -2588,11 +2826,11 @@ var ruleModules = [
2588
2826
  function mergeRules(modules) {
2589
2827
  const merged = {};
2590
2828
  for (const mod of modules) {
2591
- for (const [name, rule3] of Object.entries(mod.rules)) {
2829
+ for (const [name, rule4] of Object.entries(mod.rules)) {
2592
2830
  if (merged[name] !== void 0) {
2593
2831
  throw new Error(`Duplicate ESLint rule name: "${name}"`);
2594
2832
  }
2595
- merged[name] = rule3;
2833
+ merged[name] = rule4;
2596
2834
  }
2597
2835
  }
2598
2836
  return merged;
@@ -2608,15 +2846,15 @@ var ruleNames = Object.keys(plugin.rules).sort();
2608
2846
  var legacyPlugins = buildLegacyPlugins();
2609
2847
  function buildLegacyPlugins() {
2610
2848
  const out = {};
2611
- for (const [name, rule3] of Object.entries(rules)) {
2612
- out[name] = oneRulePlugin(name, rule3);
2849
+ for (const [name, rule4] of Object.entries(rules)) {
2850
+ out[name] = oneRulePlugin(name, rule4);
2613
2851
  }
2614
2852
  return out;
2615
2853
  }
2616
- function oneRulePlugin(name, rule3) {
2854
+ function oneRulePlugin(name, rule4) {
2617
2855
  return {
2618
2856
  meta: { name, version: "1.0.0" },
2619
- rules: { [name]: rule3 }
2857
+ rules: { [name]: rule4 }
2620
2858
  };
2621
2859
  }
2622
2860
 
@@ -2642,14 +2880,32 @@ var rowActionsConfig = {
2642
2880
  "@dloizides/single-row-action-source": "error"
2643
2881
  }
2644
2882
  };
2883
+ var GAME_RULE_NAMES = ["game-menu-focusable"];
2884
+ var gameConfig = {
2885
+ plugins: commentsConfig.plugins,
2886
+ rules: {
2887
+ "@dloizides/game-menu-focusable": "error"
2888
+ }
2889
+ };
2890
+ var API_RULE_NAMES = ["no-raw-backend-fetch"];
2891
+ var apiConfig = {
2892
+ plugins: commentsConfig.plugins,
2893
+ rules: {
2894
+ "@dloizides/no-raw-backend-fetch": "error"
2895
+ }
2896
+ };
2645
2897
  var recommendedConfig = {
2646
2898
  plugins: commentsConfig.plugins,
2647
- rules: { ...commentsConfig.rules, ...rowActionsConfig.rules }
2899
+ rules: { ...commentsConfig.rules, ...rowActionsConfig.rules, ...apiConfig.rules }
2648
2900
  };
2649
2901
 
2902
+ exports.API_RULE_NAMES = API_RULE_NAMES;
2650
2903
  exports.COMMENT_RULE_NAMES = COMMENT_RULE_NAMES;
2904
+ exports.GAME_RULE_NAMES = GAME_RULE_NAMES;
2651
2905
  exports.ROW_ACTION_RULE_NAMES = ROW_ACTION_RULE_NAMES;
2906
+ exports.apiConfig = apiConfig;
2652
2907
  exports.commentsConfig = commentsConfig;
2908
+ exports.gameConfig = gameConfig;
2653
2909
  exports.legacyPlugins = legacyPlugins;
2654
2910
  exports.plugin = plugin;
2655
2911
  exports.recommendedConfig = recommendedConfig;