@sarj/eslint-plugin 2.3.3 → 2.3.4
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 +54 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2681,6 +2681,25 @@ function typeHasRawString(type) {
|
|
|
2681
2681
|
const parts = type.isUnion() ? type.types : [type];
|
|
2682
2682
|
return parts.some((t) => (t.flags & ts.TypeFlags.String) !== 0);
|
|
2683
2683
|
}
|
|
2684
|
+
function isExternalSourceFile(sf) {
|
|
2685
|
+
if (sf === void 0) {
|
|
2686
|
+
return false;
|
|
2687
|
+
}
|
|
2688
|
+
return sf.isDeclarationFile || sf.fileName.includes("/node_modules/");
|
|
2689
|
+
}
|
|
2690
|
+
function symbolIsExternallyDeclared(sym) {
|
|
2691
|
+
return sym?.declarations?.some((d) => isExternalSourceFile(d.getSourceFile())) ?? false;
|
|
2692
|
+
}
|
|
2693
|
+
function bindingSourceExpression(decl) {
|
|
2694
|
+
let node = decl.parent;
|
|
2695
|
+
while (!ts.isForOfStatement(node) && !(ts.isVariableDeclaration(node) && node.initializer !== void 0)) {
|
|
2696
|
+
if (node.parent === void 0) {
|
|
2697
|
+
return void 0;
|
|
2698
|
+
}
|
|
2699
|
+
node = node.parent;
|
|
2700
|
+
}
|
|
2701
|
+
return ts.isForOfStatement(node) ? node.expression : node.initializer;
|
|
2702
|
+
}
|
|
2684
2703
|
function refKey(node) {
|
|
2685
2704
|
if (node.type === AST_NODE_TYPES12.Identifier) {
|
|
2686
2705
|
return node.name;
|
|
@@ -2738,6 +2757,37 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
2738
2757
|
}
|
|
2739
2758
|
return typeHasRawString(services.getTypeAtLocation(node));
|
|
2740
2759
|
}
|
|
2760
|
+
function originIsExternal(node, depth) {
|
|
2761
|
+
if (node === void 0 || services === null || depth > 6) {
|
|
2762
|
+
return false;
|
|
2763
|
+
}
|
|
2764
|
+
const checker = services.program.getTypeChecker();
|
|
2765
|
+
if (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node) || ts.isAsExpression(node)) {
|
|
2766
|
+
return originIsExternal(node.expression, depth + 1);
|
|
2767
|
+
}
|
|
2768
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
2769
|
+
return symbolIsExternallyDeclared(checker.getSymbolAtLocation(node.name));
|
|
2770
|
+
}
|
|
2771
|
+
if (ts.isCallExpression(node)) {
|
|
2772
|
+
return originIsExternal(node.expression, depth + 1);
|
|
2773
|
+
}
|
|
2774
|
+
if (ts.isIdentifier(node)) {
|
|
2775
|
+
const decl = checker.getSymbolAtLocation(node)?.valueDeclaration;
|
|
2776
|
+
if (decl === void 0) {
|
|
2777
|
+
return false;
|
|
2778
|
+
}
|
|
2779
|
+
if (ts.isVariableDeclaration(decl) && decl.initializer !== void 0) {
|
|
2780
|
+
return originIsExternal(decl.initializer, depth + 1);
|
|
2781
|
+
}
|
|
2782
|
+
if (ts.isBindingElement(decl)) {
|
|
2783
|
+
return originIsExternal(bindingSourceExpression(decl), depth + 1);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
return false;
|
|
2787
|
+
}
|
|
2788
|
+
function operandIsFlaggable(node) {
|
|
2789
|
+
return operandIsRawString(node) && !originIsExternal(services?.esTreeNodeToTSNodeMap.get(node), 0);
|
|
2790
|
+
}
|
|
2741
2791
|
function pushScope() {
|
|
2742
2792
|
scopeStack.push({ clusters: /* @__PURE__ */ new Map() });
|
|
2743
2793
|
}
|
|
@@ -2802,18 +2852,18 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
2802
2852
|
const rightKey = refKey(node.right);
|
|
2803
2853
|
const leftLit = strLiteral(node.left);
|
|
2804
2854
|
if (leftKey !== null && rightLit !== null) {
|
|
2805
|
-
if (
|
|
2855
|
+
if (operandIsFlaggable(node.left)) {
|
|
2806
2856
|
accumulate(leftKey, [rightLit], node);
|
|
2807
2857
|
}
|
|
2808
2858
|
} else if (rightKey !== null && leftLit !== null) {
|
|
2809
|
-
if (
|
|
2859
|
+
if (operandIsFlaggable(node.right)) {
|
|
2810
2860
|
accumulate(rightKey, [leftLit], node);
|
|
2811
2861
|
}
|
|
2812
2862
|
}
|
|
2813
2863
|
},
|
|
2814
2864
|
SwitchStatement(node) {
|
|
2815
2865
|
const key = refKey(node.discriminant);
|
|
2816
|
-
if (key === null || !
|
|
2866
|
+
if (key === null || !operandIsFlaggable(node.discriminant)) {
|
|
2817
2867
|
return;
|
|
2818
2868
|
}
|
|
2819
2869
|
const literals = [];
|
|
@@ -3052,7 +3102,7 @@ var rules = {
|
|
|
3052
3102
|
var plugin = {
|
|
3053
3103
|
meta: {
|
|
3054
3104
|
name: "@sarj/eslint-plugin",
|
|
3055
|
-
version: "2.3.
|
|
3105
|
+
version: "2.3.4"
|
|
3056
3106
|
},
|
|
3057
3107
|
rules,
|
|
3058
3108
|
configs: {
|