@pobammer-ts/eslint-cease-nonsense-rules 1.4.0 → 1.4.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/build-metadata.json
CHANGED
package/dist/index.js
CHANGED
|
@@ -7289,7 +7289,8 @@ function FromObject13(context, type3, value) {
|
|
|
7289
7289
|
const knownPropertyKeys = exports_guard.Keys(type3.properties);
|
|
7290
7290
|
for (const key of knownPropertyKeys) {
|
|
7291
7291
|
const propertyValue = FromType16(context, type3.properties[key], value[key]);
|
|
7292
|
-
|
|
7292
|
+
const isUnassignableUndefined = exports_guard.IsUndefined(propertyValue) && (IsOptional(type3.properties[key]) || !exports_guard.HasPropertyKey(type3.properties[key], "default"));
|
|
7293
|
+
if (isUnassignableUndefined)
|
|
7293
7294
|
continue;
|
|
7294
7295
|
value[key] = FromType16(context, type3.properties[key], value[key]);
|
|
7295
7296
|
}
|
|
@@ -10537,6 +10538,21 @@ var IS_FUNCTION_EXPRESSION = new Set([
|
|
|
10537
10538
|
TSESTree8.AST_NODE_TYPES.FunctionExpression,
|
|
10538
10539
|
TSESTree8.AST_NODE_TYPES.ArrowFunctionExpression
|
|
10539
10540
|
]);
|
|
10541
|
+
var CONTROL_FLOW_TYPES = new Set([
|
|
10542
|
+
TSESTree8.AST_NODE_TYPES.BlockStatement,
|
|
10543
|
+
TSESTree8.AST_NODE_TYPES.IfStatement,
|
|
10544
|
+
TSESTree8.AST_NODE_TYPES.SwitchStatement,
|
|
10545
|
+
TSESTree8.AST_NODE_TYPES.SwitchCase,
|
|
10546
|
+
TSESTree8.AST_NODE_TYPES.TryStatement,
|
|
10547
|
+
TSESTree8.AST_NODE_TYPES.CatchClause,
|
|
10548
|
+
TSESTree8.AST_NODE_TYPES.WhileStatement,
|
|
10549
|
+
TSESTree8.AST_NODE_TYPES.DoWhileStatement,
|
|
10550
|
+
TSESTree8.AST_NODE_TYPES.ForStatement,
|
|
10551
|
+
TSESTree8.AST_NODE_TYPES.ForInStatement,
|
|
10552
|
+
TSESTree8.AST_NODE_TYPES.ForOfStatement,
|
|
10553
|
+
TSESTree8.AST_NODE_TYPES.LabeledStatement,
|
|
10554
|
+
TSESTree8.AST_NODE_TYPES.WithStatement
|
|
10555
|
+
]);
|
|
10540
10556
|
function isTopLevelReturn(node) {
|
|
10541
10557
|
let parent = ascendPastWrappers(node.parent);
|
|
10542
10558
|
if (!parent)
|
|
@@ -10555,7 +10571,7 @@ function isTopLevelReturn(node) {
|
|
|
10555
10571
|
return false;
|
|
10556
10572
|
if (parent.type === TSESTree8.AST_NODE_TYPES.ReturnStatement) {
|
|
10557
10573
|
let currentNode = ascendPastWrappers(parent.parent);
|
|
10558
|
-
|
|
10574
|
+
while (currentNode && CONTROL_FLOW_TYPES.has(currentNode.type))
|
|
10559
10575
|
currentNode = ascendPastWrappers(currentNode.parent);
|
|
10560
10576
|
if (!currentNode)
|
|
10561
10577
|
return false;
|
|
@@ -10614,6 +10630,25 @@ function isJSXPropValue(node) {
|
|
|
10614
10630
|
}
|
|
10615
10631
|
return parent.type === TSESTree8.AST_NODE_TYPES.JSXAttribute;
|
|
10616
10632
|
}
|
|
10633
|
+
function isTernaryJSXChild(node) {
|
|
10634
|
+
let current = node.parent;
|
|
10635
|
+
if (!current)
|
|
10636
|
+
return false;
|
|
10637
|
+
let foundTernary = false;
|
|
10638
|
+
while (current && (current.type === TSESTree8.AST_NODE_TYPES.ConditionalExpression || WRAPPER_PARENT_TYPES.has(current.type))) {
|
|
10639
|
+
if (current.type === TSESTree8.AST_NODE_TYPES.ConditionalExpression)
|
|
10640
|
+
foundTernary = true;
|
|
10641
|
+
current = current.parent;
|
|
10642
|
+
}
|
|
10643
|
+
if (!foundTernary || !current)
|
|
10644
|
+
return false;
|
|
10645
|
+
if (current.type !== TSESTree8.AST_NODE_TYPES.JSXExpressionContainer)
|
|
10646
|
+
return false;
|
|
10647
|
+
const containerParent = current.parent;
|
|
10648
|
+
if (!containerParent)
|
|
10649
|
+
return false;
|
|
10650
|
+
return containerParent.type === TSESTree8.AST_NODE_TYPES.JSXElement || containerParent.type === TSESTree8.AST_NODE_TYPES.JSXFragment;
|
|
10651
|
+
}
|
|
10617
10652
|
var docs3 = {
|
|
10618
10653
|
description: "Enforce key props on all React elements except top-level returns",
|
|
10619
10654
|
recommended: true
|
|
@@ -10643,6 +10678,8 @@ var requireReactComponentKeys = {
|
|
|
10643
10678
|
return;
|
|
10644
10679
|
if (isJSXPropValue(node))
|
|
10645
10680
|
return;
|
|
10681
|
+
if (isTernaryJSXChild(node))
|
|
10682
|
+
return;
|
|
10646
10683
|
if (node.type === TSESTree8.AST_NODE_TYPES.JSXFragment) {
|
|
10647
10684
|
context.report({
|
|
10648
10685
|
messageId: "missingKey",
|
|
@@ -10816,13 +10853,16 @@ function getHookName2(node) {
|
|
|
10816
10853
|
const { callee } = node;
|
|
10817
10854
|
if (callee.type === TSESTree9.AST_NODE_TYPES.Identifier)
|
|
10818
10855
|
return callee.name;
|
|
10819
|
-
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier)
|
|
10856
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier) {
|
|
10820
10857
|
return callee.property.name;
|
|
10858
|
+
}
|
|
10821
10859
|
return;
|
|
10822
10860
|
}
|
|
10823
10861
|
function getMemberExpressionDepth(node) {
|
|
10824
10862
|
let depth = 0;
|
|
10825
10863
|
let current = node;
|
|
10864
|
+
if (current.type === TSESTree9.AST_NODE_TYPES.ChainExpression)
|
|
10865
|
+
current = current.expression;
|
|
10826
10866
|
while (current.type === TSESTree9.AST_NODE_TYPES.MemberExpression) {
|
|
10827
10867
|
depth += 1;
|
|
10828
10868
|
current = current.object;
|
|
@@ -10831,23 +10871,53 @@ function getMemberExpressionDepth(node) {
|
|
|
10831
10871
|
}
|
|
10832
10872
|
function getRootIdentifier(node) {
|
|
10833
10873
|
let current = node;
|
|
10834
|
-
|
|
10835
|
-
current = current.
|
|
10874
|
+
if (current.type === TSESTree9.AST_NODE_TYPES.ChainExpression)
|
|
10875
|
+
current = current.expression;
|
|
10876
|
+
while (current.type === TSESTree9.AST_NODE_TYPES.MemberExpression || current.type === TSESTree9.AST_NODE_TYPES.TSNonNullExpression) {
|
|
10877
|
+
if (current.type === TSESTree9.AST_NODE_TYPES.MemberExpression)
|
|
10878
|
+
current = current.object;
|
|
10879
|
+
else
|
|
10880
|
+
current = current.expression;
|
|
10881
|
+
}
|
|
10836
10882
|
return current.type === TSESTree9.AST_NODE_TYPES.Identifier ? current : undefined;
|
|
10837
10883
|
}
|
|
10838
10884
|
function nodeToDependencyString(node, sourceCode) {
|
|
10839
10885
|
return sourceCode.getText(node);
|
|
10840
10886
|
}
|
|
10887
|
+
function nodeToSafeDependencyPath(node, sourceCode) {
|
|
10888
|
+
if (node.type === TSESTree9.AST_NODE_TYPES.Identifier)
|
|
10889
|
+
return node.name;
|
|
10890
|
+
if (node.type === TSESTree9.AST_NODE_TYPES.ChainExpression) {
|
|
10891
|
+
return nodeToSafeDependencyPath(node.expression, sourceCode);
|
|
10892
|
+
}
|
|
10893
|
+
if (TS_RUNTIME_EXPRESSIONS.has(node.type)) {
|
|
10894
|
+
const expr = node;
|
|
10895
|
+
return nodeToSafeDependencyPath(expr.expression, sourceCode);
|
|
10896
|
+
}
|
|
10897
|
+
if (node.type === TSESTree9.AST_NODE_TYPES.MemberExpression) {
|
|
10898
|
+
const objectPath = nodeToSafeDependencyPath(node.object, sourceCode);
|
|
10899
|
+
if (node.computed) {
|
|
10900
|
+
const propertyText = sourceCode.getText(node.property);
|
|
10901
|
+
return `${objectPath}[${propertyText}]`;
|
|
10902
|
+
}
|
|
10903
|
+
const propertyName = node.property.type === TSESTree9.AST_NODE_TYPES.Identifier ? node.property.name : "";
|
|
10904
|
+
const separator = node.optional ? "?." : ".";
|
|
10905
|
+
return `${objectPath}${separator}${propertyName}`;
|
|
10906
|
+
}
|
|
10907
|
+
return sourceCode.getText(node);
|
|
10908
|
+
}
|
|
10841
10909
|
function isStableArrayIndex(stableResult, node, identifierName) {
|
|
10842
10910
|
if (!stableResult)
|
|
10843
10911
|
return false;
|
|
10844
|
-
if (!(stableResult instanceof Set) || node.type !== TSESTree9.AST_NODE_TYPES.VariableDeclarator || node.id.type !== TSESTree9.AST_NODE_TYPES.ArrayPattern)
|
|
10912
|
+
if (!(stableResult instanceof Set) || node.type !== TSESTree9.AST_NODE_TYPES.VariableDeclarator || node.id.type !== TSESTree9.AST_NODE_TYPES.ArrayPattern) {
|
|
10845
10913
|
return false;
|
|
10914
|
+
}
|
|
10846
10915
|
const elements = node.id.elements;
|
|
10847
10916
|
let index2 = 0;
|
|
10848
10917
|
for (const element of elements) {
|
|
10849
|
-
if (element.type === TSESTree9.AST_NODE_TYPES.Identifier && element.name === identifierName)
|
|
10918
|
+
if (element.type === TSESTree9.AST_NODE_TYPES.Identifier && element.name === identifierName) {
|
|
10850
10919
|
return stableResult.has(index2);
|
|
10920
|
+
}
|
|
10851
10921
|
index2 += 1;
|
|
10852
10922
|
}
|
|
10853
10923
|
return false;
|
|
@@ -10883,16 +10953,20 @@ function isStableValue(variable, identifierName, stableHooks) {
|
|
|
10883
10953
|
return true;
|
|
10884
10954
|
if (init?.type === TSESTree9.AST_NODE_TYPES.CallExpression) {
|
|
10885
10955
|
const { callee } = init;
|
|
10886
|
-
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.object.name === "React" && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.property.name === "joinBindings")
|
|
10956
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.object.name === "React" && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.property.name === "joinBindings") {
|
|
10887
10957
|
return true;
|
|
10888
|
-
|
|
10958
|
+
}
|
|
10959
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.property.name === "map") {
|
|
10889
10960
|
return true;
|
|
10961
|
+
}
|
|
10890
10962
|
}
|
|
10891
10963
|
if (init) {
|
|
10892
|
-
if (init.type === TSESTree9.AST_NODE_TYPES.Literal || init.type === TSESTree9.AST_NODE_TYPES.TemplateLiteral)
|
|
10964
|
+
if (init.type === TSESTree9.AST_NODE_TYPES.Literal || init.type === TSESTree9.AST_NODE_TYPES.TemplateLiteral) {
|
|
10893
10965
|
return true;
|
|
10894
|
-
|
|
10966
|
+
}
|
|
10967
|
+
if (init.type === TSESTree9.AST_NODE_TYPES.UnaryExpression && init.argument.type === TSESTree9.AST_NODE_TYPES.Literal) {
|
|
10895
10968
|
return true;
|
|
10969
|
+
}
|
|
10896
10970
|
}
|
|
10897
10971
|
const variableDefinition = variable.defs.find((definition2) => definition2.node === node);
|
|
10898
10972
|
if (variableDefinition && variableDefinition.node.type === TSESTree9.AST_NODE_TYPES.VariableDeclarator) {
|
|
@@ -10909,7 +10983,17 @@ function isStableValue(variable, identifierName, stableHooks) {
|
|
|
10909
10983
|
function findTopmostMemberExpression(node) {
|
|
10910
10984
|
let current = node;
|
|
10911
10985
|
let { parent } = node;
|
|
10912
|
-
while (parent
|
|
10986
|
+
while (parent) {
|
|
10987
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.CallExpression && parent.callee === current) {
|
|
10988
|
+
if (current.type === TSESTree9.AST_NODE_TYPES.MemberExpression)
|
|
10989
|
+
return current.object;
|
|
10990
|
+
break;
|
|
10991
|
+
}
|
|
10992
|
+
const isMemberParent = parent.type === TSESTree9.AST_NODE_TYPES.MemberExpression && parent.object === current;
|
|
10993
|
+
const isChainParent = parent.type === TSESTree9.AST_NODE_TYPES.ChainExpression;
|
|
10994
|
+
const isNonNullParent = parent.type === TSESTree9.AST_NODE_TYPES.TSNonNullExpression;
|
|
10995
|
+
if (!isMemberParent && !isChainParent && !isNonNullParent)
|
|
10996
|
+
break;
|
|
10913
10997
|
current = parent;
|
|
10914
10998
|
parent = parent.parent;
|
|
10915
10999
|
}
|
|
@@ -10921,9 +11005,24 @@ var IS_CEASE_BOUNDARY = new Set([
|
|
|
10921
11005
|
TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
10922
11006
|
TSESTree9.AST_NODE_TYPES.VariableDeclarator
|
|
10923
11007
|
]);
|
|
11008
|
+
var TS_RUNTIME_EXPRESSIONS = new Set([
|
|
11009
|
+
TSESTree9.AST_NODE_TYPES.TSNonNullExpression,
|
|
11010
|
+
TSESTree9.AST_NODE_TYPES.TSAsExpression,
|
|
11011
|
+
TSESTree9.AST_NODE_TYPES.TSSatisfiesExpression,
|
|
11012
|
+
TSESTree9.AST_NODE_TYPES.TSTypeAssertion,
|
|
11013
|
+
TSESTree9.AST_NODE_TYPES.TSInstantiationExpression
|
|
11014
|
+
]);
|
|
11015
|
+
function isComputedPropertyIdentifier(identifier3) {
|
|
11016
|
+
const parent = identifier3.parent;
|
|
11017
|
+
return parent?.type === TSESTree9.AST_NODE_TYPES.Property && parent.computed && parent.key === identifier3;
|
|
11018
|
+
}
|
|
10924
11019
|
function isInTypePosition(identifier3) {
|
|
10925
11020
|
let parent = identifier3.parent;
|
|
10926
11021
|
while (parent) {
|
|
11022
|
+
if (TS_RUNTIME_EXPRESSIONS.has(parent.type)) {
|
|
11023
|
+
parent = parent.parent;
|
|
11024
|
+
continue;
|
|
11025
|
+
}
|
|
10927
11026
|
if (parent.type.startsWith("TS"))
|
|
10928
11027
|
return true;
|
|
10929
11028
|
if (IS_CEASE_BOUNDARY.has(parent.type))
|
|
@@ -10969,10 +11068,12 @@ function resolveFunctionReference(identifier3, scope) {
|
|
|
10969
11068
|
return;
|
|
10970
11069
|
for (const definition of variable.defs) {
|
|
10971
11070
|
const { node } = definition;
|
|
10972
|
-
if (node.type === TSESTree9.AST_NODE_TYPES.FunctionDeclaration)
|
|
11071
|
+
if (node.type === TSESTree9.AST_NODE_TYPES.FunctionDeclaration) {
|
|
10973
11072
|
return node;
|
|
10974
|
-
|
|
11073
|
+
}
|
|
11074
|
+
if (node.type === TSESTree9.AST_NODE_TYPES.VariableDeclarator && node.init && (node.init.type === TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression || node.init.type === TSESTree9.AST_NODE_TYPES.FunctionExpression)) {
|
|
10975
11075
|
return node.init;
|
|
11076
|
+
}
|
|
10976
11077
|
}
|
|
10977
11078
|
return;
|
|
10978
11079
|
}
|
|
@@ -11009,9 +11110,11 @@ function collectCaptures(node, sourceCode) {
|
|
|
11009
11110
|
}
|
|
11010
11111
|
captureSet.add(name);
|
|
11011
11112
|
const depthNode = findTopmostMemberExpression(current);
|
|
11012
|
-
const usagePath =
|
|
11113
|
+
const usagePath = nodeToSafeDependencyPath(depthNode, sourceCode);
|
|
11114
|
+
const depth = getMemberExpressionDepth(depthNode);
|
|
11013
11115
|
captures.push({
|
|
11014
|
-
depth
|
|
11116
|
+
depth,
|
|
11117
|
+
forceDependency: isComputedPropertyIdentifier(current),
|
|
11015
11118
|
name,
|
|
11016
11119
|
node: depthNode,
|
|
11017
11120
|
usagePath,
|
|
@@ -11030,6 +11133,16 @@ function collectCaptures(node, sourceCode) {
|
|
|
11030
11133
|
visit(current.property);
|
|
11031
11134
|
return;
|
|
11032
11135
|
}
|
|
11136
|
+
if (current.type === TSESTree9.AST_NODE_TYPES.ChainExpression) {
|
|
11137
|
+
visit(current.expression);
|
|
11138
|
+
return;
|
|
11139
|
+
}
|
|
11140
|
+
if (current.type === TSESTree9.AST_NODE_TYPES.Property) {
|
|
11141
|
+
if (current.computed)
|
|
11142
|
+
visit(current.key);
|
|
11143
|
+
visit(current.value);
|
|
11144
|
+
return;
|
|
11145
|
+
}
|
|
11033
11146
|
const keys2 = sourceCode.visitorKeys?.[current.type] ?? [];
|
|
11034
11147
|
for (const key of keys2) {
|
|
11035
11148
|
const value = current[key];
|
|
@@ -11125,9 +11238,9 @@ var useExhaustiveDependencies = {
|
|
|
11125
11238
|
if (closureArgument === undefined)
|
|
11126
11239
|
return;
|
|
11127
11240
|
let closureFunction;
|
|
11128
|
-
if (closureArgument.type === TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression || closureArgument.type === TSESTree9.AST_NODE_TYPES.FunctionExpression)
|
|
11241
|
+
if (closureArgument.type === TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression || closureArgument.type === TSESTree9.AST_NODE_TYPES.FunctionExpression) {
|
|
11129
11242
|
closureFunction = closureArgument;
|
|
11130
|
-
else if (closureArgument.type === TSESTree9.AST_NODE_TYPES.Identifier) {
|
|
11243
|
+
} else if (closureArgument.type === TSESTree9.AST_NODE_TYPES.Identifier) {
|
|
11131
11244
|
const scope = getScope(callNode);
|
|
11132
11245
|
closureFunction = resolveFunctionReference(closureArgument, scope);
|
|
11133
11246
|
}
|
|
@@ -11136,7 +11249,7 @@ var useExhaustiveDependencies = {
|
|
|
11136
11249
|
const dependenciesArgument = parameters3[dependenciesIndex];
|
|
11137
11250
|
if (!dependenciesArgument && options3.reportMissingDependenciesArray) {
|
|
11138
11251
|
const captures2 = collectCaptures(closureFunction, context.sourceCode);
|
|
11139
|
-
const requiredCaptures = captures2.filter((capture) => !isStableValue(capture.variable, capture.name, stableHooks));
|
|
11252
|
+
const requiredCaptures = captures2.filter((capture) => capture.forceDependency || !isStableValue(capture.variable, capture.name, stableHooks));
|
|
11140
11253
|
if (requiredCaptures.length > 0) {
|
|
11141
11254
|
const missingNames = [...new Set(requiredCaptures.map(returnName))].join(", ");
|
|
11142
11255
|
const usagePaths = requiredCaptures.map(({ usagePath }) => usagePath);
|
|
@@ -11213,8 +11326,9 @@ var useExhaustiveDependencies = {
|
|
|
11213
11326
|
}
|
|
11214
11327
|
const missingCaptures = new Array;
|
|
11215
11328
|
for (const capture of captures) {
|
|
11216
|
-
if (isStableValue(capture.variable, capture.name, stableHooks))
|
|
11329
|
+
if (!capture.forceDependency && isStableValue(capture.variable, capture.name, stableHooks)) {
|
|
11217
11330
|
continue;
|
|
11331
|
+
}
|
|
11218
11332
|
const rootIdentifier = getRootIdentifier(capture.node);
|
|
11219
11333
|
if (!rootIdentifier)
|
|
11220
11334
|
continue;
|
|
@@ -11269,8 +11383,9 @@ var useExhaustiveDependencies = {
|
|
|
11269
11383
|
}
|
|
11270
11384
|
}
|
|
11271
11385
|
for (const capture of captures) {
|
|
11272
|
-
if (isStableValue(capture.variable, capture.name, stableHooks))
|
|
11386
|
+
if (!capture.forceDependency && isStableValue(capture.variable, capture.name, stableHooks)) {
|
|
11273
11387
|
continue;
|
|
11388
|
+
}
|
|
11274
11389
|
const rootIdentifier = getRootIdentifier(capture.node);
|
|
11275
11390
|
if (!rootIdentifier)
|
|
11276
11391
|
continue;
|
|
@@ -13130,4 +13245,4 @@ export {
|
|
|
13130
13245
|
createBanInstancesOptions
|
|
13131
13246
|
};
|
|
13132
13247
|
|
|
13133
|
-
//# debugId=
|
|
13248
|
+
//# debugId=37B24C45DE0AD08464756E2164756E21
|