@sarj/eslint-plugin 2.3.0 → 2.3.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.
package/dist/index.cjs CHANGED
@@ -2569,119 +2569,8 @@ var no_secret_in_log_default = import_utils24.ESLintUtils.RuleCreator(
2569
2569
  }
2570
2570
  });
2571
2571
 
2572
- // src/rules/no-template-literal-in-log.ts
2573
- var import_utils25 = require("@typescript-eslint/utils");
2574
- var LOG_METHODS2 = /* @__PURE__ */ new Set([
2575
- "debug",
2576
- "info",
2577
- "warn",
2578
- "warning",
2579
- "error",
2580
- "exception",
2581
- "critical",
2582
- "trace",
2583
- "log",
2584
- "fatal",
2585
- "success"
2586
- ]);
2587
- var LOGGER_NAMES2 = /* @__PURE__ */ new Set([
2588
- "console",
2589
- "logger",
2590
- "log",
2591
- "_log",
2592
- "_logger"
2593
- ]);
2594
- var LOGGER_FACTORIES2 = /* @__PURE__ */ new Set([
2595
- "getlogger",
2596
- "createlogger"
2597
- ]);
2598
- function looksLikeLogger(node) {
2599
- switch (node.type) {
2600
- case "Identifier": {
2601
- const name = node.name.toLowerCase();
2602
- return LOGGER_NAMES2.has(name) || LOGGER_FACTORIES2.has(name);
2603
- }
2604
- case "MemberExpression": {
2605
- if (!node.computed && node.property.type === "Identifier") {
2606
- const prop = node.property.name.toLowerCase();
2607
- if (LOGGER_NAMES2.has(prop) || LOGGER_FACTORIES2.has(prop)) {
2608
- return true;
2609
- }
2610
- }
2611
- return looksLikeLogger(node.object);
2612
- }
2613
- case "CallExpression":
2614
- return looksLikeLogger(node.callee);
2615
- default:
2616
- return false;
2617
- }
2618
- }
2619
- function findInterpolatingTemplate(node) {
2620
- if (node.type === "TemplateLiteral") {
2621
- return node.expressions.length > 0 ? node : null;
2622
- }
2623
- if (node.type === "BinaryExpression" && node.operator === "+") {
2624
- return findInterpolatingTemplate(node.left) ?? findInterpolatingTemplate(node.right);
2625
- }
2626
- return null;
2627
- }
2628
- function messageArg(node, method, receiver) {
2629
- const levelFirst = method === "log" && !isConsoleReceiver(receiver);
2630
- const arg = node.arguments[levelFirst ? 1 : 0];
2631
- if (arg === void 0 || arg.type === "SpreadElement") {
2632
- return null;
2633
- }
2634
- return arg;
2635
- }
2636
- function isConsoleReceiver(node) {
2637
- return node.type === "Identifier" && node.name === "console";
2638
- }
2639
- var no_template_literal_in_log_default = import_utils25.ESLintUtils.RuleCreator(
2640
- (name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
2641
- )({
2642
- name: "no-template-literal-in-log",
2643
- meta: {
2644
- type: "problem",
2645
- docs: {
2646
- description: "Disallow an interpolating template literal as a logging message \u2014 pass variables as structured fields so logs stay filterable and templates stay constant."
2647
- },
2648
- schema: [],
2649
- messages: {
2650
- noTemplateLiteralInLog: "Interpolating template literal as a logging message \u2014 pass variables as structured fields (logger.info('msg', { key })) instead."
2651
- }
2652
- },
2653
- defaultOptions: [],
2654
- create(context) {
2655
- return {
2656
- CallExpression(node) {
2657
- const callee = node.callee;
2658
- if (callee.type !== "MemberExpression" || callee.computed) {
2659
- return;
2660
- }
2661
- if (callee.property.type !== "Identifier") {
2662
- return;
2663
- }
2664
- const method = callee.property.name;
2665
- if (!LOG_METHODS2.has(method)) {
2666
- return;
2667
- }
2668
- if (!looksLikeLogger(callee.object)) {
2669
- return;
2670
- }
2671
- const arg = messageArg(node, method, callee.object);
2672
- if (arg === null) {
2673
- return;
2674
- }
2675
- if (findInterpolatingTemplate(arg) !== null) {
2676
- context.report({ node, messageId: "noTemplateLiteralInLog" });
2677
- }
2678
- }
2679
- };
2680
- }
2681
- });
2682
-
2683
2572
  // src/rules/prefer-string-literal-union.ts
2684
- var import_utils26 = require("@typescript-eslint/utils");
2573
+ var import_utils25 = require("@typescript-eslint/utils");
2685
2574
  var CHOICE_TOKENS = /* @__PURE__ */ new Set([
2686
2575
  "status",
2687
2576
  "state",
@@ -2719,30 +2608,30 @@ function isChoiceLikeName(name) {
2719
2608
  return CHOICE_TOKENS.has(lastWord(name));
2720
2609
  }
2721
2610
  function keyName(key) {
2722
- if (key.type === import_utils26.AST_NODE_TYPES.Identifier) {
2611
+ if (key.type === import_utils25.AST_NODE_TYPES.Identifier) {
2723
2612
  return key.name;
2724
2613
  }
2725
- if (key.type === import_utils26.AST_NODE_TYPES.Literal && typeof key.value === "string") {
2614
+ if (key.type === import_utils25.AST_NODE_TYPES.Literal && typeof key.value === "string") {
2726
2615
  return key.value;
2727
2616
  }
2728
2617
  return null;
2729
2618
  }
2730
2619
  function isStringLiteralUnion(node) {
2731
- if (node?.type !== import_utils26.AST_NODE_TYPES.TSUnionType) {
2620
+ if (node?.type !== import_utils25.AST_NODE_TYPES.TSUnionType) {
2732
2621
  return false;
2733
2622
  }
2734
2623
  const stringMembers = node.types.filter(
2735
- (t) => t.type === import_utils26.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils26.AST_NODE_TYPES.Literal && typeof t.literal.value === "string"
2624
+ (t) => t.type === import_utils25.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils25.AST_NODE_TYPES.Literal && typeof t.literal.value === "string"
2736
2625
  );
2737
2626
  return stringMembers.length >= MIN_CLUSTER_SIZE;
2738
2627
  }
2739
2628
  function refKey(node) {
2740
- if (node.type === import_utils26.AST_NODE_TYPES.Identifier) {
2629
+ if (node.type === import_utils25.AST_NODE_TYPES.Identifier) {
2741
2630
  return node.name;
2742
2631
  }
2743
- if (node.type === import_utils26.AST_NODE_TYPES.MemberExpression && !node.computed) {
2632
+ if (node.type === import_utils25.AST_NODE_TYPES.MemberExpression && !node.computed) {
2744
2633
  const inner = refKey(node.object);
2745
- if (inner === null || node.property.type !== import_utils26.AST_NODE_TYPES.Identifier) {
2634
+ if (inner === null || node.property.type !== import_utils25.AST_NODE_TYPES.Identifier) {
2746
2635
  return null;
2747
2636
  }
2748
2637
  return `${inner}.${node.property.name}`;
@@ -2750,12 +2639,12 @@ function refKey(node) {
2750
2639
  return null;
2751
2640
  }
2752
2641
  function strLiteral(node) {
2753
- if (node.type === import_utils26.AST_NODE_TYPES.Literal && typeof node.value === "string") {
2642
+ if (node.type === import_utils25.AST_NODE_TYPES.Literal && typeof node.value === "string") {
2754
2643
  return node.value;
2755
2644
  }
2756
2645
  return null;
2757
2646
  }
2758
- var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator(
2647
+ var prefer_string_literal_union_default = import_utils25.ESLintUtils.RuleCreator(
2759
2648
  (name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
2760
2649
  )({
2761
2650
  name: "prefer-string-literal-union",
@@ -2820,7 +2709,7 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
2820
2709
  containersWithUnion.add(container);
2821
2710
  return;
2822
2711
  }
2823
- if (typeNode?.type !== import_utils26.AST_NODE_TYPES.TSStringKeyword) {
2712
+ if (typeNode?.type !== import_utils25.AST_NODE_TYPES.TSStringKeyword) {
2824
2713
  return;
2825
2714
  }
2826
2715
  const name = keyName(key);
@@ -2904,10 +2793,10 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
2904
2793
  }
2905
2794
  };
2906
2795
  function refKeyText(node) {
2907
- if (node.type === import_utils26.AST_NODE_TYPES.BinaryExpression) {
2796
+ if (node.type === import_utils25.AST_NODE_TYPES.BinaryExpression) {
2908
2797
  return refKey(node.left) ?? refKey(node.right) ?? "value";
2909
2798
  }
2910
- if (node.type === import_utils26.AST_NODE_TYPES.SwitchStatement) {
2799
+ if (node.type === import_utils25.AST_NODE_TYPES.SwitchStatement) {
2911
2800
  return refKey(node.discriminant) ?? "value";
2912
2801
  }
2913
2802
  return "value";
@@ -2916,7 +2805,7 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
2916
2805
  });
2917
2806
 
2918
2807
  // src/rules/single-public-export.ts
2919
- var import_utils27 = require("@typescript-eslint/utils");
2808
+ var import_utils26 = require("@typescript-eslint/utils");
2920
2809
  var JUNK_DRAWER_STEMS = /* @__PURE__ */ new Set([
2921
2810
  "util",
2922
2811
  "utils",
@@ -2950,12 +2839,12 @@ var kebabCase = (name) => {
2950
2839
  }
2951
2840
  return normalized.replace(CAMEL_BOUNDARY_RE, "-").toLowerCase();
2952
2841
  };
2953
- var isFunctionExpression2 = (node) => node !== null && (node.type === import_utils27.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils27.AST_NODE_TYPES.FunctionExpression);
2842
+ var isFunctionExpression2 = (node) => node !== null && (node.type === import_utils26.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils26.AST_NODE_TYPES.FunctionExpression);
2954
2843
  var functionConstName = (decl) => {
2955
2844
  if (decl.declarations.length !== 1) return null;
2956
2845
  const [declarator] = decl.declarations;
2957
2846
  if (declarator === void 0) return null;
2958
- if (declarator.id.type !== import_utils27.AST_NODE_TYPES.Identifier) return null;
2847
+ if (declarator.id.type !== import_utils26.AST_NODE_TYPES.Identifier) return null;
2959
2848
  if (!isFunctionExpression2(declarator.init)) return null;
2960
2849
  return declarator.id.name;
2961
2850
  };
@@ -2969,20 +2858,20 @@ var summarizeExports = (body) => {
2969
2858
  };
2970
2859
  for (const statement of body) {
2971
2860
  switch (statement.type) {
2972
- case import_utils27.AST_NODE_TYPES.ExportAllDeclaration:
2861
+ case import_utils26.AST_NODE_TYPES.ExportAllDeclaration:
2973
2862
  hasReExport = true;
2974
2863
  break;
2975
- case import_utils27.AST_NODE_TYPES.ExportDefaultDeclaration: {
2864
+ case import_utils26.AST_NODE_TYPES.ExportDefaultDeclaration: {
2976
2865
  names += 1;
2977
2866
  const decl = statement.declaration;
2978
- if (decl.type === import_utils27.AST_NODE_TYPES.FunctionDeclaration && decl.id !== null) {
2867
+ if (decl.type === import_utils26.AST_NODE_TYPES.FunctionDeclaration && decl.id !== null) {
2979
2868
  candidate = { name: decl.id.name, node: statement };
2980
- } else if (decl.type === import_utils27.AST_NODE_TYPES.ClassDeclaration && decl.id !== null) {
2869
+ } else if (decl.type === import_utils26.AST_NODE_TYPES.ClassDeclaration && decl.id !== null) {
2981
2870
  candidate = { name: decl.id.name, node: statement };
2982
2871
  }
2983
2872
  break;
2984
2873
  }
2985
- case import_utils27.AST_NODE_TYPES.ExportNamedDeclaration: {
2874
+ case import_utils26.AST_NODE_TYPES.ExportNamedDeclaration: {
2986
2875
  if (statement.source !== null) {
2987
2876
  hasReExport = true;
2988
2877
  break;
@@ -2993,15 +2882,15 @@ var summarizeExports = (body) => {
2993
2882
  break;
2994
2883
  }
2995
2884
  switch (decl.type) {
2996
- case import_utils27.AST_NODE_TYPES.FunctionDeclaration:
2885
+ case import_utils26.AST_NODE_TYPES.FunctionDeclaration:
2997
2886
  if (decl.id !== null) addCandidate(decl.id.name, statement);
2998
2887
  else names += 1;
2999
2888
  break;
3000
- case import_utils27.AST_NODE_TYPES.ClassDeclaration:
2889
+ case import_utils26.AST_NODE_TYPES.ClassDeclaration:
3001
2890
  if (decl.id !== null) addCandidate(decl.id.name, statement);
3002
2891
  else names += 1;
3003
2892
  break;
3004
- case import_utils27.AST_NODE_TYPES.VariableDeclaration: {
2893
+ case import_utils26.AST_NODE_TYPES.VariableDeclaration: {
3005
2894
  const fnName = functionConstName(decl);
3006
2895
  if (fnName !== null && decl.declarations.length === 1) {
3007
2896
  addCandidate(fnName, statement);
@@ -3021,7 +2910,7 @@ var summarizeExports = (body) => {
3021
2910
  }
3022
2911
  return { names, hasReExport, candidate };
3023
2912
  };
3024
- var single_public_export_default = import_utils27.ESLintUtils.RuleCreator(
2913
+ var single_public_export_default = import_utils26.ESLintUtils.RuleCreator(
3025
2914
  (name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
3026
2915
  )({
3027
2916
  name: "single-public-export",
@@ -3085,14 +2974,13 @@ var rules = {
3085
2974
  "no-cors-wildcard-with-credentials": no_cors_wildcard_with_credentials_default,
3086
2975
  "no-fat-try-blocks": no_fat_try_blocks_default,
3087
2976
  "no-secret-in-log": no_secret_in_log_default,
3088
- "no-template-literal-in-log": no_template_literal_in_log_default,
3089
2977
  "prefer-string-literal-union": prefer_string_literal_union_default,
3090
2978
  "single-public-export": single_public_export_default
3091
2979
  };
3092
2980
  var plugin = {
3093
2981
  meta: {
3094
2982
  name: "@sarj/eslint-plugin",
3095
- version: "2.3.0"
2983
+ version: "2.3.1"
3096
2984
  },
3097
2985
  rules,
3098
2986
  configs: {
@@ -3121,7 +3009,6 @@ var plugin = {
3121
3009
  // Ported from sarj-python-lint (SARJ), corpus-validated FP~0.
3122
3010
  "@sarj/no-fat-try-blocks": "warn",
3123
3011
  "@sarj/no-cors-wildcard-with-credentials": "warn",
3124
- "@sarj/no-template-literal-in-log": "warn",
3125
3012
  "@sarj/no-secret-in-log": "warn",
3126
3013
  "@sarj/single-public-export": "warn",
3127
3014
  "@sarj/prefer-string-literal-union": "warn"
@@ -3156,7 +3043,6 @@ var plugin = {
3156
3043
  // Ported from sarj-python-lint (SARJ), corpus-validated FP~0.
3157
3044
  "@sarj/no-fat-try-blocks": "error",
3158
3045
  "@sarj/no-cors-wildcard-with-credentials": "error",
3159
- "@sarj/no-template-literal-in-log": "error",
3160
3046
  "@sarj/no-secret-in-log": "error",
3161
3047
  "@sarj/single-public-export": "error",
3162
3048
  // High-volume/stylistic — warn until rollout proves FP rate.