@dloizides/frontend-devtools 2.0.0 → 2.1.1

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.
@@ -2132,6 +2132,111 @@ var no_raw_color_literal_default = {
2132
2132
  }
2133
2133
  };
2134
2134
 
2135
+ // src/rules/reimplemented-packages-registry.js
2136
+ var REIMPLEMENTED_PACKAGE_REGISTRY = [
2137
+ {
2138
+ id: "analytics",
2139
+ package: "@dloizides/analytics-web",
2140
+ use: "createAnalytics, track, createWebVitals",
2141
+ paths: [/\/src\/lib\/analytics\//, /\/UmamiClient\.[cm]?[jt]sx?$/, /\/MultiProviderClient\.[cm]?[jt]sx?$/, /\/useWebVitalsTracking\.[cm]?[jt]sx?$/],
2142
+ literals: []
2143
+ },
2144
+ {
2145
+ id: "bff-csrf",
2146
+ package: "@dloizides/bff-web-client",
2147
+ use: "createBffAxiosClient (default CSRF interceptor)",
2148
+ paths: [/\/bffCsrf\.[cm]?[jt]sx?$/],
2149
+ literals: [/^X-BFF-Csrf$/i]
2150
+ },
2151
+ {
2152
+ id: "forgot-password",
2153
+ package: "@dloizides/auth-web",
2154
+ use: "useBffForgotPassword, ForgotPasswordForm",
2155
+ paths: [/\/forgotPasswordRequest\.[cm]?[jt]sx?$/],
2156
+ literals: []
2157
+ },
2158
+ {
2159
+ id: "logger",
2160
+ package: "@dloizides/logging-web",
2161
+ use: "logger, LoggingService",
2162
+ paths: [/\/src\/(?:lib\/)?utils\/logger\.[cm]?[jt]sx?$/],
2163
+ literals: []
2164
+ }
2165
+ ];
2166
+
2167
+ // src/rules/no-reimplemented-package.js
2168
+ var TEST_FILE2 = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)|(?:\/e2e\/)/;
2169
+ var SHARED_SOURCE = /\/(?:NpmPackages\/packages|node_modules)\//;
2170
+ function normalisePath2(filename) {
2171
+ return typeof filename === "string" ? filename.split("\\").join("/") : "";
2172
+ }
2173
+ function isExemptFile2(path2, allow) {
2174
+ if (!path2.includes("/src/")) return true;
2175
+ if (TEST_FILE2.test(path2) || SHARED_SOURCE.test(path2)) return true;
2176
+ return allow.some((fragment) => path2.includes(fragment));
2177
+ }
2178
+ var MODULE_DECLARATIONS = /* @__PURE__ */ new Set(["ImportDeclaration", "ExportNamedDeclaration", "ExportAllDeclaration"]);
2179
+ function usesPackage(program, packageName) {
2180
+ return program.body.some((statement) => {
2181
+ if (!MODULE_DECLARATIONS.has(statement.type) || statement.source == null) return false;
2182
+ const source = statement.source.value;
2183
+ return source === packageName || typeof source === "string" && source.startsWith(`${packageName}/`);
2184
+ });
2185
+ }
2186
+ function literalText(node) {
2187
+ if (node.type === "Literal") return typeof node.value === "string" ? node.value : "";
2188
+ return node.quasis.length === 1 ? node.quasis[0].value.cooked ?? "" : "";
2189
+ }
2190
+ var noReimplementedPackageRule = {
2191
+ meta: {
2192
+ type: "problem",
2193
+ docs: {
2194
+ description: "Flag app code that re-implements a capability a shared @dloizides package already provides.",
2195
+ recommended: false
2196
+ },
2197
+ schema: [
2198
+ {
2199
+ type: "object",
2200
+ properties: { allow: { type: "array", items: { type: "string" } } },
2201
+ additionalProperties: false
2202
+ }
2203
+ ],
2204
+ messages: {
2205
+ reimplemented: "This re-implements {{package}} ({{id}}). Use {{use}} from {{package}} instead (QUAL-ADOPT-1)."
2206
+ }
2207
+ },
2208
+ create(context) {
2209
+ const options = context.options[0] ?? {};
2210
+ const path2 = normalisePath2(context.filename ?? context.getFilename());
2211
+ if (isExemptFile2(path2, options.allow ?? [])) return {};
2212
+ const reported = /* @__PURE__ */ new Set();
2213
+ const report = (node, entry) => {
2214
+ if (reported.has(entry.id)) return;
2215
+ reported.add(entry.id);
2216
+ context.report({ node, messageId: "reimplemented", data: { id: entry.id, package: entry.package, use: entry.use } });
2217
+ };
2218
+ const checkLiteral = (node) => {
2219
+ const text = literalText(node);
2220
+ if (text === "") return;
2221
+ for (const entry of REIMPLEMENTED_PACKAGE_REGISTRY)
2222
+ if (entry.literals.some((pattern) => pattern.test(text))) report(node, entry);
2223
+ };
2224
+ return {
2225
+ Program(node) {
2226
+ for (const entry of REIMPLEMENTED_PACKAGE_REGISTRY)
2227
+ if (entry.paths.some((pattern) => pattern.test(path2)) && !usesPackage(node, entry.package)) report(node, entry);
2228
+ },
2229
+ Literal: checkLiteral,
2230
+ TemplateLiteral: checkLiteral
2231
+ };
2232
+ }
2233
+ };
2234
+ var no_reimplemented_package_default = {
2235
+ rules: {
2236
+ "no-reimplemented-package": noReimplementedPackageRule
2237
+ }
2238
+ };
2239
+
2135
2240
  // src/rules/prefer-const-enum.js
2136
2241
  function toPascalCase(value) {
2137
2242
  const words = value.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[-_\s]+/).filter((w) => w.length > 0);
@@ -2203,17 +2308,17 @@ var prefer_const_enum_default = {
2203
2308
 
2204
2309
  // src/rules/query-key-factory.js
2205
2310
  var QUERY_KEY = "queryKey";
2206
- var TEST_FILE2 = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
2311
+ var TEST_FILE3 = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
2207
2312
  var FACTORY_FILE = /[kK]eys?(?:Factory)?\.[cm]?[jt]sx?$/;
2208
2313
  var DEFAULT_ALLOWED_PATH_FRAGMENTS2 = ["/generated/", "/autoGeneratedHooks/"];
2209
2314
  var INLINE_KEY_TYPES = /* @__PURE__ */ new Set(["ArrayExpression", "Literal", "TemplateLiteral"]);
2210
2315
  var TYPE_WRAPPERS = /* @__PURE__ */ new Set(["TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression"]);
2211
- function normalisePath2(filename) {
2316
+ function normalisePath3(filename) {
2212
2317
  return typeof filename === "string" ? filename.split("\\").join("/") : "";
2213
2318
  }
2214
- function isExemptFile2(filename, allow) {
2215
- const path2 = normalisePath2(filename);
2216
- if (TEST_FILE2.test(path2)) return true;
2319
+ function isExemptFile3(filename, allow) {
2320
+ const path2 = normalisePath3(filename);
2321
+ if (TEST_FILE3.test(path2)) return true;
2217
2322
  if (FACTORY_FILE.test(path2)) return true;
2218
2323
  return [...DEFAULT_ALLOWED_PATH_FRAGMENTS2, ...allow].some((fragment) => path2.includes(fragment));
2219
2324
  }
@@ -2248,7 +2353,7 @@ var rule4 = {
2248
2353
  const options = context.options[0] ?? {};
2249
2354
  const allow = Array.isArray(options.allow) ? options.allow : [];
2250
2355
  const filename = context.filename ?? context.getFilename();
2251
- if (isExemptFile2(filename, allow)) return {};
2356
+ if (isExemptFile3(filename, allow)) return {};
2252
2357
  return {
2253
2358
  Property(node) {
2254
2359
  if (!isQueryKeyProperty(node)) return;
@@ -2942,6 +3047,7 @@ var ruleModules = [
2942
3047
  no_product_imports_in_shared_default,
2943
3048
  no_raw_backend_fetch_default,
2944
3049
  no_raw_color_literal_default,
3050
+ no_reimplemented_package_default,
2945
3051
  prefer_const_enum_default,
2946
3052
  query_key_factory_default,
2947
3053
  require_stable_hook_args_default,
@@ -3060,11 +3166,18 @@ var apiConfig = {
3060
3166
  "@dloizides/no-raw-backend-fetch": "error"
3061
3167
  }
3062
3168
  };
3169
+ var REUSE_RULE_NAMES = ["no-reimplemented-package"];
3170
+ var reuseConfig = {
3171
+ plugins: commentsConfig.plugins,
3172
+ rules: {
3173
+ "@dloizides/no-reimplemented-package": "error"
3174
+ }
3175
+ };
3063
3176
  var recommendedConfig = {
3064
3177
  plugins: commentsConfig.plugins,
3065
3178
  rules: { ...commentsConfig.rules, ...rowActionsConfig.rules, ...apiConfig.rules }
3066
3179
  };
3067
3180
 
3068
- export { API_RULE_NAMES, COMMENT_RULE_NAMES, GAME_RULE_NAMES, HOUSE_PATTERN_RULE_NAMES, ROW_ACTION_RULE_NAMES, apiConfig, commentsConfig, gameConfig, legacyPlugins, patternPacksConfig, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
3181
+ export { API_RULE_NAMES, COMMENT_RULE_NAMES, GAME_RULE_NAMES, HOUSE_PATTERN_RULE_NAMES, REUSE_RULE_NAMES, ROW_ACTION_RULE_NAMES, apiConfig, commentsConfig, gameConfig, legacyPlugins, patternPacksConfig, plugin, recommendedConfig, reuseConfig, rowActionsConfig, ruleNames, rules };
3069
3182
  //# sourceMappingURL=index.mjs.map
3070
3183
  //# sourceMappingURL=index.mjs.map