@sarj/eslint-plugin 2.3.0 → 2.3.2
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 +194 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.js +174 -135
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2235,7 +2235,15 @@ var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
2235
2235
|
"Object",
|
|
2236
2236
|
"Headers",
|
|
2237
2237
|
"URLSearchParams",
|
|
2238
|
-
"FormData"
|
|
2238
|
+
"FormData",
|
|
2239
|
+
"TextEncoder",
|
|
2240
|
+
"TextDecoder",
|
|
2241
|
+
"Blob",
|
|
2242
|
+
"ReadableStream",
|
|
2243
|
+
"WritableStream",
|
|
2244
|
+
"TransformStream",
|
|
2245
|
+
"Response",
|
|
2246
|
+
"AbortController"
|
|
2239
2247
|
]);
|
|
2240
2248
|
function isNode3(value) {
|
|
2241
2249
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -2425,7 +2433,49 @@ var INNOCUOUS_WORDS = /* @__PURE__ */ new Set([
|
|
|
2425
2433
|
"invalid",
|
|
2426
2434
|
"exists",
|
|
2427
2435
|
"type",
|
|
2428
|
-
"types"
|
|
2436
|
+
"types",
|
|
2437
|
+
"name",
|
|
2438
|
+
"names",
|
|
2439
|
+
"label",
|
|
2440
|
+
"labels",
|
|
2441
|
+
"title",
|
|
2442
|
+
"expiry",
|
|
2443
|
+
"expiration",
|
|
2444
|
+
"expires",
|
|
2445
|
+
"ttl",
|
|
2446
|
+
"version",
|
|
2447
|
+
"versions",
|
|
2448
|
+
"policy",
|
|
2449
|
+
"rotation",
|
|
2450
|
+
"arn",
|
|
2451
|
+
"path",
|
|
2452
|
+
"paths",
|
|
2453
|
+
"issuer",
|
|
2454
|
+
"audience",
|
|
2455
|
+
"strength",
|
|
2456
|
+
"manager",
|
|
2457
|
+
"service",
|
|
2458
|
+
"services",
|
|
2459
|
+
"repository",
|
|
2460
|
+
"provider",
|
|
2461
|
+
"providers",
|
|
2462
|
+
"store",
|
|
2463
|
+
"factory",
|
|
2464
|
+
"handler",
|
|
2465
|
+
"controller",
|
|
2466
|
+
"bucket",
|
|
2467
|
+
"url",
|
|
2468
|
+
"uri",
|
|
2469
|
+
"endpoint",
|
|
2470
|
+
"endpoints",
|
|
2471
|
+
"scope",
|
|
2472
|
+
"scopes",
|
|
2473
|
+
"event",
|
|
2474
|
+
"events",
|
|
2475
|
+
"format",
|
|
2476
|
+
"at",
|
|
2477
|
+
"len",
|
|
2478
|
+
"length"
|
|
2429
2479
|
]);
|
|
2430
2480
|
var REDACTION_RE = /prefix|suffix|redact|mask|hash|hint|_len|length/i;
|
|
2431
2481
|
var WHOLE_TOKEN_REDACTION_MARKERS = /* @__PURE__ */ new Set(["tag"]);
|
|
@@ -2500,6 +2550,12 @@ function isLoggerExpr(expr) {
|
|
|
2500
2550
|
return false;
|
|
2501
2551
|
}
|
|
2502
2552
|
}
|
|
2553
|
+
function isRawSecretValue(prop) {
|
|
2554
|
+
if (prop.shorthand) {
|
|
2555
|
+
return true;
|
|
2556
|
+
}
|
|
2557
|
+
return prop.value.type === "Identifier" || prop.value.type === "MemberExpression";
|
|
2558
|
+
}
|
|
2503
2559
|
function propertyKeyName2(prop) {
|
|
2504
2560
|
if (prop.computed) {
|
|
2505
2561
|
return null;
|
|
@@ -2554,7 +2610,7 @@ var no_secret_in_log_default = import_utils24.ESLintUtils.RuleCreator(
|
|
|
2554
2610
|
continue;
|
|
2555
2611
|
}
|
|
2556
2612
|
const keyName2 = propertyKeyName2(prop);
|
|
2557
|
-
if (keyName2 !== null && isSecretKeyword(keyName2)) {
|
|
2613
|
+
if (keyName2 !== null && isSecretKeyword(keyName2) && isRawSecretValue(prop)) {
|
|
2558
2614
|
context.report({
|
|
2559
2615
|
node: prop,
|
|
2560
2616
|
messageId: "noSecretInLog",
|
|
@@ -2569,119 +2625,8 @@ var no_secret_in_log_default = import_utils24.ESLintUtils.RuleCreator(
|
|
|
2569
2625
|
}
|
|
2570
2626
|
});
|
|
2571
2627
|
|
|
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
2628
|
// src/rules/prefer-string-literal-union.ts
|
|
2684
|
-
var
|
|
2629
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
2685
2630
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
2686
2631
|
"status",
|
|
2687
2632
|
"state",
|
|
@@ -2698,6 +2643,10 @@ var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
|
2698
2643
|
]);
|
|
2699
2644
|
var LOWER_TOKEN_RE = /^[a-z][a-z0-9_-]{0,30}$/;
|
|
2700
2645
|
var MIN_CLUSTER_SIZE = 2;
|
|
2646
|
+
var BOOLEANISH = /* @__PURE__ */ new Set(["true", "false"]);
|
|
2647
|
+
function isEnumToken(lit) {
|
|
2648
|
+
return LOWER_TOKEN_RE.test(lit) && lit.length >= 2 && !BOOLEANISH.has(lit);
|
|
2649
|
+
}
|
|
2701
2650
|
var IGNORE_PATTERNS = [
|
|
2702
2651
|
/[\\/]generated[\\/]/,
|
|
2703
2652
|
/\.gen\.tsx?$/,
|
|
@@ -2719,30 +2668,105 @@ function isChoiceLikeName(name) {
|
|
|
2719
2668
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
2720
2669
|
}
|
|
2721
2670
|
function keyName(key) {
|
|
2722
|
-
if (key.type ===
|
|
2671
|
+
if (key.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
2723
2672
|
return key.name;
|
|
2724
2673
|
}
|
|
2725
|
-
if (key.type ===
|
|
2674
|
+
if (key.type === import_utils25.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
2726
2675
|
return key.value;
|
|
2727
2676
|
}
|
|
2728
2677
|
return null;
|
|
2729
2678
|
}
|
|
2679
|
+
function isStringLiteralMember(t) {
|
|
2680
|
+
return t.type === import_utils25.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils25.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
|
|
2681
|
+
}
|
|
2730
2682
|
function isStringLiteralUnion(node) {
|
|
2731
|
-
if (node?.type !==
|
|
2683
|
+
if (node?.type !== import_utils25.AST_NODE_TYPES.TSUnionType) {
|
|
2732
2684
|
return false;
|
|
2733
2685
|
}
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
return
|
|
2686
|
+
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
2687
|
+
}
|
|
2688
|
+
function isLikelyClosedUnion(node) {
|
|
2689
|
+
return node?.type === import_utils25.AST_NODE_TYPES.TSUnionType && node.types.some(isStringLiteralMember);
|
|
2690
|
+
}
|
|
2691
|
+
function unionMemberNames(typeNode, out) {
|
|
2692
|
+
if (typeNode === void 0) {
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
if (typeNode.type === import_utils25.AST_NODE_TYPES.TSIntersectionType || typeNode.type === import_utils25.AST_NODE_TYPES.TSUnionType) {
|
|
2696
|
+
for (const t of typeNode.types) {
|
|
2697
|
+
unionMemberNames(t, out);
|
|
2698
|
+
}
|
|
2699
|
+
return;
|
|
2700
|
+
}
|
|
2701
|
+
if (typeNode.type !== import_utils25.AST_NODE_TYPES.TSTypeLiteral) {
|
|
2702
|
+
return;
|
|
2703
|
+
}
|
|
2704
|
+
for (const member of typeNode.members) {
|
|
2705
|
+
if (member.type === import_utils25.AST_NODE_TYPES.TSPropertySignature && isLikelyClosedUnion(member.typeAnnotation?.typeAnnotation)) {
|
|
2706
|
+
const propName2 = keyName(member.key);
|
|
2707
|
+
if (propName2 !== null) {
|
|
2708
|
+
out.add(propName2);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
function bindingName(node) {
|
|
2714
|
+
const id = node.type === import_utils25.AST_NODE_TYPES.AssignmentPattern ? node.left : node;
|
|
2715
|
+
return id.type === import_utils25.AST_NODE_TYPES.Identifier ? id.name : null;
|
|
2716
|
+
}
|
|
2717
|
+
function addUnionRefsFromBinding(param, out) {
|
|
2718
|
+
const binding = param.type === import_utils25.AST_NODE_TYPES.AssignmentPattern ? param.left : param;
|
|
2719
|
+
if (binding.type === import_utils25.AST_NODE_TYPES.ObjectPattern) {
|
|
2720
|
+
const members = /* @__PURE__ */ new Set();
|
|
2721
|
+
unionMemberNames(binding.typeAnnotation?.typeAnnotation, members);
|
|
2722
|
+
if (members.size === 0) {
|
|
2723
|
+
return;
|
|
2724
|
+
}
|
|
2725
|
+
for (const prop of binding.properties) {
|
|
2726
|
+
if (prop.type !== import_utils25.AST_NODE_TYPES.Property) {
|
|
2727
|
+
continue;
|
|
2728
|
+
}
|
|
2729
|
+
const propKey = keyName(prop.key);
|
|
2730
|
+
const local = bindingName(prop.value);
|
|
2731
|
+
if (propKey !== null && local !== null && members.has(propKey)) {
|
|
2732
|
+
out.add(local);
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
if (binding.type !== import_utils25.AST_NODE_TYPES.Identifier) {
|
|
2738
|
+
return;
|
|
2739
|
+
}
|
|
2740
|
+
const typeNode = binding.typeAnnotation?.typeAnnotation;
|
|
2741
|
+
if (isLikelyClosedUnion(typeNode)) {
|
|
2742
|
+
out.add(binding.name);
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2745
|
+
if (typeNode?.type === import_utils25.AST_NODE_TYPES.TSTypeLiteral) {
|
|
2746
|
+
for (const member of typeNode.members) {
|
|
2747
|
+
if (member.type === import_utils25.AST_NODE_TYPES.TSPropertySignature && isLikelyClosedUnion(member.typeAnnotation?.typeAnnotation)) {
|
|
2748
|
+
const propName2 = keyName(member.key);
|
|
2749
|
+
if (propName2 !== null) {
|
|
2750
|
+
out.add(`${binding.name}.${propName2}`);
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
function unionRefsFromParams(fn) {
|
|
2757
|
+
const out = /* @__PURE__ */ new Set();
|
|
2758
|
+
for (const param of fn.params) {
|
|
2759
|
+
addUnionRefsFromBinding(param, out);
|
|
2760
|
+
}
|
|
2761
|
+
return out;
|
|
2738
2762
|
}
|
|
2739
2763
|
function refKey(node) {
|
|
2740
|
-
if (node.type ===
|
|
2764
|
+
if (node.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
2741
2765
|
return node.name;
|
|
2742
2766
|
}
|
|
2743
|
-
if (node.type ===
|
|
2767
|
+
if (node.type === import_utils25.AST_NODE_TYPES.MemberExpression && !node.computed) {
|
|
2744
2768
|
const inner = refKey(node.object);
|
|
2745
|
-
if (inner === null || node.property.type !==
|
|
2769
|
+
if (inner === null || node.property.type !== import_utils25.AST_NODE_TYPES.Identifier) {
|
|
2746
2770
|
return null;
|
|
2747
2771
|
}
|
|
2748
2772
|
return `${inner}.${node.property.name}`;
|
|
@@ -2750,12 +2774,12 @@ function refKey(node) {
|
|
|
2750
2774
|
return null;
|
|
2751
2775
|
}
|
|
2752
2776
|
function strLiteral(node) {
|
|
2753
|
-
if (node.type ===
|
|
2777
|
+
if (node.type === import_utils25.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
2754
2778
|
return node.value;
|
|
2755
2779
|
}
|
|
2756
2780
|
return null;
|
|
2757
2781
|
}
|
|
2758
|
-
var prefer_string_literal_union_default =
|
|
2782
|
+
var prefer_string_literal_union_default = import_utils25.ESLintUtils.RuleCreator(
|
|
2759
2783
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
2760
2784
|
)({
|
|
2761
2785
|
name: "prefer-string-literal-union",
|
|
@@ -2781,16 +2805,25 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
|
|
|
2781
2805
|
const validClusters = [];
|
|
2782
2806
|
const bareChoiceProps = [];
|
|
2783
2807
|
const containersWithUnion = /* @__PURE__ */ new Set();
|
|
2784
|
-
function pushScope() {
|
|
2785
|
-
scopeStack.push(
|
|
2808
|
+
function pushScope(fn) {
|
|
2809
|
+
scopeStack.push({
|
|
2810
|
+
clusters: /* @__PURE__ */ new Map(),
|
|
2811
|
+
unionRefs: unionRefsFromParams(fn)
|
|
2812
|
+
});
|
|
2813
|
+
}
|
|
2814
|
+
function isUnionTypedRef(key, current) {
|
|
2815
|
+
if (current.has(key)) {
|
|
2816
|
+
return true;
|
|
2817
|
+
}
|
|
2818
|
+
return scopeStack.some((s) => s.unionRefs.has(key));
|
|
2786
2819
|
}
|
|
2787
2820
|
function popScope() {
|
|
2788
|
-
const
|
|
2789
|
-
if (
|
|
2821
|
+
const scope = scopeStack.pop();
|
|
2822
|
+
if (scope === void 0) {
|
|
2790
2823
|
return;
|
|
2791
2824
|
}
|
|
2792
|
-
for (const entry of clusters
|
|
2793
|
-
if (entry.allTokens && entry.literals.size >= MIN_CLUSTER_SIZE) {
|
|
2825
|
+
for (const [key, entry] of scope.clusters) {
|
|
2826
|
+
if (entry.allTokens && entry.literals.size >= MIN_CLUSTER_SIZE && !isUnionTypedRef(key, scope.unionRefs)) {
|
|
2794
2827
|
validClusters.push(entry.node);
|
|
2795
2828
|
}
|
|
2796
2829
|
}
|
|
@@ -2800,10 +2833,10 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
|
|
|
2800
2833
|
if (scope === void 0) {
|
|
2801
2834
|
return;
|
|
2802
2835
|
}
|
|
2803
|
-
const allTokens = literals.every((lit) =>
|
|
2804
|
-
const existing = scope.get(key);
|
|
2836
|
+
const allTokens = literals.every((lit) => isEnumToken(lit));
|
|
2837
|
+
const existing = scope.clusters.get(key);
|
|
2805
2838
|
if (existing === void 0) {
|
|
2806
|
-
scope.set(key, {
|
|
2839
|
+
scope.clusters.set(key, {
|
|
2807
2840
|
node,
|
|
2808
2841
|
literals: new Set(literals),
|
|
2809
2842
|
allTokens
|
|
@@ -2820,7 +2853,7 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
|
|
|
2820
2853
|
containersWithUnion.add(container);
|
|
2821
2854
|
return;
|
|
2822
2855
|
}
|
|
2823
|
-
if (typeNode?.type !==
|
|
2856
|
+
if (typeNode?.type !== import_utils25.AST_NODE_TYPES.TSStringKeyword) {
|
|
2824
2857
|
return;
|
|
2825
2858
|
}
|
|
2826
2859
|
const name = keyName(key);
|
|
@@ -2836,6 +2869,15 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
|
|
|
2836
2869
|
"FunctionExpression:exit": popScope,
|
|
2837
2870
|
ArrowFunctionExpression: pushScope,
|
|
2838
2871
|
"ArrowFunctionExpression:exit": popScope,
|
|
2872
|
+
VariableDeclarator(node) {
|
|
2873
|
+
const scope = scopeStack[scopeStack.length - 1];
|
|
2874
|
+
if (scope === void 0 || node.id.type !== import_utils25.AST_NODE_TYPES.Identifier) {
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2877
|
+
if (isLikelyClosedUnion(node.id.typeAnnotation?.typeAnnotation)) {
|
|
2878
|
+
scope.unionRefs.add(node.id.name);
|
|
2879
|
+
}
|
|
2880
|
+
},
|
|
2839
2881
|
BinaryExpression(node) {
|
|
2840
2882
|
if (node.operator !== "===" && node.operator !== "!==" && node.operator !== "==" && node.operator !== "!=") {
|
|
2841
2883
|
return;
|
|
@@ -2904,10 +2946,10 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
|
|
|
2904
2946
|
}
|
|
2905
2947
|
};
|
|
2906
2948
|
function refKeyText(node) {
|
|
2907
|
-
if (node.type ===
|
|
2949
|
+
if (node.type === import_utils25.AST_NODE_TYPES.BinaryExpression) {
|
|
2908
2950
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
2909
2951
|
}
|
|
2910
|
-
if (node.type ===
|
|
2952
|
+
if (node.type === import_utils25.AST_NODE_TYPES.SwitchStatement) {
|
|
2911
2953
|
return refKey(node.discriminant) ?? "value";
|
|
2912
2954
|
}
|
|
2913
2955
|
return "value";
|
|
@@ -2916,7 +2958,7 @@ var prefer_string_literal_union_default = import_utils26.ESLintUtils.RuleCreator
|
|
|
2916
2958
|
});
|
|
2917
2959
|
|
|
2918
2960
|
// src/rules/single-public-export.ts
|
|
2919
|
-
var
|
|
2961
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
2920
2962
|
var JUNK_DRAWER_STEMS = /* @__PURE__ */ new Set([
|
|
2921
2963
|
"util",
|
|
2922
2964
|
"utils",
|
|
@@ -2950,12 +2992,12 @@ var kebabCase = (name) => {
|
|
|
2950
2992
|
}
|
|
2951
2993
|
return normalized.replace(CAMEL_BOUNDARY_RE, "-").toLowerCase();
|
|
2952
2994
|
};
|
|
2953
|
-
var isFunctionExpression2 = (node) => node !== null && (node.type ===
|
|
2995
|
+
var isFunctionExpression2 = (node) => node !== null && (node.type === import_utils26.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils26.AST_NODE_TYPES.FunctionExpression);
|
|
2954
2996
|
var functionConstName = (decl) => {
|
|
2955
2997
|
if (decl.declarations.length !== 1) return null;
|
|
2956
2998
|
const [declarator] = decl.declarations;
|
|
2957
2999
|
if (declarator === void 0) return null;
|
|
2958
|
-
if (declarator.id.type !==
|
|
3000
|
+
if (declarator.id.type !== import_utils26.AST_NODE_TYPES.Identifier) return null;
|
|
2959
3001
|
if (!isFunctionExpression2(declarator.init)) return null;
|
|
2960
3002
|
return declarator.id.name;
|
|
2961
3003
|
};
|
|
@@ -2969,20 +3011,20 @@ var summarizeExports = (body) => {
|
|
|
2969
3011
|
};
|
|
2970
3012
|
for (const statement of body) {
|
|
2971
3013
|
switch (statement.type) {
|
|
2972
|
-
case
|
|
3014
|
+
case import_utils26.AST_NODE_TYPES.ExportAllDeclaration:
|
|
2973
3015
|
hasReExport = true;
|
|
2974
3016
|
break;
|
|
2975
|
-
case
|
|
3017
|
+
case import_utils26.AST_NODE_TYPES.ExportDefaultDeclaration: {
|
|
2976
3018
|
names += 1;
|
|
2977
3019
|
const decl = statement.declaration;
|
|
2978
|
-
if (decl.type ===
|
|
3020
|
+
if (decl.type === import_utils26.AST_NODE_TYPES.FunctionDeclaration && decl.id !== null) {
|
|
2979
3021
|
candidate = { name: decl.id.name, node: statement };
|
|
2980
|
-
} else if (decl.type ===
|
|
3022
|
+
} else if (decl.type === import_utils26.AST_NODE_TYPES.ClassDeclaration && decl.id !== null) {
|
|
2981
3023
|
candidate = { name: decl.id.name, node: statement };
|
|
2982
3024
|
}
|
|
2983
3025
|
break;
|
|
2984
3026
|
}
|
|
2985
|
-
case
|
|
3027
|
+
case import_utils26.AST_NODE_TYPES.ExportNamedDeclaration: {
|
|
2986
3028
|
if (statement.source !== null) {
|
|
2987
3029
|
hasReExport = true;
|
|
2988
3030
|
break;
|
|
@@ -2993,15 +3035,15 @@ var summarizeExports = (body) => {
|
|
|
2993
3035
|
break;
|
|
2994
3036
|
}
|
|
2995
3037
|
switch (decl.type) {
|
|
2996
|
-
case
|
|
3038
|
+
case import_utils26.AST_NODE_TYPES.FunctionDeclaration:
|
|
2997
3039
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
2998
3040
|
else names += 1;
|
|
2999
3041
|
break;
|
|
3000
|
-
case
|
|
3042
|
+
case import_utils26.AST_NODE_TYPES.ClassDeclaration:
|
|
3001
3043
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
3002
3044
|
else names += 1;
|
|
3003
3045
|
break;
|
|
3004
|
-
case
|
|
3046
|
+
case import_utils26.AST_NODE_TYPES.VariableDeclaration: {
|
|
3005
3047
|
const fnName = functionConstName(decl);
|
|
3006
3048
|
if (fnName !== null && decl.declarations.length === 1) {
|
|
3007
3049
|
addCandidate(fnName, statement);
|
|
@@ -3021,7 +3063,7 @@ var summarizeExports = (body) => {
|
|
|
3021
3063
|
}
|
|
3022
3064
|
return { names, hasReExport, candidate };
|
|
3023
3065
|
};
|
|
3024
|
-
var single_public_export_default =
|
|
3066
|
+
var single_public_export_default = import_utils26.ESLintUtils.RuleCreator(
|
|
3025
3067
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3026
3068
|
)({
|
|
3027
3069
|
name: "single-public-export",
|
|
@@ -3085,14 +3127,13 @@ var rules = {
|
|
|
3085
3127
|
"no-cors-wildcard-with-credentials": no_cors_wildcard_with_credentials_default,
|
|
3086
3128
|
"no-fat-try-blocks": no_fat_try_blocks_default,
|
|
3087
3129
|
"no-secret-in-log": no_secret_in_log_default,
|
|
3088
|
-
"no-template-literal-in-log": no_template_literal_in_log_default,
|
|
3089
3130
|
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
3090
3131
|
"single-public-export": single_public_export_default
|
|
3091
3132
|
};
|
|
3092
3133
|
var plugin = {
|
|
3093
3134
|
meta: {
|
|
3094
3135
|
name: "@sarj/eslint-plugin",
|
|
3095
|
-
version: "2.3.
|
|
3136
|
+
version: "2.3.2"
|
|
3096
3137
|
},
|
|
3097
3138
|
rules,
|
|
3098
3139
|
configs: {
|
|
@@ -3121,7 +3162,6 @@ var plugin = {
|
|
|
3121
3162
|
// Ported from sarj-python-lint (SARJ), corpus-validated FP~0.
|
|
3122
3163
|
"@sarj/no-fat-try-blocks": "warn",
|
|
3123
3164
|
"@sarj/no-cors-wildcard-with-credentials": "warn",
|
|
3124
|
-
"@sarj/no-template-literal-in-log": "warn",
|
|
3125
3165
|
"@sarj/no-secret-in-log": "warn",
|
|
3126
3166
|
"@sarj/single-public-export": "warn",
|
|
3127
3167
|
"@sarj/prefer-string-literal-union": "warn"
|
|
@@ -3156,7 +3196,6 @@ var plugin = {
|
|
|
3156
3196
|
// Ported from sarj-python-lint (SARJ), corpus-validated FP~0.
|
|
3157
3197
|
"@sarj/no-fat-try-blocks": "error",
|
|
3158
3198
|
"@sarj/no-cors-wildcard-with-credentials": "error",
|
|
3159
|
-
"@sarj/no-template-literal-in-log": "error",
|
|
3160
3199
|
"@sarj/no-secret-in-log": "error",
|
|
3161
3200
|
"@sarj/single-public-export": "error",
|
|
3162
3201
|
// High-volume/stylistic — warn until rollout proves FP rate.
|