@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.cjs
CHANGED
|
@@ -2700,6 +2700,25 @@ function typeHasRawString(type) {
|
|
|
2700
2700
|
const parts = type.isUnion() ? type.types : [type];
|
|
2701
2701
|
return parts.some((t) => (t.flags & ts.TypeFlags.String) !== 0);
|
|
2702
2702
|
}
|
|
2703
|
+
function isExternalSourceFile(sf) {
|
|
2704
|
+
if (sf === void 0) {
|
|
2705
|
+
return false;
|
|
2706
|
+
}
|
|
2707
|
+
return sf.isDeclarationFile || sf.fileName.includes("/node_modules/");
|
|
2708
|
+
}
|
|
2709
|
+
function symbolIsExternallyDeclared(sym) {
|
|
2710
|
+
return sym?.declarations?.some((d) => isExternalSourceFile(d.getSourceFile())) ?? false;
|
|
2711
|
+
}
|
|
2712
|
+
function bindingSourceExpression(decl) {
|
|
2713
|
+
let node = decl.parent;
|
|
2714
|
+
while (!ts.isForOfStatement(node) && !(ts.isVariableDeclaration(node) && node.initializer !== void 0)) {
|
|
2715
|
+
if (node.parent === void 0) {
|
|
2716
|
+
return void 0;
|
|
2717
|
+
}
|
|
2718
|
+
node = node.parent;
|
|
2719
|
+
}
|
|
2720
|
+
return ts.isForOfStatement(node) ? node.expression : node.initializer;
|
|
2721
|
+
}
|
|
2703
2722
|
function refKey(node) {
|
|
2704
2723
|
if (node.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
2705
2724
|
return node.name;
|
|
@@ -2757,6 +2776,37 @@ var prefer_string_literal_union_default = import_utils25.ESLintUtils.RuleCreator
|
|
|
2757
2776
|
}
|
|
2758
2777
|
return typeHasRawString(services.getTypeAtLocation(node));
|
|
2759
2778
|
}
|
|
2779
|
+
function originIsExternal(node, depth) {
|
|
2780
|
+
if (node === void 0 || services === null || depth > 6) {
|
|
2781
|
+
return false;
|
|
2782
|
+
}
|
|
2783
|
+
const checker = services.program.getTypeChecker();
|
|
2784
|
+
if (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node) || ts.isAsExpression(node)) {
|
|
2785
|
+
return originIsExternal(node.expression, depth + 1);
|
|
2786
|
+
}
|
|
2787
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
2788
|
+
return symbolIsExternallyDeclared(checker.getSymbolAtLocation(node.name));
|
|
2789
|
+
}
|
|
2790
|
+
if (ts.isCallExpression(node)) {
|
|
2791
|
+
return originIsExternal(node.expression, depth + 1);
|
|
2792
|
+
}
|
|
2793
|
+
if (ts.isIdentifier(node)) {
|
|
2794
|
+
const decl = checker.getSymbolAtLocation(node)?.valueDeclaration;
|
|
2795
|
+
if (decl === void 0) {
|
|
2796
|
+
return false;
|
|
2797
|
+
}
|
|
2798
|
+
if (ts.isVariableDeclaration(decl) && decl.initializer !== void 0) {
|
|
2799
|
+
return originIsExternal(decl.initializer, depth + 1);
|
|
2800
|
+
}
|
|
2801
|
+
if (ts.isBindingElement(decl)) {
|
|
2802
|
+
return originIsExternal(bindingSourceExpression(decl), depth + 1);
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
return false;
|
|
2806
|
+
}
|
|
2807
|
+
function operandIsFlaggable(node) {
|
|
2808
|
+
return operandIsRawString(node) && !originIsExternal(services?.esTreeNodeToTSNodeMap.get(node), 0);
|
|
2809
|
+
}
|
|
2760
2810
|
function pushScope() {
|
|
2761
2811
|
scopeStack.push({ clusters: /* @__PURE__ */ new Map() });
|
|
2762
2812
|
}
|
|
@@ -2821,18 +2871,18 @@ var prefer_string_literal_union_default = import_utils25.ESLintUtils.RuleCreator
|
|
|
2821
2871
|
const rightKey = refKey(node.right);
|
|
2822
2872
|
const leftLit = strLiteral(node.left);
|
|
2823
2873
|
if (leftKey !== null && rightLit !== null) {
|
|
2824
|
-
if (
|
|
2874
|
+
if (operandIsFlaggable(node.left)) {
|
|
2825
2875
|
accumulate(leftKey, [rightLit], node);
|
|
2826
2876
|
}
|
|
2827
2877
|
} else if (rightKey !== null && leftLit !== null) {
|
|
2828
|
-
if (
|
|
2878
|
+
if (operandIsFlaggable(node.right)) {
|
|
2829
2879
|
accumulate(rightKey, [leftLit], node);
|
|
2830
2880
|
}
|
|
2831
2881
|
}
|
|
2832
2882
|
},
|
|
2833
2883
|
SwitchStatement(node) {
|
|
2834
2884
|
const key = refKey(node.discriminant);
|
|
2835
|
-
if (key === null || !
|
|
2885
|
+
if (key === null || !operandIsFlaggable(node.discriminant)) {
|
|
2836
2886
|
return;
|
|
2837
2887
|
}
|
|
2838
2888
|
const literals = [];
|
|
@@ -3071,7 +3121,7 @@ var rules = {
|
|
|
3071
3121
|
var plugin = {
|
|
3072
3122
|
meta: {
|
|
3073
3123
|
name: "@sarj/eslint-plugin",
|
|
3074
|
-
version: "2.3.
|
|
3124
|
+
version: "2.3.4"
|
|
3075
3125
|
},
|
|
3076
3126
|
rules,
|
|
3077
3127
|
configs: {
|