@dloizides/frontend-devtools 1.7.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.
- package/CHANGELOG.md +11 -0
- package/dist/eslint/index.d.mts +4 -1
- package/dist/eslint/index.d.ts +4 -1
- package/dist/eslint/index.js +112 -1
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +111 -2
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -1890,6 +1890,107 @@ var no_product_imports_in_shared_default = {
|
|
|
1890
1890
|
}
|
|
1891
1891
|
};
|
|
1892
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
|
+
|
|
1893
1994
|
// src/rules/no-raw-color-literal.js
|
|
1894
1995
|
var FULL_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
1895
1996
|
var FUNCTIONAL_COLOR = /\b(?:rgba?|hsla?)\s*\(/;
|
|
@@ -2708,6 +2809,7 @@ var ruleModules = [
|
|
|
2708
2809
|
no_null_check_default,
|
|
2709
2810
|
no_optional_undefined_default,
|
|
2710
2811
|
no_product_imports_in_shared_default,
|
|
2812
|
+
no_raw_backend_fetch_default,
|
|
2711
2813
|
no_raw_color_literal_default,
|
|
2712
2814
|
prefer_const_enum_default,
|
|
2713
2815
|
require_stable_hook_args_default,
|
|
@@ -2778,11 +2880,18 @@ var gameConfig = {
|
|
|
2778
2880
|
"@dloizides/game-menu-focusable": "error"
|
|
2779
2881
|
}
|
|
2780
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
|
+
};
|
|
2781
2890
|
var recommendedConfig = {
|
|
2782
2891
|
plugins: commentsConfig.plugins,
|
|
2783
|
-
rules: { ...commentsConfig.rules, ...rowActionsConfig.rules }
|
|
2892
|
+
rules: { ...commentsConfig.rules, ...rowActionsConfig.rules, ...apiConfig.rules }
|
|
2784
2893
|
};
|
|
2785
2894
|
|
|
2786
|
-
export { COMMENT_RULE_NAMES, GAME_RULE_NAMES, ROW_ACTION_RULE_NAMES, commentsConfig, gameConfig, 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 };
|
|
2787
2896
|
//# sourceMappingURL=index.mjs.map
|
|
2788
2897
|
//# sourceMappingURL=index.mjs.map
|