@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.
@@ -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
 
@@ -1755,6 +1890,107 @@ var no_product_imports_in_shared_default = {
1755
1890
  }
1756
1891
  };
1757
1892
 
1893
+ // src/rules/no-raw-backend-fetch.js
1894
+ var DEFAULT_ALLOWED_PATH_FRAGMENTS = [
1895
+ "/src/server/",
1896
+ "/src/http/",
1897
+ "/src/lib/http/",
1898
+ "/generated/",
1899
+ "/app/+html.",
1900
+ "service-worker",
1901
+ "serviceWorker",
1902
+ "/sw."
1903
+ ];
1904
+ var CLIENT_PACKAGE_PATH = /\/packages\/[^/]+-client\//;
1905
+ var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
1906
+ var EXEMPT_URL_SCHEME = /^\s*(?:data|blob):/i;
1907
+ var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
1908
+ var AXIOS_MODULE = "axios";
1909
+ function normalisePath(filename) {
1910
+ return typeof filename === "string" ? filename.split("\\").join("/") : "";
1911
+ }
1912
+ function isExemptFile(filename, allow) {
1913
+ const path2 = normalisePath(filename);
1914
+ if (!path2.includes("/src/")) return true;
1915
+ if (TEST_FILE.test(path2)) return true;
1916
+ if (CLIENT_PACKAGE_PATH.test(path2)) return true;
1917
+ return [...DEFAULT_ALLOWED_PATH_FRAGMENTS, ...allow].some((fragment) => path2.includes(fragment));
1918
+ }
1919
+ function isFetchCallee(callee) {
1920
+ if (callee.type === "Identifier") return callee.name === "fetch";
1921
+ if (callee.type !== "MemberExpression" || callee.computed) return false;
1922
+ const isFetchProperty = callee.property.type === "Identifier" && callee.property.name === "fetch";
1923
+ const isGlobalObject = callee.object.type === "Identifier" && GLOBAL_OBJECTS.has(callee.object.name);
1924
+ return isFetchProperty && isGlobalObject;
1925
+ }
1926
+ function leadingText(node) {
1927
+ if (node === void 0) return "";
1928
+ if (node.type === "Literal" && typeof node.value === "string") return node.value;
1929
+ if (node.type === "TemplateLiteral") return node.quasis[0].value.cooked ?? "";
1930
+ return "";
1931
+ }
1932
+ function isDataOrBlobUrl(node) {
1933
+ return EXEMPT_URL_SCHEME.test(leadingText(node));
1934
+ }
1935
+ function isAxiosSource(node) {
1936
+ return node !== void 0 && node.type === "Literal" && node.value === AXIOS_MODULE;
1937
+ }
1938
+ function isTypeOnlyImport2(node) {
1939
+ if (node.importKind === "type") return true;
1940
+ const hasSpecifiers = node.specifiers.length > 0;
1941
+ return hasSpecifiers && node.specifiers.every((specifier) => specifier.importKind === "type");
1942
+ }
1943
+ var noRawBackendFetchRule = {
1944
+ meta: {
1945
+ type: "problem",
1946
+ docs: {
1947
+ 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.",
1948
+ category: "Best Practices",
1949
+ recommended: true
1950
+ },
1951
+ schema: [
1952
+ {
1953
+ type: "object",
1954
+ properties: {
1955
+ allow: { type: "array", items: { type: "string" } }
1956
+ },
1957
+ additionalProperties: false
1958
+ }
1959
+ ],
1960
+ messages: {
1961
+ 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.",
1962
+ 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."
1963
+ }
1964
+ },
1965
+ create(context) {
1966
+ const options = context.options[0] ?? {};
1967
+ const allow = Array.isArray(options.allow) ? options.allow : [];
1968
+ const filename = context.filename ?? context.getFilename();
1969
+ if (isExemptFile(filename, allow)) return {};
1970
+ return {
1971
+ CallExpression(node) {
1972
+ if (isFetchCallee(node.callee)) {
1973
+ if (!isDataOrBlobUrl(node.arguments[0])) context.report({ node, messageId: "rawFetch" });
1974
+ return;
1975
+ }
1976
+ const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
1977
+ if (isRequire && isAxiosSource(node.arguments[0])) context.report({ node, messageId: "rawAxios" });
1978
+ },
1979
+ ImportExpression(node) {
1980
+ if (isAxiosSource(node.source)) context.report({ node, messageId: "rawAxios" });
1981
+ },
1982
+ ImportDeclaration(node) {
1983
+ if (isAxiosSource(node.source) && !isTypeOnlyImport2(node)) context.report({ node, messageId: "rawAxios" });
1984
+ }
1985
+ };
1986
+ }
1987
+ };
1988
+ var no_raw_backend_fetch_default = {
1989
+ rules: {
1990
+ "no-raw-backend-fetch": noRawBackendFetchRule
1991
+ }
1992
+ };
1993
+
1758
1994
  // src/rules/no-raw-color-literal.js
1759
1995
  var FULL_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
1760
1996
  var FUNCTIONAL_COLOR = /\b(?:rgba?|hsla?)\s*\(/;
@@ -2147,12 +2383,12 @@ var SPEC_TYPE = "RowActionSpec";
2147
2383
  var MEMO_HOOKS = /* @__PURE__ */ new Set(["useMemo", "useCallback"]);
2148
2384
  var MAX_DEPTH = 8;
2149
2385
  var Source = Object.freeze({ LOCAL: "local", EXTERNAL: "external" });
2150
- function getScopeFor(context, node) {
2386
+ function getScopeFor2(context, node) {
2151
2387
  const sourceCode = context.sourceCode ?? context.getSourceCode();
2152
2388
  if (typeof sourceCode.getScope === "function") return sourceCode.getScope(node);
2153
2389
  return context.getScope();
2154
2390
  }
2155
- function findVariable(scope, name) {
2391
+ function findVariable2(scope, name) {
2156
2392
  let current = scope;
2157
2393
  while (current) {
2158
2394
  const found = current.set.get(name);
@@ -2224,7 +2460,7 @@ function createClassifier(context) {
2224
2460
  }
2225
2461
  const root = rootIdentifier(node.callee);
2226
2462
  if (!root) return Source.EXTERNAL;
2227
- const variable = findVariable(getScopeFor(context, node), root.name);
2463
+ const variable = findVariable2(getScopeFor2(context, node), root.name);
2228
2464
  if (!variable || variable.defs.length === 0) return Source.EXTERNAL;
2229
2465
  const def = variable.defs[0];
2230
2466
  if (def.type === "ImportBinding" || def.type === "Parameter") return Source.EXTERNAL;
@@ -2249,7 +2485,7 @@ function createClassifier(context) {
2249
2485
  case "CallExpression":
2250
2486
  return classifyCall(node, depth, seen);
2251
2487
  case "Identifier": {
2252
- const variable = findVariable(getScopeFor(context, node), node.name);
2488
+ const variable = findVariable2(getScopeFor2(context, node), node.name);
2253
2489
  return variable ? classifyVariable(variable, depth, seen) : Source.EXTERNAL;
2254
2490
  }
2255
2491
  default:
@@ -2562,6 +2798,7 @@ var ruleModules = [
2562
2798
  enforce_route_preload_default,
2563
2799
  enforce_test_colocation_default,
2564
2800
  enum_file_isolation_default,
2801
+ game_menu_focusable_default,
2565
2802
  i18n_interpolation_default,
2566
2803
  i18n_param_names_default,
2567
2804
  no_barrel_companion_file_default,
@@ -2572,6 +2809,7 @@ var ruleModules = [
2572
2809
  no_null_check_default,
2573
2810
  no_optional_undefined_default,
2574
2811
  no_product_imports_in_shared_default,
2812
+ no_raw_backend_fetch_default,
2575
2813
  no_raw_color_literal_default,
2576
2814
  prefer_const_enum_default,
2577
2815
  require_stable_hook_args_default,
@@ -2581,11 +2819,11 @@ var ruleModules = [
2581
2819
  function mergeRules(modules) {
2582
2820
  const merged = {};
2583
2821
  for (const mod of modules) {
2584
- for (const [name, rule3] of Object.entries(mod.rules)) {
2822
+ for (const [name, rule4] of Object.entries(mod.rules)) {
2585
2823
  if (merged[name] !== void 0) {
2586
2824
  throw new Error(`Duplicate ESLint rule name: "${name}"`);
2587
2825
  }
2588
- merged[name] = rule3;
2826
+ merged[name] = rule4;
2589
2827
  }
2590
2828
  }
2591
2829
  return merged;
@@ -2601,15 +2839,15 @@ var ruleNames = Object.keys(plugin.rules).sort();
2601
2839
  var legacyPlugins = buildLegacyPlugins();
2602
2840
  function buildLegacyPlugins() {
2603
2841
  const out = {};
2604
- for (const [name, rule3] of Object.entries(rules)) {
2605
- out[name] = oneRulePlugin(name, rule3);
2842
+ for (const [name, rule4] of Object.entries(rules)) {
2843
+ out[name] = oneRulePlugin(name, rule4);
2606
2844
  }
2607
2845
  return out;
2608
2846
  }
2609
- function oneRulePlugin(name, rule3) {
2847
+ function oneRulePlugin(name, rule4) {
2610
2848
  return {
2611
2849
  meta: { name, version: "1.0.0" },
2612
- rules: { [name]: rule3 }
2850
+ rules: { [name]: rule4 }
2613
2851
  };
2614
2852
  }
2615
2853
 
@@ -2635,11 +2873,25 @@ var rowActionsConfig = {
2635
2873
  "@dloizides/single-row-action-source": "error"
2636
2874
  }
2637
2875
  };
2876
+ var GAME_RULE_NAMES = ["game-menu-focusable"];
2877
+ var gameConfig = {
2878
+ plugins: commentsConfig.plugins,
2879
+ rules: {
2880
+ "@dloizides/game-menu-focusable": "error"
2881
+ }
2882
+ };
2883
+ var API_RULE_NAMES = ["no-raw-backend-fetch"];
2884
+ var apiConfig = {
2885
+ plugins: commentsConfig.plugins,
2886
+ rules: {
2887
+ "@dloizides/no-raw-backend-fetch": "error"
2888
+ }
2889
+ };
2638
2890
  var recommendedConfig = {
2639
2891
  plugins: commentsConfig.plugins,
2640
- rules: { ...commentsConfig.rules, ...rowActionsConfig.rules }
2892
+ rules: { ...commentsConfig.rules, ...rowActionsConfig.rules, ...apiConfig.rules }
2641
2893
  };
2642
2894
 
2643
- export { COMMENT_RULE_NAMES, ROW_ACTION_RULE_NAMES, commentsConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
2895
+ export { API_RULE_NAMES, COMMENT_RULE_NAMES, GAME_RULE_NAMES, ROW_ACTION_RULE_NAMES, apiConfig, commentsConfig, gameConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
2644
2896
  //# sourceMappingURL=index.mjs.map
2645
2897
  //# sourceMappingURL=index.mjs.map