@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/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.8.0] - 2026-10-19
|
|
9
|
+
|
|
10
|
+
PATTERN-1.4 "TypeScript pattern rules as ESLint rules", row PAT-API-1 "web apps call the backend through the shared client".
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `no-raw-backend-fetch`: reports `fetch(` / `window.fetch(` / `globalThis.fetch(` / `self.fetch(` and value imports of `axios`
|
|
15
|
+
(`import`, `require`, `import()`) in `src/**`. Exempt: `src/server/`, `src/http/`, `src/lib/http/`, `packages/*-client/`,
|
|
16
|
+
`/generated/`, service worker files, `app/+html.*`, tests, `data:`/`blob:` URLs, `import type` from axios. Option `{ allow: string[] }`.
|
|
17
|
+
- `apiConfig` flat-config preset (`API_RULE_NAMES`) at `error`; included in `recommendedConfig`.
|
|
18
|
+
|
|
8
19
|
## [1.7.0] - 2026-10-19
|
|
9
20
|
|
|
10
21
|
NAV-1 "Every game menu works with arrow keys and controller", phase 3.
|
package/dist/eslint/index.d.mts
CHANGED
|
@@ -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 };
|
package/dist/eslint/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist/eslint/index.js
CHANGED
|
@@ -1897,6 +1897,107 @@ 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 GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
1915
|
+
var AXIOS_MODULE = "axios";
|
|
1916
|
+
function normalisePath(filename) {
|
|
1917
|
+
return typeof filename === "string" ? filename.split("\\").join("/") : "";
|
|
1918
|
+
}
|
|
1919
|
+
function isExemptFile(filename, allow) {
|
|
1920
|
+
const path2 = normalisePath(filename);
|
|
1921
|
+
if (!path2.includes("/src/")) return true;
|
|
1922
|
+
if (TEST_FILE.test(path2)) return true;
|
|
1923
|
+
if (CLIENT_PACKAGE_PATH.test(path2)) return true;
|
|
1924
|
+
return [...DEFAULT_ALLOWED_PATH_FRAGMENTS, ...allow].some((fragment) => path2.includes(fragment));
|
|
1925
|
+
}
|
|
1926
|
+
function isFetchCallee(callee) {
|
|
1927
|
+
if (callee.type === "Identifier") return callee.name === "fetch";
|
|
1928
|
+
if (callee.type !== "MemberExpression" || callee.computed) return false;
|
|
1929
|
+
const isFetchProperty = callee.property.type === "Identifier" && callee.property.name === "fetch";
|
|
1930
|
+
const isGlobalObject = callee.object.type === "Identifier" && GLOBAL_OBJECTS.has(callee.object.name);
|
|
1931
|
+
return isFetchProperty && isGlobalObject;
|
|
1932
|
+
}
|
|
1933
|
+
function leadingText(node) {
|
|
1934
|
+
if (node === void 0) return "";
|
|
1935
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
1936
|
+
if (node.type === "TemplateLiteral") return node.quasis[0].value.cooked ?? "";
|
|
1937
|
+
return "";
|
|
1938
|
+
}
|
|
1939
|
+
function isDataOrBlobUrl(node) {
|
|
1940
|
+
return EXEMPT_URL_SCHEME.test(leadingText(node));
|
|
1941
|
+
}
|
|
1942
|
+
function isAxiosSource(node) {
|
|
1943
|
+
return node !== void 0 && node.type === "Literal" && node.value === AXIOS_MODULE;
|
|
1944
|
+
}
|
|
1945
|
+
function isTypeOnlyImport2(node) {
|
|
1946
|
+
if (node.importKind === "type") return true;
|
|
1947
|
+
const hasSpecifiers = node.specifiers.length > 0;
|
|
1948
|
+
return hasSpecifiers && node.specifiers.every((specifier) => specifier.importKind === "type");
|
|
1949
|
+
}
|
|
1950
|
+
var noRawBackendFetchRule = {
|
|
1951
|
+
meta: {
|
|
1952
|
+
type: "problem",
|
|
1953
|
+
docs: {
|
|
1954
|
+
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.",
|
|
1955
|
+
category: "Best Practices",
|
|
1956
|
+
recommended: true
|
|
1957
|
+
},
|
|
1958
|
+
schema: [
|
|
1959
|
+
{
|
|
1960
|
+
type: "object",
|
|
1961
|
+
properties: {
|
|
1962
|
+
allow: { type: "array", items: { type: "string" } }
|
|
1963
|
+
},
|
|
1964
|
+
additionalProperties: false
|
|
1965
|
+
}
|
|
1966
|
+
],
|
|
1967
|
+
messages: {
|
|
1968
|
+
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.",
|
|
1969
|
+
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."
|
|
1970
|
+
}
|
|
1971
|
+
},
|
|
1972
|
+
create(context) {
|
|
1973
|
+
const options = context.options[0] ?? {};
|
|
1974
|
+
const allow = Array.isArray(options.allow) ? options.allow : [];
|
|
1975
|
+
const filename = context.filename ?? context.getFilename();
|
|
1976
|
+
if (isExemptFile(filename, allow)) return {};
|
|
1977
|
+
return {
|
|
1978
|
+
CallExpression(node) {
|
|
1979
|
+
if (isFetchCallee(node.callee)) {
|
|
1980
|
+
if (!isDataOrBlobUrl(node.arguments[0])) context.report({ node, messageId: "rawFetch" });
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
|
|
1984
|
+
if (isRequire && isAxiosSource(node.arguments[0])) context.report({ node, messageId: "rawAxios" });
|
|
1985
|
+
},
|
|
1986
|
+
ImportExpression(node) {
|
|
1987
|
+
if (isAxiosSource(node.source)) context.report({ node, messageId: "rawAxios" });
|
|
1988
|
+
},
|
|
1989
|
+
ImportDeclaration(node) {
|
|
1990
|
+
if (isAxiosSource(node.source) && !isTypeOnlyImport2(node)) context.report({ node, messageId: "rawAxios" });
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
};
|
|
1995
|
+
var no_raw_backend_fetch_default = {
|
|
1996
|
+
rules: {
|
|
1997
|
+
"no-raw-backend-fetch": noRawBackendFetchRule
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
|
|
1900
2001
|
// src/rules/no-raw-color-literal.js
|
|
1901
2002
|
var FULL_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
1902
2003
|
var FUNCTIONAL_COLOR = /\b(?:rgba?|hsla?)\s*\(/;
|
|
@@ -2715,6 +2816,7 @@ var ruleModules = [
|
|
|
2715
2816
|
no_null_check_default,
|
|
2716
2817
|
no_optional_undefined_default,
|
|
2717
2818
|
no_product_imports_in_shared_default,
|
|
2819
|
+
no_raw_backend_fetch_default,
|
|
2718
2820
|
no_raw_color_literal_default,
|
|
2719
2821
|
prefer_const_enum_default,
|
|
2720
2822
|
require_stable_hook_args_default,
|
|
@@ -2785,14 +2887,23 @@ var gameConfig = {
|
|
|
2785
2887
|
"@dloizides/game-menu-focusable": "error"
|
|
2786
2888
|
}
|
|
2787
2889
|
};
|
|
2890
|
+
var API_RULE_NAMES = ["no-raw-backend-fetch"];
|
|
2891
|
+
var apiConfig = {
|
|
2892
|
+
plugins: commentsConfig.plugins,
|
|
2893
|
+
rules: {
|
|
2894
|
+
"@dloizides/no-raw-backend-fetch": "error"
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2788
2897
|
var recommendedConfig = {
|
|
2789
2898
|
plugins: commentsConfig.plugins,
|
|
2790
|
-
rules: { ...commentsConfig.rules, ...rowActionsConfig.rules }
|
|
2899
|
+
rules: { ...commentsConfig.rules, ...rowActionsConfig.rules, ...apiConfig.rules }
|
|
2791
2900
|
};
|
|
2792
2901
|
|
|
2902
|
+
exports.API_RULE_NAMES = API_RULE_NAMES;
|
|
2793
2903
|
exports.COMMENT_RULE_NAMES = COMMENT_RULE_NAMES;
|
|
2794
2904
|
exports.GAME_RULE_NAMES = GAME_RULE_NAMES;
|
|
2795
2905
|
exports.ROW_ACTION_RULE_NAMES = ROW_ACTION_RULE_NAMES;
|
|
2906
|
+
exports.apiConfig = apiConfig;
|
|
2796
2907
|
exports.commentsConfig = commentsConfig;
|
|
2797
2908
|
exports.gameConfig = gameConfig;
|
|
2798
2909
|
exports.legacyPlugins = legacyPlugins;
|