@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.
@@ -1904,6 +1904,9 @@ var DEFAULT_ALLOWED_PATH_FRAGMENTS = [
1904
1904
  var CLIENT_PACKAGE_PATH = /\/packages\/[^/]+-client\//;
1905
1905
  var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
1906
1906
  var EXEMPT_URL_SCHEME = /^\s*(?:data|blob):/i;
1907
+ var ABSOLUTE_HTTP_URL = /^https?:\/\/[^/\s]+\//i;
1908
+ var ABSOLUTE_HTTP_LITERAL = /^https?:\/\/[^/\s]+(?:[/?#]|$)/i;
1909
+ var URL_OBJECTS = /* @__PURE__ */ new Set(["URL", "webkitURL"]);
1907
1910
  var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
1908
1911
  var AXIOS_MODULE = "axios";
1909
1912
  function normalisePath(filename) {
@@ -1932,6 +1935,69 @@ function leadingText(node) {
1932
1935
  function isDataOrBlobUrl(node) {
1933
1936
  return EXEMPT_URL_SCHEME.test(leadingText(node));
1934
1937
  }
1938
+ function isThirdPartyLiteralUrl(node) {
1939
+ if (node === void 0) return false;
1940
+ if (node.type === "Literal") return typeof node.value === "string" && ABSOLUTE_HTTP_LITERAL.test(node.value);
1941
+ if (node.type !== "TemplateLiteral") return false;
1942
+ const head = node.quasis[0].value.cooked ?? "";
1943
+ return node.expressions.length === 0 ? ABSOLUTE_HTTP_LITERAL.test(head) : ABSOLUTE_HTTP_URL.test(head);
1944
+ }
1945
+ function unwrapExpression(node) {
1946
+ let current = node;
1947
+ while (current !== void 0 && current !== null && ["TSAsExpression", "TSNonNullExpression", "TSTypeAssertion", "TSSatisfiesExpression"].includes(current.type))
1948
+ current = current.expression;
1949
+ return current;
1950
+ }
1951
+ function memberName(node) {
1952
+ return node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" ? node.property.name : "";
1953
+ }
1954
+ function isUrlObject(node) {
1955
+ if (node.type === "Identifier") return URL_OBJECTS.has(node.name);
1956
+ return memberName(node) !== "" && URL_OBJECTS.has(memberName(node)) && node.object.type === "Identifier" && GLOBAL_OBJECTS.has(node.object.name);
1957
+ }
1958
+ function isCreateObjectUrlCall(node) {
1959
+ if (node === void 0 || node === null || node.type !== "CallExpression") return false;
1960
+ return memberName(node.callee) === "createObjectURL" && isUrlObject(node.callee.object);
1961
+ }
1962
+ function constInitOf(identifier, scope) {
1963
+ let current = scope;
1964
+ while (current !== null) {
1965
+ const variable = current.set.get(identifier.name);
1966
+ if (variable !== void 0) {
1967
+ const def = variable.defs.length === 1 ? variable.defs[0] : void 0;
1968
+ const isConst = def !== void 0 && def.type === "Variable" && def.parent.kind === "const";
1969
+ return isConst ? unwrapExpression(def.node.init) : void 0;
1970
+ }
1971
+ current = current.upper;
1972
+ }
1973
+ return void 0;
1974
+ }
1975
+ function isNewFileReader(node) {
1976
+ return node !== void 0 && node !== null && node.type === "NewExpression" && node.callee.type === "Identifier" && node.callee.name === "FileReader";
1977
+ }
1978
+ function isFileReaderResult(node, scope) {
1979
+ if (node === void 0 || node === null || memberName(node) !== "result") return false;
1980
+ const object = unwrapExpression(node.object);
1981
+ if (isNewFileReader(object)) return true;
1982
+ return object.type === "Identifier" && isNewFileReader(constInitOf(object, scope));
1983
+ }
1984
+ function isLocalObjectUrl(node, scope) {
1985
+ const target = unwrapExpression(node);
1986
+ if (target === void 0 || target === null) return false;
1987
+ if (isCreateObjectUrlCall(target) || isFileReaderResult(target, scope)) return true;
1988
+ if (target.type !== "Identifier") return false;
1989
+ const init = constInitOf(target, scope);
1990
+ return isCreateObjectUrlCall(init) || isFileReaderResult(init, scope);
1991
+ }
1992
+ function scopeOf(context, node) {
1993
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
1994
+ return typeof sourceCode.getScope === "function" ? sourceCode.getScope(node) : context.getScope();
1995
+ }
1996
+ function isExemptFetchTarget(context, node) {
1997
+ const target = node.arguments[0];
1998
+ if (isDataOrBlobUrl(target) || isThirdPartyLiteralUrl(target)) return true;
1999
+ return isLocalObjectUrl(target, scopeOf(context, node));
2000
+ }
1935
2001
  function isAxiosSource(node) {
1936
2002
  return node !== void 0 && node.type === "Literal" && node.value === AXIOS_MODULE;
1937
2003
  }
@@ -1967,10 +2033,12 @@ var noRawBackendFetchRule = {
1967
2033
  const allow = Array.isArray(options.allow) ? options.allow : [];
1968
2034
  const filename = context.filename ?? context.getFilename();
1969
2035
  if (isExemptFile(filename, allow)) return {};
2036
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
2037
+ if (sourceCode.ast === void 0 || sourceCode.ast.type !== "Program") return {};
1970
2038
  return {
1971
2039
  CallExpression(node) {
1972
2040
  if (isFetchCallee(node.callee)) {
1973
- if (!isDataOrBlobUrl(node.arguments[0])) context.report({ node, messageId: "rawFetch" });
2041
+ if (!isExemptFetchTarget(context, node)) context.report({ node, messageId: "rawFetch" });
1974
2042
  return;
1975
2043
  }
1976
2044
  const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
@@ -2098,8 +2166,8 @@ var preferConstEnumRule = {
2098
2166
  const exportPrefix = isExported ? "export " : "";
2099
2167
  const enumMembers = types.map((member) => {
2100
2168
  const value = member.literal.value;
2101
- const memberName = toPascalCase(value);
2102
- return ` ${memberName} = '${value}',`;
2169
+ const memberName2 = toPascalCase(value);
2170
+ return ` ${memberName2} = '${value}',`;
2103
2171
  }).join("\n");
2104
2172
  const replacement = `${exportPrefix}const enum ${typeName} {
2105
2173
  ${enumMembers}