@dloizides/frontend-devtools 1.8.0 → 1.10.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,26 @@ 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.10.0] - 2026-10-19
9
+
10
+ PATTERN-1.12 "TS rule packs + house rules in frontend-devtools" (D-PAT-12 "Whole rule packs as warnings, one shared approach").
11
+
12
+ ### Added
13
+ - `patternPacksConfig`: the recommended rules of `@tanstack/eslint-plugin-query`, `eslint-plugin-react-you-might-not-need-an-effect`, `eslint-plugin-boundaries` and `eslint-plugin-sonarjs`, every rule at `warn`, plus the house rules.
14
+ - `query-key-factory` (PAT-QUERY-KEY-1 "queryKey only from a key factory"): flags an inline array/string/template `queryKey`; key-factory files (`*Keys.ts`), tests and generated code are exempt; `allow` adds path fragments.
15
+ - `HOUSE_PATTERN_RULE_NAMES`.
16
+
17
+ ## [1.9.0] - 2026-10-19
18
+
19
+ 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.
20
+
21
+ ### Changed
22
+ - `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`).
23
+ - `no-raw-backend-fetch` registers no visitors when the parsed AST is not an ESTree `Program` (non-JS languages under an unscoped `apiConfig`).
24
+
25
+ ### Tests
26
+ - `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/`.
27
+
8
28
  ## [1.8.0] - 2026-10-19
9
29
 
10
30
  PATTERN-1.4 "TypeScript pattern rules as ESLint rules", row PAT-API-1 "web apps call the backend through the shared client".
@@ -74,6 +74,10 @@ declare const ruleNames: readonly string[];
74
74
  */
75
75
  declare const legacyPlugins: Record<string, FlatConfigPlugin>;
76
76
 
77
+ declare const HOUSE_PATTERN_RULE_NAMES: readonly string[];
78
+ /** D-PAT-12 preset: four community rule packs plus the house pattern rules, every rule at warn. */
79
+ declare const patternPacksConfig: FlatConfig;
80
+
77
81
  declare const COMMENT_RULE_NAMES: readonly string[];
78
82
  /** Flat-config block for COMMENTS-1: no code comments, short doc comments on public members only. */
79
83
  declare const commentsConfig: FlatConfig;
@@ -89,4 +93,4 @@ declare const apiConfig: FlatConfig;
89
93
  /** The recommended flat-config block: every rule the pack enables by default, at error. */
90
94
  declare const recommendedConfig: FlatConfig;
91
95
 
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 };
96
+ export { API_RULE_NAMES, COMMENT_RULE_NAMES, type CustomRule, type FlatConfig, type FlatConfigPlugin, GAME_RULE_NAMES, HOUSE_PATTERN_RULE_NAMES, ROW_ACTION_RULE_NAMES, type SingleRulePlugin, apiConfig, commentsConfig, gameConfig, legacyPlugins, patternPacksConfig, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
@@ -74,6 +74,10 @@ declare const ruleNames: readonly string[];
74
74
  */
75
75
  declare const legacyPlugins: Record<string, FlatConfigPlugin>;
76
76
 
77
+ declare const HOUSE_PATTERN_RULE_NAMES: readonly string[];
78
+ /** D-PAT-12 preset: four community rule packs plus the house pattern rules, every rule at warn. */
79
+ declare const patternPacksConfig: FlatConfig;
80
+
77
81
  declare const COMMENT_RULE_NAMES: readonly string[];
78
82
  /** Flat-config block for COMMENTS-1: no code comments, short doc comments on public members only. */
79
83
  declare const commentsConfig: FlatConfig;
@@ -89,4 +93,4 @@ declare const apiConfig: FlatConfig;
89
93
  /** The recommended flat-config block: every rule the pack enables by default, at error. */
90
94
  declare const recommendedConfig: FlatConfig;
91
95
 
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 };
96
+ export { API_RULE_NAMES, COMMENT_RULE_NAMES, type CustomRule, type FlatConfig, type FlatConfigPlugin, GAME_RULE_NAMES, HOUSE_PATTERN_RULE_NAMES, ROW_ACTION_RULE_NAMES, type SingleRulePlugin, apiConfig, commentsConfig, gameConfig, legacyPlugins, patternPacksConfig, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
@@ -2,11 +2,19 @@
2
2
 
3
3
  var fs = require('fs');
4
4
  var path = require('path');
5
+ var tanstackQueryPlugin = require('@tanstack/eslint-plugin-query');
6
+ var boundariesPlugin = require('eslint-plugin-boundaries');
7
+ var effectPlugin = require('eslint-plugin-react-you-might-not-need-an-effect');
8
+ var sonarjsPlugin = require('eslint-plugin-sonarjs');
5
9
 
6
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
11
 
8
12
  var fs__default = /*#__PURE__*/_interopDefault(fs);
9
13
  var path__default = /*#__PURE__*/_interopDefault(path);
14
+ var tanstackQueryPlugin__default = /*#__PURE__*/_interopDefault(tanstackQueryPlugin);
15
+ var boundariesPlugin__default = /*#__PURE__*/_interopDefault(boundariesPlugin);
16
+ var effectPlugin__default = /*#__PURE__*/_interopDefault(effectPlugin);
17
+ var sonarjsPlugin__default = /*#__PURE__*/_interopDefault(sonarjsPlugin);
10
18
 
11
19
  // src/rules/comment-utils.js
12
20
  var DIRECTIVE_PATTERNS = [
@@ -1911,6 +1919,9 @@ var DEFAULT_ALLOWED_PATH_FRAGMENTS = [
1911
1919
  var CLIENT_PACKAGE_PATH = /\/packages\/[^/]+-client\//;
1912
1920
  var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
1913
1921
  var EXEMPT_URL_SCHEME = /^\s*(?:data|blob):/i;
1922
+ var ABSOLUTE_HTTP_URL = /^https?:\/\/[^/\s]+\//i;
1923
+ var ABSOLUTE_HTTP_LITERAL = /^https?:\/\/[^/\s]+(?:[/?#]|$)/i;
1924
+ var URL_OBJECTS = /* @__PURE__ */ new Set(["URL", "webkitURL"]);
1914
1925
  var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
1915
1926
  var AXIOS_MODULE = "axios";
1916
1927
  function normalisePath(filename) {
@@ -1939,6 +1950,69 @@ function leadingText(node) {
1939
1950
  function isDataOrBlobUrl(node) {
1940
1951
  return EXEMPT_URL_SCHEME.test(leadingText(node));
1941
1952
  }
1953
+ function isThirdPartyLiteralUrl(node) {
1954
+ if (node === void 0) return false;
1955
+ if (node.type === "Literal") return typeof node.value === "string" && ABSOLUTE_HTTP_LITERAL.test(node.value);
1956
+ if (node.type !== "TemplateLiteral") return false;
1957
+ const head = node.quasis[0].value.cooked ?? "";
1958
+ return node.expressions.length === 0 ? ABSOLUTE_HTTP_LITERAL.test(head) : ABSOLUTE_HTTP_URL.test(head);
1959
+ }
1960
+ function unwrapExpression(node) {
1961
+ let current = node;
1962
+ while (current !== void 0 && current !== null && ["TSAsExpression", "TSNonNullExpression", "TSTypeAssertion", "TSSatisfiesExpression"].includes(current.type))
1963
+ current = current.expression;
1964
+ return current;
1965
+ }
1966
+ function memberName(node) {
1967
+ return node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" ? node.property.name : "";
1968
+ }
1969
+ function isUrlObject(node) {
1970
+ if (node.type === "Identifier") return URL_OBJECTS.has(node.name);
1971
+ return memberName(node) !== "" && URL_OBJECTS.has(memberName(node)) && node.object.type === "Identifier" && GLOBAL_OBJECTS.has(node.object.name);
1972
+ }
1973
+ function isCreateObjectUrlCall(node) {
1974
+ if (node === void 0 || node === null || node.type !== "CallExpression") return false;
1975
+ return memberName(node.callee) === "createObjectURL" && isUrlObject(node.callee.object);
1976
+ }
1977
+ function constInitOf(identifier, scope) {
1978
+ let current = scope;
1979
+ while (current !== null) {
1980
+ const variable = current.set.get(identifier.name);
1981
+ if (variable !== void 0) {
1982
+ const def = variable.defs.length === 1 ? variable.defs[0] : void 0;
1983
+ const isConst = def !== void 0 && def.type === "Variable" && def.parent.kind === "const";
1984
+ return isConst ? unwrapExpression(def.node.init) : void 0;
1985
+ }
1986
+ current = current.upper;
1987
+ }
1988
+ return void 0;
1989
+ }
1990
+ function isNewFileReader(node) {
1991
+ return node !== void 0 && node !== null && node.type === "NewExpression" && node.callee.type === "Identifier" && node.callee.name === "FileReader";
1992
+ }
1993
+ function isFileReaderResult(node, scope) {
1994
+ if (node === void 0 || node === null || memberName(node) !== "result") return false;
1995
+ const object = unwrapExpression(node.object);
1996
+ if (isNewFileReader(object)) return true;
1997
+ return object.type === "Identifier" && isNewFileReader(constInitOf(object, scope));
1998
+ }
1999
+ function isLocalObjectUrl(node, scope) {
2000
+ const target = unwrapExpression(node);
2001
+ if (target === void 0 || target === null) return false;
2002
+ if (isCreateObjectUrlCall(target) || isFileReaderResult(target, scope)) return true;
2003
+ if (target.type !== "Identifier") return false;
2004
+ const init = constInitOf(target, scope);
2005
+ return isCreateObjectUrlCall(init) || isFileReaderResult(init, scope);
2006
+ }
2007
+ function scopeOf(context, node) {
2008
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
2009
+ return typeof sourceCode.getScope === "function" ? sourceCode.getScope(node) : context.getScope();
2010
+ }
2011
+ function isExemptFetchTarget(context, node) {
2012
+ const target = node.arguments[0];
2013
+ if (isDataOrBlobUrl(target) || isThirdPartyLiteralUrl(target)) return true;
2014
+ return isLocalObjectUrl(target, scopeOf(context, node));
2015
+ }
1942
2016
  function isAxiosSource(node) {
1943
2017
  return node !== void 0 && node.type === "Literal" && node.value === AXIOS_MODULE;
1944
2018
  }
@@ -1974,10 +2048,12 @@ var noRawBackendFetchRule = {
1974
2048
  const allow = Array.isArray(options.allow) ? options.allow : [];
1975
2049
  const filename = context.filename ?? context.getFilename();
1976
2050
  if (isExemptFile(filename, allow)) return {};
2051
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
2052
+ if (sourceCode.ast === void 0 || sourceCode.ast.type !== "Program") return {};
1977
2053
  return {
1978
2054
  CallExpression(node) {
1979
2055
  if (isFetchCallee(node.callee)) {
1980
- if (!isDataOrBlobUrl(node.arguments[0])) context.report({ node, messageId: "rawFetch" });
2056
+ if (!isExemptFetchTarget(context, node)) context.report({ node, messageId: "rawFetch" });
1981
2057
  return;
1982
2058
  }
1983
2059
  const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
@@ -2105,8 +2181,8 @@ var preferConstEnumRule = {
2105
2181
  const exportPrefix = isExported ? "export " : "";
2106
2182
  const enumMembers = types.map((member) => {
2107
2183
  const value = member.literal.value;
2108
- const memberName = toPascalCase(value);
2109
- return ` ${memberName} = '${value}',`;
2184
+ const memberName2 = toPascalCase(value);
2185
+ return ` ${memberName2} = '${value}',`;
2110
2186
  }).join("\n");
2111
2187
  const replacement = `${exportPrefix}const enum ${typeName} {
2112
2188
  ${enumMembers}
@@ -2136,6 +2212,65 @@ var prefer_const_enum_default = {
2136
2212
  }
2137
2213
  };
2138
2214
 
2215
+ // src/rules/query-key-factory.js
2216
+ var QUERY_KEY = "queryKey";
2217
+ var TEST_FILE2 = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
2218
+ var FACTORY_FILE = /[kK]eys?(?:Factory)?\.[cm]?[jt]sx?$/;
2219
+ var DEFAULT_ALLOWED_PATH_FRAGMENTS2 = ["/generated/", "/autoGeneratedHooks/"];
2220
+ var INLINE_KEY_TYPES = /* @__PURE__ */ new Set(["ArrayExpression", "Literal", "TemplateLiteral"]);
2221
+ var TYPE_WRAPPERS = /* @__PURE__ */ new Set(["TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression"]);
2222
+ function normalisePath2(filename) {
2223
+ return typeof filename === "string" ? filename.split("\\").join("/") : "";
2224
+ }
2225
+ function isExemptFile2(filename, allow) {
2226
+ const path2 = normalisePath2(filename);
2227
+ if (TEST_FILE2.test(path2)) return true;
2228
+ if (FACTORY_FILE.test(path2)) return true;
2229
+ return [...DEFAULT_ALLOWED_PATH_FRAGMENTS2, ...allow].some((fragment) => path2.includes(fragment));
2230
+ }
2231
+ function unwrap2(node) {
2232
+ let current = node;
2233
+ while (current && TYPE_WRAPPERS.has(current.type)) current = current.expression;
2234
+ return current;
2235
+ }
2236
+ function isQueryKeyProperty(node) {
2237
+ if (node.computed) return false;
2238
+ if (node.key.type === "Identifier") return node.key.name === QUERY_KEY;
2239
+ return node.key.type === "Literal" && node.key.value === QUERY_KEY;
2240
+ }
2241
+ var rule4 = {
2242
+ meta: {
2243
+ type: "suggestion",
2244
+ docs: {
2245
+ description: "PAT-QUERY-KEY-1: a React Query queryKey comes from a key factory, never an inline literal."
2246
+ },
2247
+ schema: [
2248
+ {
2249
+ type: "object",
2250
+ properties: { allow: { type: "array", items: { type: "string" } } },
2251
+ additionalProperties: false
2252
+ }
2253
+ ],
2254
+ messages: {
2255
+ inlineKey: "Inline queryKey literal. Build it with a key factory (e.g. clientKeys.detail(id) from clientKeys.ts) so the query and its invalidation share one key."
2256
+ }
2257
+ },
2258
+ create(context) {
2259
+ const options = context.options[0] ?? {};
2260
+ const allow = Array.isArray(options.allow) ? options.allow : [];
2261
+ const filename = context.filename ?? context.getFilename();
2262
+ if (isExemptFile2(filename, allow)) return {};
2263
+ return {
2264
+ Property(node) {
2265
+ if (!isQueryKeyProperty(node)) return;
2266
+ const value = unwrap2(node.value);
2267
+ if (value && INLINE_KEY_TYPES.has(value.type)) context.report({ node: node.value, messageId: "inlineKey" });
2268
+ }
2269
+ };
2270
+ }
2271
+ };
2272
+ var query_key_factory_default = { rules: { "query-key-factory": rule4 } };
2273
+
2139
2274
  // src/rules/require-stable-hook-args.js
2140
2275
  var STABLE_INIT_CALLS = /* @__PURE__ */ new Set([
2141
2276
  "useCallback",
@@ -2819,6 +2954,7 @@ var ruleModules = [
2819
2954
  no_raw_backend_fetch_default,
2820
2955
  no_raw_color_literal_default,
2821
2956
  prefer_const_enum_default,
2957
+ query_key_factory_default,
2822
2958
  require_stable_hook_args_default,
2823
2959
  single_row_action_source_default,
2824
2960
  smart_max_lines_default
@@ -2826,11 +2962,11 @@ var ruleModules = [
2826
2962
  function mergeRules(modules) {
2827
2963
  const merged = {};
2828
2964
  for (const mod of modules) {
2829
- for (const [name, rule4] of Object.entries(mod.rules)) {
2965
+ for (const [name, rule5] of Object.entries(mod.rules)) {
2830
2966
  if (merged[name] !== void 0) {
2831
2967
  throw new Error(`Duplicate ESLint rule name: "${name}"`);
2832
2968
  }
2833
- merged[name] = rule4;
2969
+ merged[name] = rule5;
2834
2970
  }
2835
2971
  }
2836
2972
  return merged;
@@ -2846,17 +2982,58 @@ var ruleNames = Object.keys(plugin.rules).sort();
2846
2982
  var legacyPlugins = buildLegacyPlugins();
2847
2983
  function buildLegacyPlugins() {
2848
2984
  const out = {};
2849
- for (const [name, rule4] of Object.entries(rules)) {
2850
- out[name] = oneRulePlugin(name, rule4);
2985
+ for (const [name, rule5] of Object.entries(rules)) {
2986
+ out[name] = oneRulePlugin(name, rule5);
2851
2987
  }
2852
2988
  return out;
2853
2989
  }
2854
- function oneRulePlugin(name, rule4) {
2990
+ function oneRulePlugin(name, rule5) {
2855
2991
  return {
2856
2992
  meta: { name, version: "1.0.0" },
2857
- rules: { [name]: rule4 }
2993
+ rules: { [name]: rule5 }
2858
2994
  };
2859
2995
  }
2996
+ var OFF_LEVELS = ["off", 0];
2997
+ function pluginOf(mod) {
2998
+ const candidate = mod;
2999
+ const inner = candidate.default;
3000
+ return inner?.rules !== void 0 ? inner : candidate;
3001
+ }
3002
+ function rulesOf(config) {
3003
+ const blocks = Array.isArray(config) ? config : [config ?? {}];
3004
+ return Object.assign({}, ...blocks.map((block) => block.rules ?? {}));
3005
+ }
3006
+ function toWarn(entry) {
3007
+ const level = Array.isArray(entry) ? entry[0] : entry;
3008
+ if (OFF_LEVELS.includes(level)) {
3009
+ return entry;
3010
+ }
3011
+ return Array.isArray(entry) ? ["warn", ...entry.slice(1)] : "warn";
3012
+ }
3013
+ function warnAll(rules2) {
3014
+ return Object.fromEntries(Object.entries(rules2).map(([name, entry]) => [name, toWarn(entry)]));
3015
+ }
3016
+ var tanstackQuery = pluginOf(tanstackQueryPlugin__default.default);
3017
+ var effect = pluginOf(effectPlugin__default.default);
3018
+ var boundaries = pluginOf(boundariesPlugin__default.default);
3019
+ var sonarjs = pluginOf(sonarjsPlugin__default.default);
3020
+ var HOUSE_PATTERN_RULE_NAMES = ["query-key-factory"];
3021
+ var patternPacksConfig = {
3022
+ plugins: {
3023
+ "@tanstack/query": tanstackQuery,
3024
+ "react-you-might-not-need-an-effect": effect,
3025
+ boundaries,
3026
+ sonarjs,
3027
+ "@dloizides": plugin
3028
+ },
3029
+ rules: warnAll({
3030
+ ...rulesOf(tanstackQuery.configs?.["flat/recommended"]),
3031
+ ...rulesOf(effect.configs?.recommended),
3032
+ ...rulesOf(boundaries.configs?.recommended),
3033
+ ...rulesOf(sonarjs.configs?.recommended),
3034
+ "@dloizides/query-key-factory": "warn"
3035
+ })
3036
+ };
2860
3037
 
2861
3038
  // src/eslint/configs.ts
2862
3039
  var DOC_COMMENT_MAX_LINES = 3;
@@ -2902,11 +3079,13 @@ var recommendedConfig = {
2902
3079
  exports.API_RULE_NAMES = API_RULE_NAMES;
2903
3080
  exports.COMMENT_RULE_NAMES = COMMENT_RULE_NAMES;
2904
3081
  exports.GAME_RULE_NAMES = GAME_RULE_NAMES;
3082
+ exports.HOUSE_PATTERN_RULE_NAMES = HOUSE_PATTERN_RULE_NAMES;
2905
3083
  exports.ROW_ACTION_RULE_NAMES = ROW_ACTION_RULE_NAMES;
2906
3084
  exports.apiConfig = apiConfig;
2907
3085
  exports.commentsConfig = commentsConfig;
2908
3086
  exports.gameConfig = gameConfig;
2909
3087
  exports.legacyPlugins = legacyPlugins;
3088
+ exports.patternPacksConfig = patternPacksConfig;
2910
3089
  exports.plugin = plugin;
2911
3090
  exports.recommendedConfig = recommendedConfig;
2912
3091
  exports.rowActionsConfig = rowActionsConfig;