@dloizides/frontend-devtools 1.7.0 → 1.9.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 CHANGED
@@ -5,6 +5,28 @@ All notable changes to `@dloizides/frontend-devtools` are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.9.0] - 2026-10-19
9
+
10
+ PATTERN-1.4 "TypeScript pattern rules as ESLint rules", `no-raw-backend-fetch` (PAT-API-1 "web apps call the backend through the shared client") hardening.
11
+
12
+ ### Changed
13
+ - `no-raw-backend-fetch` no longer reports `fetch` of a literal absolute `http(s)://host/...` URL (third-party), or of a value produced by `URL.createObjectURL(...)` / `new FileReader().result` (direct, or via a single `const`).
14
+ - `no-raw-backend-fetch` registers no visitors when the parsed AST is not an ESTree `Program` (non-JS languages under an unscoped `apiConfig`).
15
+
16
+ ### Tests
17
+ - `apiConfigUnscoped.test.ts`: `apiConfig` without `files` lints `.js`/`.mjs`/`.cjs`, build output and a 2000-deep nested file without throwing, and still reports under `src/`.
18
+
19
+ ## [1.8.0] - 2026-10-19
20
+
21
+ PATTERN-1.4 "TypeScript pattern rules as ESLint rules", row PAT-API-1 "web apps call the backend through the shared client".
22
+
23
+ ### Added
24
+
25
+ - `no-raw-backend-fetch`: reports `fetch(` / `window.fetch(` / `globalThis.fetch(` / `self.fetch(` and value imports of `axios`
26
+ (`import`, `require`, `import()`) in `src/**`. Exempt: `src/server/`, `src/http/`, `src/lib/http/`, `packages/*-client/`,
27
+ `/generated/`, service worker files, `app/+html.*`, tests, `data:`/`blob:` URLs, `import type` from axios. Option `{ allow: string[] }`.
28
+ - `apiConfig` flat-config preset (`API_RULE_NAMES`) at `error`; included in `recommendedConfig`.
29
+
8
30
  ## [1.7.0] - 2026-10-19
9
31
 
10
32
  NAV-1 "Every game menu works with arrow keys and controller", phase 3.
@@ -83,7 +83,10 @@ declare const rowActionsConfig: FlatConfig;
83
83
  declare const GAME_RULE_NAMES: readonly string[];
84
84
  /** The game preset: menus stay walkable with arrow keys and a controller (NAV-1). Game repos only. */
85
85
  declare const gameConfig: FlatConfig;
86
+ declare const API_RULE_NAMES: readonly string[];
87
+ /** PAT-API-1: the backend is called through the shared client or generated hooks, never raw fetch/axios. */
88
+ declare const apiConfig: FlatConfig;
86
89
  /** The recommended flat-config block: every rule the pack enables by default, at error. */
87
90
  declare const recommendedConfig: FlatConfig;
88
91
 
89
- export { COMMENT_RULE_NAMES, type CustomRule, type FlatConfig, type FlatConfigPlugin, GAME_RULE_NAMES, ROW_ACTION_RULE_NAMES, type SingleRulePlugin, commentsConfig, gameConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
92
+ export { API_RULE_NAMES, COMMENT_RULE_NAMES, type CustomRule, type FlatConfig, type FlatConfigPlugin, GAME_RULE_NAMES, ROW_ACTION_RULE_NAMES, type SingleRulePlugin, apiConfig, commentsConfig, gameConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
@@ -83,7 +83,10 @@ declare const rowActionsConfig: FlatConfig;
83
83
  declare const GAME_RULE_NAMES: readonly string[];
84
84
  /** The game preset: menus stay walkable with arrow keys and a controller (NAV-1). Game repos only. */
85
85
  declare const gameConfig: FlatConfig;
86
+ declare const API_RULE_NAMES: readonly string[];
87
+ /** PAT-API-1: the backend is called through the shared client or generated hooks, never raw fetch/axios. */
88
+ declare const apiConfig: FlatConfig;
86
89
  /** The recommended flat-config block: every rule the pack enables by default, at error. */
87
90
  declare const recommendedConfig: FlatConfig;
88
91
 
89
- export { COMMENT_RULE_NAMES, type CustomRule, type FlatConfig, type FlatConfigPlugin, GAME_RULE_NAMES, ROW_ACTION_RULE_NAMES, type SingleRulePlugin, commentsConfig, gameConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
92
+ export { API_RULE_NAMES, COMMENT_RULE_NAMES, type CustomRule, type FlatConfig, type FlatConfigPlugin, GAME_RULE_NAMES, ROW_ACTION_RULE_NAMES, type SingleRulePlugin, apiConfig, commentsConfig, gameConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
@@ -1897,6 +1897,175 @@ var no_product_imports_in_shared_default = {
1897
1897
  }
1898
1898
  };
1899
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 ABSOLUTE_HTTP_URL = /^https?:\/\/[^/\s]+\//i;
1915
+ var ABSOLUTE_HTTP_LITERAL = /^https?:\/\/[^/\s]+(?:[/?#]|$)/i;
1916
+ var URL_OBJECTS = /* @__PURE__ */ new Set(["URL", "webkitURL"]);
1917
+ var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
1918
+ var AXIOS_MODULE = "axios";
1919
+ function normalisePath(filename) {
1920
+ return typeof filename === "string" ? filename.split("\\").join("/") : "";
1921
+ }
1922
+ function isExemptFile(filename, allow) {
1923
+ const path2 = normalisePath(filename);
1924
+ if (!path2.includes("/src/")) return true;
1925
+ if (TEST_FILE.test(path2)) return true;
1926
+ if (CLIENT_PACKAGE_PATH.test(path2)) return true;
1927
+ return [...DEFAULT_ALLOWED_PATH_FRAGMENTS, ...allow].some((fragment) => path2.includes(fragment));
1928
+ }
1929
+ function isFetchCallee(callee) {
1930
+ if (callee.type === "Identifier") return callee.name === "fetch";
1931
+ if (callee.type !== "MemberExpression" || callee.computed) return false;
1932
+ const isFetchProperty = callee.property.type === "Identifier" && callee.property.name === "fetch";
1933
+ const isGlobalObject = callee.object.type === "Identifier" && GLOBAL_OBJECTS.has(callee.object.name);
1934
+ return isFetchProperty && isGlobalObject;
1935
+ }
1936
+ function leadingText(node) {
1937
+ if (node === void 0) return "";
1938
+ if (node.type === "Literal" && typeof node.value === "string") return node.value;
1939
+ if (node.type === "TemplateLiteral") return node.quasis[0].value.cooked ?? "";
1940
+ return "";
1941
+ }
1942
+ function isDataOrBlobUrl(node) {
1943
+ return EXEMPT_URL_SCHEME.test(leadingText(node));
1944
+ }
1945
+ function isThirdPartyLiteralUrl(node) {
1946
+ if (node === void 0) return false;
1947
+ if (node.type === "Literal") return typeof node.value === "string" && ABSOLUTE_HTTP_LITERAL.test(node.value);
1948
+ if (node.type !== "TemplateLiteral") return false;
1949
+ const head = node.quasis[0].value.cooked ?? "";
1950
+ return node.expressions.length === 0 ? ABSOLUTE_HTTP_LITERAL.test(head) : ABSOLUTE_HTTP_URL.test(head);
1951
+ }
1952
+ function unwrapExpression(node) {
1953
+ let current = node;
1954
+ while (current !== void 0 && current !== null && ["TSAsExpression", "TSNonNullExpression", "TSTypeAssertion", "TSSatisfiesExpression"].includes(current.type))
1955
+ current = current.expression;
1956
+ return current;
1957
+ }
1958
+ function memberName(node) {
1959
+ return node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" ? node.property.name : "";
1960
+ }
1961
+ function isUrlObject(node) {
1962
+ if (node.type === "Identifier") return URL_OBJECTS.has(node.name);
1963
+ return memberName(node) !== "" && URL_OBJECTS.has(memberName(node)) && node.object.type === "Identifier" && GLOBAL_OBJECTS.has(node.object.name);
1964
+ }
1965
+ function isCreateObjectUrlCall(node) {
1966
+ if (node === void 0 || node === null || node.type !== "CallExpression") return false;
1967
+ return memberName(node.callee) === "createObjectURL" && isUrlObject(node.callee.object);
1968
+ }
1969
+ function constInitOf(identifier, scope) {
1970
+ let current = scope;
1971
+ while (current !== null) {
1972
+ const variable = current.set.get(identifier.name);
1973
+ if (variable !== void 0) {
1974
+ const def = variable.defs.length === 1 ? variable.defs[0] : void 0;
1975
+ const isConst = def !== void 0 && def.type === "Variable" && def.parent.kind === "const";
1976
+ return isConst ? unwrapExpression(def.node.init) : void 0;
1977
+ }
1978
+ current = current.upper;
1979
+ }
1980
+ return void 0;
1981
+ }
1982
+ function isNewFileReader(node) {
1983
+ return node !== void 0 && node !== null && node.type === "NewExpression" && node.callee.type === "Identifier" && node.callee.name === "FileReader";
1984
+ }
1985
+ function isFileReaderResult(node, scope) {
1986
+ if (node === void 0 || node === null || memberName(node) !== "result") return false;
1987
+ const object = unwrapExpression(node.object);
1988
+ if (isNewFileReader(object)) return true;
1989
+ return object.type === "Identifier" && isNewFileReader(constInitOf(object, scope));
1990
+ }
1991
+ function isLocalObjectUrl(node, scope) {
1992
+ const target = unwrapExpression(node);
1993
+ if (target === void 0 || target === null) return false;
1994
+ if (isCreateObjectUrlCall(target) || isFileReaderResult(target, scope)) return true;
1995
+ if (target.type !== "Identifier") return false;
1996
+ const init = constInitOf(target, scope);
1997
+ return isCreateObjectUrlCall(init) || isFileReaderResult(init, scope);
1998
+ }
1999
+ function scopeOf(context, node) {
2000
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
2001
+ return typeof sourceCode.getScope === "function" ? sourceCode.getScope(node) : context.getScope();
2002
+ }
2003
+ function isExemptFetchTarget(context, node) {
2004
+ const target = node.arguments[0];
2005
+ if (isDataOrBlobUrl(target) || isThirdPartyLiteralUrl(target)) return true;
2006
+ return isLocalObjectUrl(target, scopeOf(context, node));
2007
+ }
2008
+ function isAxiosSource(node) {
2009
+ return node !== void 0 && node.type === "Literal" && node.value === AXIOS_MODULE;
2010
+ }
2011
+ function isTypeOnlyImport2(node) {
2012
+ if (node.importKind === "type") return true;
2013
+ const hasSpecifiers = node.specifiers.length > 0;
2014
+ return hasSpecifiers && node.specifiers.every((specifier) => specifier.importKind === "type");
2015
+ }
2016
+ var noRawBackendFetchRule = {
2017
+ meta: {
2018
+ type: "problem",
2019
+ docs: {
2020
+ 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.",
2021
+ category: "Best Practices",
2022
+ recommended: true
2023
+ },
2024
+ schema: [
2025
+ {
2026
+ type: "object",
2027
+ properties: {
2028
+ allow: { type: "array", items: { type: "string" } }
2029
+ },
2030
+ additionalProperties: false
2031
+ }
2032
+ ],
2033
+ messages: {
2034
+ 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.",
2035
+ 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."
2036
+ }
2037
+ },
2038
+ create(context) {
2039
+ const options = context.options[0] ?? {};
2040
+ const allow = Array.isArray(options.allow) ? options.allow : [];
2041
+ const filename = context.filename ?? context.getFilename();
2042
+ if (isExemptFile(filename, allow)) return {};
2043
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
2044
+ if (sourceCode.ast === void 0 || sourceCode.ast.type !== "Program") return {};
2045
+ return {
2046
+ CallExpression(node) {
2047
+ if (isFetchCallee(node.callee)) {
2048
+ if (!isExemptFetchTarget(context, node)) context.report({ node, messageId: "rawFetch" });
2049
+ return;
2050
+ }
2051
+ const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
2052
+ if (isRequire && isAxiosSource(node.arguments[0])) context.report({ node, messageId: "rawAxios" });
2053
+ },
2054
+ ImportExpression(node) {
2055
+ if (isAxiosSource(node.source)) context.report({ node, messageId: "rawAxios" });
2056
+ },
2057
+ ImportDeclaration(node) {
2058
+ if (isAxiosSource(node.source) && !isTypeOnlyImport2(node)) context.report({ node, messageId: "rawAxios" });
2059
+ }
2060
+ };
2061
+ }
2062
+ };
2063
+ var no_raw_backend_fetch_default = {
2064
+ rules: {
2065
+ "no-raw-backend-fetch": noRawBackendFetchRule
2066
+ }
2067
+ };
2068
+
1900
2069
  // src/rules/no-raw-color-literal.js
1901
2070
  var FULL_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
1902
2071
  var FUNCTIONAL_COLOR = /\b(?:rgba?|hsla?)\s*\(/;
@@ -2004,8 +2173,8 @@ var preferConstEnumRule = {
2004
2173
  const exportPrefix = isExported ? "export " : "";
2005
2174
  const enumMembers = types.map((member) => {
2006
2175
  const value = member.literal.value;
2007
- const memberName = toPascalCase(value);
2008
- return ` ${memberName} = '${value}',`;
2176
+ const memberName2 = toPascalCase(value);
2177
+ return ` ${memberName2} = '${value}',`;
2009
2178
  }).join("\n");
2010
2179
  const replacement = `${exportPrefix}const enum ${typeName} {
2011
2180
  ${enumMembers}
@@ -2715,6 +2884,7 @@ var ruleModules = [
2715
2884
  no_null_check_default,
2716
2885
  no_optional_undefined_default,
2717
2886
  no_product_imports_in_shared_default,
2887
+ no_raw_backend_fetch_default,
2718
2888
  no_raw_color_literal_default,
2719
2889
  prefer_const_enum_default,
2720
2890
  require_stable_hook_args_default,
@@ -2785,14 +2955,23 @@ var gameConfig = {
2785
2955
  "@dloizides/game-menu-focusable": "error"
2786
2956
  }
2787
2957
  };
2958
+ var API_RULE_NAMES = ["no-raw-backend-fetch"];
2959
+ var apiConfig = {
2960
+ plugins: commentsConfig.plugins,
2961
+ rules: {
2962
+ "@dloizides/no-raw-backend-fetch": "error"
2963
+ }
2964
+ };
2788
2965
  var recommendedConfig = {
2789
2966
  plugins: commentsConfig.plugins,
2790
- rules: { ...commentsConfig.rules, ...rowActionsConfig.rules }
2967
+ rules: { ...commentsConfig.rules, ...rowActionsConfig.rules, ...apiConfig.rules }
2791
2968
  };
2792
2969
 
2970
+ exports.API_RULE_NAMES = API_RULE_NAMES;
2793
2971
  exports.COMMENT_RULE_NAMES = COMMENT_RULE_NAMES;
2794
2972
  exports.GAME_RULE_NAMES = GAME_RULE_NAMES;
2795
2973
  exports.ROW_ACTION_RULE_NAMES = ROW_ACTION_RULE_NAMES;
2974
+ exports.apiConfig = apiConfig;
2796
2975
  exports.commentsConfig = commentsConfig;
2797
2976
  exports.gameConfig = gameConfig;
2798
2977
  exports.legacyPlugins = legacyPlugins;