@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 +109 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +99 -18
- package/dist/index.js.map +1 -1
- package/package.json +8 -2
package/dist/index.js
CHANGED
|
@@ -2223,7 +2223,15 @@ var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
2223
2223
|
"Object",
|
|
2224
2224
|
"Headers",
|
|
2225
2225
|
"URLSearchParams",
|
|
2226
|
-
"FormData"
|
|
2226
|
+
"FormData",
|
|
2227
|
+
"TextEncoder",
|
|
2228
|
+
"TextDecoder",
|
|
2229
|
+
"Blob",
|
|
2230
|
+
"ReadableStream",
|
|
2231
|
+
"WritableStream",
|
|
2232
|
+
"TransformStream",
|
|
2233
|
+
"Response",
|
|
2234
|
+
"AbortController"
|
|
2227
2235
|
]);
|
|
2228
2236
|
function isNode3(value) {
|
|
2229
2237
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -2413,7 +2421,49 @@ var INNOCUOUS_WORDS = /* @__PURE__ */ new Set([
|
|
|
2413
2421
|
"invalid",
|
|
2414
2422
|
"exists",
|
|
2415
2423
|
"type",
|
|
2416
|
-
"types"
|
|
2424
|
+
"types",
|
|
2425
|
+
"name",
|
|
2426
|
+
"names",
|
|
2427
|
+
"label",
|
|
2428
|
+
"labels",
|
|
2429
|
+
"title",
|
|
2430
|
+
"expiry",
|
|
2431
|
+
"expiration",
|
|
2432
|
+
"expires",
|
|
2433
|
+
"ttl",
|
|
2434
|
+
"version",
|
|
2435
|
+
"versions",
|
|
2436
|
+
"policy",
|
|
2437
|
+
"rotation",
|
|
2438
|
+
"arn",
|
|
2439
|
+
"path",
|
|
2440
|
+
"paths",
|
|
2441
|
+
"issuer",
|
|
2442
|
+
"audience",
|
|
2443
|
+
"strength",
|
|
2444
|
+
"manager",
|
|
2445
|
+
"service",
|
|
2446
|
+
"services",
|
|
2447
|
+
"repository",
|
|
2448
|
+
"provider",
|
|
2449
|
+
"providers",
|
|
2450
|
+
"store",
|
|
2451
|
+
"factory",
|
|
2452
|
+
"handler",
|
|
2453
|
+
"controller",
|
|
2454
|
+
"bucket",
|
|
2455
|
+
"url",
|
|
2456
|
+
"uri",
|
|
2457
|
+
"endpoint",
|
|
2458
|
+
"endpoints",
|
|
2459
|
+
"scope",
|
|
2460
|
+
"scopes",
|
|
2461
|
+
"event",
|
|
2462
|
+
"events",
|
|
2463
|
+
"format",
|
|
2464
|
+
"at",
|
|
2465
|
+
"len",
|
|
2466
|
+
"length"
|
|
2417
2467
|
]);
|
|
2418
2468
|
var REDACTION_RE = /prefix|suffix|redact|mask|hash|hint|_len|length/i;
|
|
2419
2469
|
var WHOLE_TOKEN_REDACTION_MARKERS = /* @__PURE__ */ new Set(["tag"]);
|
|
@@ -2488,6 +2538,12 @@ function isLoggerExpr(expr) {
|
|
|
2488
2538
|
return false;
|
|
2489
2539
|
}
|
|
2490
2540
|
}
|
|
2541
|
+
function isRawSecretValue(prop) {
|
|
2542
|
+
if (prop.shorthand) {
|
|
2543
|
+
return true;
|
|
2544
|
+
}
|
|
2545
|
+
return prop.value.type === "Identifier" || prop.value.type === "MemberExpression";
|
|
2546
|
+
}
|
|
2491
2547
|
function propertyKeyName2(prop) {
|
|
2492
2548
|
if (prop.computed) {
|
|
2493
2549
|
return null;
|
|
@@ -2542,7 +2598,7 @@ var no_secret_in_log_default = ESLintUtils23.RuleCreator(
|
|
|
2542
2598
|
continue;
|
|
2543
2599
|
}
|
|
2544
2600
|
const keyName2 = propertyKeyName2(prop);
|
|
2545
|
-
if (keyName2 !== null && isSecretKeyword(keyName2)) {
|
|
2601
|
+
if (keyName2 !== null && isSecretKeyword(keyName2) && isRawSecretValue(prop)) {
|
|
2546
2602
|
context.report({
|
|
2547
2603
|
node: prop,
|
|
2548
2604
|
messageId: "noSecretInLog",
|
|
@@ -2562,6 +2618,7 @@ import {
|
|
|
2562
2618
|
ESLintUtils as ESLintUtils24,
|
|
2563
2619
|
AST_NODE_TYPES as AST_NODE_TYPES12
|
|
2564
2620
|
} from "@typescript-eslint/utils";
|
|
2621
|
+
import * as ts from "typescript";
|
|
2565
2622
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
2566
2623
|
"status",
|
|
2567
2624
|
"state",
|
|
@@ -2578,6 +2635,10 @@ var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
|
2578
2635
|
]);
|
|
2579
2636
|
var LOWER_TOKEN_RE = /^[a-z][a-z0-9_-]{0,30}$/;
|
|
2580
2637
|
var MIN_CLUSTER_SIZE = 2;
|
|
2638
|
+
var BOOLEANISH = /* @__PURE__ */ new Set(["true", "false"]);
|
|
2639
|
+
function isEnumToken(lit) {
|
|
2640
|
+
return LOWER_TOKEN_RE.test(lit) && lit.length >= 2 && !BOOLEANISH.has(lit);
|
|
2641
|
+
}
|
|
2581
2642
|
var IGNORE_PATTERNS = [
|
|
2582
2643
|
/[\\/]generated[\\/]/,
|
|
2583
2644
|
/\.gen\.tsx?$/,
|
|
@@ -2607,14 +2668,18 @@ function keyName(key) {
|
|
|
2607
2668
|
}
|
|
2608
2669
|
return null;
|
|
2609
2670
|
}
|
|
2671
|
+
function isStringLiteralMember(t) {
|
|
2672
|
+
return t.type === AST_NODE_TYPES12.TSLiteralType && t.literal.type === AST_NODE_TYPES12.Literal && typeof t.literal.value === "string";
|
|
2673
|
+
}
|
|
2610
2674
|
function isStringLiteralUnion(node) {
|
|
2611
2675
|
if (node?.type !== AST_NODE_TYPES12.TSUnionType) {
|
|
2612
2676
|
return false;
|
|
2613
2677
|
}
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2678
|
+
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
2679
|
+
}
|
|
2680
|
+
function typeHasRawString(type) {
|
|
2681
|
+
const parts = type.isUnion() ? type.types : [type];
|
|
2682
|
+
return parts.some((t) => (t.flags & ts.TypeFlags.String) !== 0);
|
|
2618
2683
|
}
|
|
2619
2684
|
function refKey(node) {
|
|
2620
2685
|
if (node.type === AST_NODE_TYPES12.Identifier) {
|
|
@@ -2657,19 +2722,31 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
2657
2722
|
if (isIgnoredFile(filename, sourceText)) {
|
|
2658
2723
|
return {};
|
|
2659
2724
|
}
|
|
2725
|
+
let services;
|
|
2726
|
+
try {
|
|
2727
|
+
services = ESLintUtils24.getParserServices(context);
|
|
2728
|
+
} catch {
|
|
2729
|
+
services = null;
|
|
2730
|
+
}
|
|
2660
2731
|
const scopeStack = [];
|
|
2661
2732
|
const validClusters = [];
|
|
2662
2733
|
const bareChoiceProps = [];
|
|
2663
2734
|
const containersWithUnion = /* @__PURE__ */ new Set();
|
|
2735
|
+
function operandIsRawString(node) {
|
|
2736
|
+
if (services === null) {
|
|
2737
|
+
return false;
|
|
2738
|
+
}
|
|
2739
|
+
return typeHasRawString(services.getTypeAtLocation(node));
|
|
2740
|
+
}
|
|
2664
2741
|
function pushScope() {
|
|
2665
|
-
scopeStack.push(/* @__PURE__ */ new Map());
|
|
2742
|
+
scopeStack.push({ clusters: /* @__PURE__ */ new Map() });
|
|
2666
2743
|
}
|
|
2667
2744
|
function popScope() {
|
|
2668
|
-
const
|
|
2669
|
-
if (
|
|
2745
|
+
const scope = scopeStack.pop();
|
|
2746
|
+
if (scope === void 0) {
|
|
2670
2747
|
return;
|
|
2671
2748
|
}
|
|
2672
|
-
for (const entry of clusters.values()) {
|
|
2749
|
+
for (const entry of scope.clusters.values()) {
|
|
2673
2750
|
if (entry.allTokens && entry.literals.size >= MIN_CLUSTER_SIZE) {
|
|
2674
2751
|
validClusters.push(entry.node);
|
|
2675
2752
|
}
|
|
@@ -2680,10 +2757,10 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
2680
2757
|
if (scope === void 0) {
|
|
2681
2758
|
return;
|
|
2682
2759
|
}
|
|
2683
|
-
const allTokens = literals.every((lit) =>
|
|
2684
|
-
const existing = scope.get(key);
|
|
2760
|
+
const allTokens = literals.every((lit) => isEnumToken(lit));
|
|
2761
|
+
const existing = scope.clusters.get(key);
|
|
2685
2762
|
if (existing === void 0) {
|
|
2686
|
-
scope.set(key, {
|
|
2763
|
+
scope.clusters.set(key, {
|
|
2687
2764
|
node,
|
|
2688
2765
|
literals: new Set(literals),
|
|
2689
2766
|
allTokens
|
|
@@ -2725,14 +2802,18 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
2725
2802
|
const rightKey = refKey(node.right);
|
|
2726
2803
|
const leftLit = strLiteral(node.left);
|
|
2727
2804
|
if (leftKey !== null && rightLit !== null) {
|
|
2728
|
-
|
|
2805
|
+
if (operandIsRawString(node.left)) {
|
|
2806
|
+
accumulate(leftKey, [rightLit], node);
|
|
2807
|
+
}
|
|
2729
2808
|
} else if (rightKey !== null && leftLit !== null) {
|
|
2730
|
-
|
|
2809
|
+
if (operandIsRawString(node.right)) {
|
|
2810
|
+
accumulate(rightKey, [leftLit], node);
|
|
2811
|
+
}
|
|
2731
2812
|
}
|
|
2732
2813
|
},
|
|
2733
2814
|
SwitchStatement(node) {
|
|
2734
2815
|
const key = refKey(node.discriminant);
|
|
2735
|
-
if (key === null) {
|
|
2816
|
+
if (key === null || !operandIsRawString(node.discriminant)) {
|
|
2736
2817
|
return;
|
|
2737
2818
|
}
|
|
2738
2819
|
const literals = [];
|
|
@@ -2971,7 +3052,7 @@ var rules = {
|
|
|
2971
3052
|
var plugin = {
|
|
2972
3053
|
meta: {
|
|
2973
3054
|
name: "@sarj/eslint-plugin",
|
|
2974
|
-
version: "2.3.
|
|
3055
|
+
version: "2.3.3"
|
|
2975
3056
|
},
|
|
2976
3057
|
rules,
|
|
2977
3058
|
configs: {
|