@sarj/eslint-plugin 2.3.1 → 2.3.3

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
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -2235,7 +2245,15 @@ var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
2235
2245
  "Object",
2236
2246
  "Headers",
2237
2247
  "URLSearchParams",
2238
- "FormData"
2248
+ "FormData",
2249
+ "TextEncoder",
2250
+ "TextDecoder",
2251
+ "Blob",
2252
+ "ReadableStream",
2253
+ "WritableStream",
2254
+ "TransformStream",
2255
+ "Response",
2256
+ "AbortController"
2239
2257
  ]);
2240
2258
  function isNode3(value) {
2241
2259
  return typeof value === "object" && value !== null && typeof value.type === "string";
@@ -2425,7 +2443,49 @@ var INNOCUOUS_WORDS = /* @__PURE__ */ new Set([
2425
2443
  "invalid",
2426
2444
  "exists",
2427
2445
  "type",
2428
- "types"
2446
+ "types",
2447
+ "name",
2448
+ "names",
2449
+ "label",
2450
+ "labels",
2451
+ "title",
2452
+ "expiry",
2453
+ "expiration",
2454
+ "expires",
2455
+ "ttl",
2456
+ "version",
2457
+ "versions",
2458
+ "policy",
2459
+ "rotation",
2460
+ "arn",
2461
+ "path",
2462
+ "paths",
2463
+ "issuer",
2464
+ "audience",
2465
+ "strength",
2466
+ "manager",
2467
+ "service",
2468
+ "services",
2469
+ "repository",
2470
+ "provider",
2471
+ "providers",
2472
+ "store",
2473
+ "factory",
2474
+ "handler",
2475
+ "controller",
2476
+ "bucket",
2477
+ "url",
2478
+ "uri",
2479
+ "endpoint",
2480
+ "endpoints",
2481
+ "scope",
2482
+ "scopes",
2483
+ "event",
2484
+ "events",
2485
+ "format",
2486
+ "at",
2487
+ "len",
2488
+ "length"
2429
2489
  ]);
2430
2490
  var REDACTION_RE = /prefix|suffix|redact|mask|hash|hint|_len|length/i;
2431
2491
  var WHOLE_TOKEN_REDACTION_MARKERS = /* @__PURE__ */ new Set(["tag"]);
@@ -2500,6 +2560,12 @@ function isLoggerExpr(expr) {
2500
2560
  return false;
2501
2561
  }
2502
2562
  }
2563
+ function isRawSecretValue(prop) {
2564
+ if (prop.shorthand) {
2565
+ return true;
2566
+ }
2567
+ return prop.value.type === "Identifier" || prop.value.type === "MemberExpression";
2568
+ }
2503
2569
  function propertyKeyName2(prop) {
2504
2570
  if (prop.computed) {
2505
2571
  return null;
@@ -2554,7 +2620,7 @@ var no_secret_in_log_default = import_utils24.ESLintUtils.RuleCreator(
2554
2620
  continue;
2555
2621
  }
2556
2622
  const keyName2 = propertyKeyName2(prop);
2557
- if (keyName2 !== null && isSecretKeyword(keyName2)) {
2623
+ if (keyName2 !== null && isSecretKeyword(keyName2) && isRawSecretValue(prop)) {
2558
2624
  context.report({
2559
2625
  node: prop,
2560
2626
  messageId: "noSecretInLog",
@@ -2571,6 +2637,7 @@ var no_secret_in_log_default = import_utils24.ESLintUtils.RuleCreator(
2571
2637
 
2572
2638
  // src/rules/prefer-string-literal-union.ts
2573
2639
  var import_utils25 = require("@typescript-eslint/utils");
2640
+ var ts = __toESM(require("typescript"), 1);
2574
2641
  var CHOICE_TOKENS = /* @__PURE__ */ new Set([
2575
2642
  "status",
2576
2643
  "state",
@@ -2587,6 +2654,10 @@ var CHOICE_TOKENS = /* @__PURE__ */ new Set([
2587
2654
  ]);
2588
2655
  var LOWER_TOKEN_RE = /^[a-z][a-z0-9_-]{0,30}$/;
2589
2656
  var MIN_CLUSTER_SIZE = 2;
2657
+ var BOOLEANISH = /* @__PURE__ */ new Set(["true", "false"]);
2658
+ function isEnumToken(lit) {
2659
+ return LOWER_TOKEN_RE.test(lit) && lit.length >= 2 && !BOOLEANISH.has(lit);
2660
+ }
2590
2661
  var IGNORE_PATTERNS = [
2591
2662
  /[\\/]generated[\\/]/,
2592
2663
  /\.gen\.tsx?$/,
@@ -2616,14 +2687,18 @@ function keyName(key) {
2616
2687
  }
2617
2688
  return null;
2618
2689
  }
2690
+ function isStringLiteralMember(t) {
2691
+ return t.type === import_utils25.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils25.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
2692
+ }
2619
2693
  function isStringLiteralUnion(node) {
2620
2694
  if (node?.type !== import_utils25.AST_NODE_TYPES.TSUnionType) {
2621
2695
  return false;
2622
2696
  }
2623
- const stringMembers = node.types.filter(
2624
- (t) => t.type === import_utils25.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils25.AST_NODE_TYPES.Literal && typeof t.literal.value === "string"
2625
- );
2626
- return stringMembers.length >= MIN_CLUSTER_SIZE;
2697
+ return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
2698
+ }
2699
+ function typeHasRawString(type) {
2700
+ const parts = type.isUnion() ? type.types : [type];
2701
+ return parts.some((t) => (t.flags & ts.TypeFlags.String) !== 0);
2627
2702
  }
2628
2703
  function refKey(node) {
2629
2704
  if (node.type === import_utils25.AST_NODE_TYPES.Identifier) {
@@ -2666,19 +2741,31 @@ var prefer_string_literal_union_default = import_utils25.ESLintUtils.RuleCreator
2666
2741
  if (isIgnoredFile(filename, sourceText)) {
2667
2742
  return {};
2668
2743
  }
2744
+ let services;
2745
+ try {
2746
+ services = import_utils25.ESLintUtils.getParserServices(context);
2747
+ } catch {
2748
+ services = null;
2749
+ }
2669
2750
  const scopeStack = [];
2670
2751
  const validClusters = [];
2671
2752
  const bareChoiceProps = [];
2672
2753
  const containersWithUnion = /* @__PURE__ */ new Set();
2754
+ function operandIsRawString(node) {
2755
+ if (services === null) {
2756
+ return false;
2757
+ }
2758
+ return typeHasRawString(services.getTypeAtLocation(node));
2759
+ }
2673
2760
  function pushScope() {
2674
- scopeStack.push(/* @__PURE__ */ new Map());
2761
+ scopeStack.push({ clusters: /* @__PURE__ */ new Map() });
2675
2762
  }
2676
2763
  function popScope() {
2677
- const clusters = scopeStack.pop();
2678
- if (clusters === void 0) {
2764
+ const scope = scopeStack.pop();
2765
+ if (scope === void 0) {
2679
2766
  return;
2680
2767
  }
2681
- for (const entry of clusters.values()) {
2768
+ for (const entry of scope.clusters.values()) {
2682
2769
  if (entry.allTokens && entry.literals.size >= MIN_CLUSTER_SIZE) {
2683
2770
  validClusters.push(entry.node);
2684
2771
  }
@@ -2689,10 +2776,10 @@ var prefer_string_literal_union_default = import_utils25.ESLintUtils.RuleCreator
2689
2776
  if (scope === void 0) {
2690
2777
  return;
2691
2778
  }
2692
- const allTokens = literals.every((lit) => LOWER_TOKEN_RE.test(lit));
2693
- const existing = scope.get(key);
2779
+ const allTokens = literals.every((lit) => isEnumToken(lit));
2780
+ const existing = scope.clusters.get(key);
2694
2781
  if (existing === void 0) {
2695
- scope.set(key, {
2782
+ scope.clusters.set(key, {
2696
2783
  node,
2697
2784
  literals: new Set(literals),
2698
2785
  allTokens
@@ -2734,14 +2821,18 @@ var prefer_string_literal_union_default = import_utils25.ESLintUtils.RuleCreator
2734
2821
  const rightKey = refKey(node.right);
2735
2822
  const leftLit = strLiteral(node.left);
2736
2823
  if (leftKey !== null && rightLit !== null) {
2737
- accumulate(leftKey, [rightLit], node);
2824
+ if (operandIsRawString(node.left)) {
2825
+ accumulate(leftKey, [rightLit], node);
2826
+ }
2738
2827
  } else if (rightKey !== null && leftLit !== null) {
2739
- accumulate(rightKey, [leftLit], node);
2828
+ if (operandIsRawString(node.right)) {
2829
+ accumulate(rightKey, [leftLit], node);
2830
+ }
2740
2831
  }
2741
2832
  },
2742
2833
  SwitchStatement(node) {
2743
2834
  const key = refKey(node.discriminant);
2744
- if (key === null) {
2835
+ if (key === null || !operandIsRawString(node.discriminant)) {
2745
2836
  return;
2746
2837
  }
2747
2838
  const literals = [];
@@ -2980,7 +3071,7 @@ var rules = {
2980
3071
  var plugin = {
2981
3072
  meta: {
2982
3073
  name: "@sarj/eslint-plugin",
2983
- version: "2.3.1"
3074
+ version: "2.3.3"
2984
3075
  },
2985
3076
  rules,
2986
3077
  configs: {