@dloizides/frontend-devtools 2.4.0 → 2.5.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 +7 -0
- package/README.md +15 -0
- package/dist/eslint/index.js +22 -4
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +22 -4
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -2181,6 +2181,8 @@ var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
|
|
|
2181
2181
|
var EXEMPT_URL_SCHEME = /^\s*(?:data|blob):/i;
|
|
2182
2182
|
var ABSOLUTE_HTTP_URL = /^https?:\/\/[^/\s]+\//i;
|
|
2183
2183
|
var ABSOLUTE_HTTP_LITERAL = /^https?:\/\/[^/\s]+(?:[/?#]|$)/i;
|
|
2184
|
+
var URL_HOST = /^https?:\/\/([^/\s?#:@]+)/i;
|
|
2185
|
+
var WILDCARD_PREFIX = "*.";
|
|
2184
2186
|
var URL_OBJECTS = /* @__PURE__ */ new Set(["URL", "webkitURL"]);
|
|
2185
2187
|
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
2186
2188
|
var AXIOS_MODULE = "axios";
|
|
@@ -2217,6 +2219,19 @@ function isThirdPartyLiteralUrl(node) {
|
|
|
2217
2219
|
const head = node.quasis[0].value.cooked ?? "";
|
|
2218
2220
|
return node.expressions.length === 0 ? ABSOLUTE_HTTP_LITERAL.test(head) : ABSOLUTE_HTTP_URL.test(head);
|
|
2219
2221
|
}
|
|
2222
|
+
function literalUrlHost(node) {
|
|
2223
|
+
const match = URL_HOST.exec(leadingText(node));
|
|
2224
|
+
return match === null ? "" : match[1].toLowerCase();
|
|
2225
|
+
}
|
|
2226
|
+
function hostMatches(host, pattern) {
|
|
2227
|
+
const wanted = pattern.toLowerCase();
|
|
2228
|
+
if (!wanted.startsWith(WILDCARD_PREFIX)) return host === wanted;
|
|
2229
|
+
return host.endsWith(wanted.slice(1));
|
|
2230
|
+
}
|
|
2231
|
+
function isBackendHostUrl(node, backendHosts) {
|
|
2232
|
+
const host = literalUrlHost(node);
|
|
2233
|
+
return host !== "" && backendHosts.some((pattern) => hostMatches(host, pattern));
|
|
2234
|
+
}
|
|
2220
2235
|
function unwrapExpression(node) {
|
|
2221
2236
|
let current = node;
|
|
2222
2237
|
while (current !== void 0 && current !== null && ["TSAsExpression", "TSNonNullExpression", "TSTypeAssertion", "TSSatisfiesExpression"].includes(current.type))
|
|
@@ -2268,9 +2283,10 @@ function scopeOf(context, node) {
|
|
|
2268
2283
|
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
2269
2284
|
return typeof sourceCode.getScope === "function" ? sourceCode.getScope(node) : context.getScope();
|
|
2270
2285
|
}
|
|
2271
|
-
function isExemptFetchTarget(context, node) {
|
|
2286
|
+
function isExemptFetchTarget(context, node, backendHosts) {
|
|
2272
2287
|
const target = node.arguments[0];
|
|
2273
|
-
if (isDataOrBlobUrl(target)
|
|
2288
|
+
if (isDataOrBlobUrl(target)) return true;
|
|
2289
|
+
if (isThirdPartyLiteralUrl(target)) return !isBackendHostUrl(target, backendHosts);
|
|
2274
2290
|
return isLocalObjectUrl(target, scopeOf(context, node));
|
|
2275
2291
|
}
|
|
2276
2292
|
function isAxiosSource(node) {
|
|
@@ -2293,7 +2309,8 @@ var noRawBackendFetchRule = {
|
|
|
2293
2309
|
{
|
|
2294
2310
|
type: "object",
|
|
2295
2311
|
properties: {
|
|
2296
|
-
allow: { type: "array", items: { type: "string" } }
|
|
2312
|
+
allow: { type: "array", items: { type: "string" } },
|
|
2313
|
+
backendHosts: { type: "array", items: { type: "string" } }
|
|
2297
2314
|
},
|
|
2298
2315
|
additionalProperties: false
|
|
2299
2316
|
}
|
|
@@ -2306,6 +2323,7 @@ var noRawBackendFetchRule = {
|
|
|
2306
2323
|
create(context) {
|
|
2307
2324
|
const options = context.options[0] ?? {};
|
|
2308
2325
|
const allow = Array.isArray(options.allow) ? options.allow : [];
|
|
2326
|
+
const backendHosts = Array.isArray(options.backendHosts) ? options.backendHosts : [];
|
|
2309
2327
|
const filename = context.filename ?? context.getFilename();
|
|
2310
2328
|
if (isExemptFile(filename, allow)) return {};
|
|
2311
2329
|
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
@@ -2313,7 +2331,7 @@ var noRawBackendFetchRule = {
|
|
|
2313
2331
|
return {
|
|
2314
2332
|
CallExpression(node) {
|
|
2315
2333
|
if (isFetchCallee(node.callee)) {
|
|
2316
|
-
if (!isExemptFetchTarget(context, node)) context.report({ node, messageId: "rawFetch" });
|
|
2334
|
+
if (!isExemptFetchTarget(context, node, backendHosts)) context.report({ node, messageId: "rawFetch" });
|
|
2317
2335
|
return;
|
|
2318
2336
|
}
|
|
2319
2337
|
const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
|