@dloizides/frontend-devtools 1.8.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,17 @@ 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
+
8
19
  ## [1.8.0] - 2026-10-19
9
20
 
10
21
  PATTERN-1.4 "TypeScript pattern rules as ESLint rules", row PAT-API-1 "web apps call the backend through the shared client".
@@ -1911,6 +1911,9 @@ var DEFAULT_ALLOWED_PATH_FRAGMENTS = [
1911
1911
  var CLIENT_PACKAGE_PATH = /\/packages\/[^/]+-client\//;
1912
1912
  var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
1913
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"]);
1914
1917
  var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
1915
1918
  var AXIOS_MODULE = "axios";
1916
1919
  function normalisePath(filename) {
@@ -1939,6 +1942,69 @@ function leadingText(node) {
1939
1942
  function isDataOrBlobUrl(node) {
1940
1943
  return EXEMPT_URL_SCHEME.test(leadingText(node));
1941
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
+ }
1942
2008
  function isAxiosSource(node) {
1943
2009
  return node !== void 0 && node.type === "Literal" && node.value === AXIOS_MODULE;
1944
2010
  }
@@ -1974,10 +2040,12 @@ var noRawBackendFetchRule = {
1974
2040
  const allow = Array.isArray(options.allow) ? options.allow : [];
1975
2041
  const filename = context.filename ?? context.getFilename();
1976
2042
  if (isExemptFile(filename, allow)) return {};
2043
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
2044
+ if (sourceCode.ast === void 0 || sourceCode.ast.type !== "Program") return {};
1977
2045
  return {
1978
2046
  CallExpression(node) {
1979
2047
  if (isFetchCallee(node.callee)) {
1980
- if (!isDataOrBlobUrl(node.arguments[0])) context.report({ node, messageId: "rawFetch" });
2048
+ if (!isExemptFetchTarget(context, node)) context.report({ node, messageId: "rawFetch" });
1981
2049
  return;
1982
2050
  }
1983
2051
  const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
@@ -2105,8 +2173,8 @@ var preferConstEnumRule = {
2105
2173
  const exportPrefix = isExported ? "export " : "";
2106
2174
  const enumMembers = types.map((member) => {
2107
2175
  const value = member.literal.value;
2108
- const memberName = toPascalCase(value);
2109
- return ` ${memberName} = '${value}',`;
2176
+ const memberName2 = toPascalCase(value);
2177
+ return ` ${memberName2} = '${value}',`;
2110
2178
  }).join("\n");
2111
2179
  const replacement = `${exportPrefix}const enum ${typeName} {
2112
2180
  ${enumMembers}