@pobammer-ts/eslint-cease-nonsense-rules 1.4.1 → 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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "commit": "f9f7350de303b20ac132d917a403f15ed30d4daf",
3
- "time": "2025-12-04T00:47:41.402Z",
4
- "version": "1.4.1"
2
+ "commit": "b2b51c8d8ebea9ceb8a4cd943c1f35ecac632c5f",
3
+ "time": "2025-12-07T19:15:33.726Z",
4
+ "version": "1.4.2"
5
5
  }
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
- if (exports_guard.IsUndefined(propertyValue))
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
  }
@@ -10852,8 +10853,9 @@ function getHookName2(node) {
10852
10853
  const { callee } = node;
10853
10854
  if (callee.type === TSESTree9.AST_NODE_TYPES.Identifier)
10854
10855
  return callee.name;
10855
- 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) {
10856
10857
  return callee.property.name;
10858
+ }
10857
10859
  return;
10858
10860
  }
10859
10861
  function getMemberExpressionDepth(node) {
@@ -10871,23 +10873,51 @@ function getRootIdentifier(node) {
10871
10873
  let current = node;
10872
10874
  if (current.type === TSESTree9.AST_NODE_TYPES.ChainExpression)
10873
10875
  current = current.expression;
10874
- while (current.type === TSESTree9.AST_NODE_TYPES.MemberExpression)
10875
- current = current.object;
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
+ }
10876
10882
  return current.type === TSESTree9.AST_NODE_TYPES.Identifier ? current : undefined;
10877
10883
  }
10878
10884
  function nodeToDependencyString(node, sourceCode) {
10879
10885
  return sourceCode.getText(node);
10880
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
+ }
10881
10909
  function isStableArrayIndex(stableResult, node, identifierName) {
10882
10910
  if (!stableResult)
10883
10911
  return false;
10884
- 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) {
10885
10913
  return false;
10914
+ }
10886
10915
  const elements = node.id.elements;
10887
10916
  let index2 = 0;
10888
10917
  for (const element of elements) {
10889
- if (element.type === TSESTree9.AST_NODE_TYPES.Identifier && element.name === identifierName)
10918
+ if (element.type === TSESTree9.AST_NODE_TYPES.Identifier && element.name === identifierName) {
10890
10919
  return stableResult.has(index2);
10920
+ }
10891
10921
  index2 += 1;
10892
10922
  }
10893
10923
  return false;
@@ -10923,16 +10953,20 @@ function isStableValue(variable, identifierName, stableHooks) {
10923
10953
  return true;
10924
10954
  if (init?.type === TSESTree9.AST_NODE_TYPES.CallExpression) {
10925
10955
  const { callee } = init;
10926
- 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") {
10927
10957
  return true;
10928
- if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.property.name === "map")
10958
+ }
10959
+ if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.property.name === "map") {
10929
10960
  return true;
10961
+ }
10930
10962
  }
10931
10963
  if (init) {
10932
- 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) {
10933
10965
  return true;
10934
- if (init.type === TSESTree9.AST_NODE_TYPES.UnaryExpression && init.argument.type === TSESTree9.AST_NODE_TYPES.Literal)
10966
+ }
10967
+ if (init.type === TSESTree9.AST_NODE_TYPES.UnaryExpression && init.argument.type === TSESTree9.AST_NODE_TYPES.Literal) {
10935
10968
  return true;
10969
+ }
10936
10970
  }
10937
10971
  const variableDefinition = variable.defs.find((definition2) => definition2.node === node);
10938
10972
  if (variableDefinition && variableDefinition.node.type === TSESTree9.AST_NODE_TYPES.VariableDeclarator) {
@@ -10957,7 +10991,8 @@ function findTopmostMemberExpression(node) {
10957
10991
  }
10958
10992
  const isMemberParent = parent.type === TSESTree9.AST_NODE_TYPES.MemberExpression && parent.object === current;
10959
10993
  const isChainParent = parent.type === TSESTree9.AST_NODE_TYPES.ChainExpression;
10960
- if (!isMemberParent && !isChainParent)
10994
+ const isNonNullParent = parent.type === TSESTree9.AST_NODE_TYPES.TSNonNullExpression;
10995
+ if (!isMemberParent && !isChainParent && !isNonNullParent)
10961
10996
  break;
10962
10997
  current = parent;
10963
10998
  parent = parent.parent;
@@ -10970,9 +11005,24 @@ var IS_CEASE_BOUNDARY = new Set([
10970
11005
  TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression,
10971
11006
  TSESTree9.AST_NODE_TYPES.VariableDeclarator
10972
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
+ }
10973
11019
  function isInTypePosition(identifier3) {
10974
11020
  let parent = identifier3.parent;
10975
11021
  while (parent) {
11022
+ if (TS_RUNTIME_EXPRESSIONS.has(parent.type)) {
11023
+ parent = parent.parent;
11024
+ continue;
11025
+ }
10976
11026
  if (parent.type.startsWith("TS"))
10977
11027
  return true;
10978
11028
  if (IS_CEASE_BOUNDARY.has(parent.type))
@@ -11018,10 +11068,12 @@ function resolveFunctionReference(identifier3, scope) {
11018
11068
  return;
11019
11069
  for (const definition of variable.defs) {
11020
11070
  const { node } = definition;
11021
- if (node.type === TSESTree9.AST_NODE_TYPES.FunctionDeclaration)
11071
+ if (node.type === TSESTree9.AST_NODE_TYPES.FunctionDeclaration) {
11022
11072
  return node;
11023
- 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))
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)) {
11024
11075
  return node.init;
11076
+ }
11025
11077
  }
11026
11078
  return;
11027
11079
  }
@@ -11058,9 +11110,11 @@ function collectCaptures(node, sourceCode) {
11058
11110
  }
11059
11111
  captureSet.add(name);
11060
11112
  const depthNode = findTopmostMemberExpression(current);
11061
- const usagePath = sourceCode.getText(depthNode);
11113
+ const usagePath = nodeToSafeDependencyPath(depthNode, sourceCode);
11114
+ const depth = getMemberExpressionDepth(depthNode);
11062
11115
  captures.push({
11063
- depth: getMemberExpressionDepth(depthNode),
11116
+ depth,
11117
+ forceDependency: isComputedPropertyIdentifier(current),
11064
11118
  name,
11065
11119
  node: depthNode,
11066
11120
  usagePath,
@@ -11083,6 +11137,12 @@ function collectCaptures(node, sourceCode) {
11083
11137
  visit(current.expression);
11084
11138
  return;
11085
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
+ }
11086
11146
  const keys2 = sourceCode.visitorKeys?.[current.type] ?? [];
11087
11147
  for (const key of keys2) {
11088
11148
  const value = current[key];
@@ -11178,9 +11238,9 @@ var useExhaustiveDependencies = {
11178
11238
  if (closureArgument === undefined)
11179
11239
  return;
11180
11240
  let closureFunction;
11181
- 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) {
11182
11242
  closureFunction = closureArgument;
11183
- else if (closureArgument.type === TSESTree9.AST_NODE_TYPES.Identifier) {
11243
+ } else if (closureArgument.type === TSESTree9.AST_NODE_TYPES.Identifier) {
11184
11244
  const scope = getScope(callNode);
11185
11245
  closureFunction = resolveFunctionReference(closureArgument, scope);
11186
11246
  }
@@ -11189,7 +11249,7 @@ var useExhaustiveDependencies = {
11189
11249
  const dependenciesArgument = parameters3[dependenciesIndex];
11190
11250
  if (!dependenciesArgument && options3.reportMissingDependenciesArray) {
11191
11251
  const captures2 = collectCaptures(closureFunction, context.sourceCode);
11192
- 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));
11193
11253
  if (requiredCaptures.length > 0) {
11194
11254
  const missingNames = [...new Set(requiredCaptures.map(returnName))].join(", ");
11195
11255
  const usagePaths = requiredCaptures.map(({ usagePath }) => usagePath);
@@ -11266,8 +11326,9 @@ var useExhaustiveDependencies = {
11266
11326
  }
11267
11327
  const missingCaptures = new Array;
11268
11328
  for (const capture of captures) {
11269
- if (isStableValue(capture.variable, capture.name, stableHooks))
11329
+ if (!capture.forceDependency && isStableValue(capture.variable, capture.name, stableHooks)) {
11270
11330
  continue;
11331
+ }
11271
11332
  const rootIdentifier = getRootIdentifier(capture.node);
11272
11333
  if (!rootIdentifier)
11273
11334
  continue;
@@ -11322,8 +11383,9 @@ var useExhaustiveDependencies = {
11322
11383
  }
11323
11384
  }
11324
11385
  for (const capture of captures) {
11325
- if (isStableValue(capture.variable, capture.name, stableHooks))
11386
+ if (!capture.forceDependency && isStableValue(capture.variable, capture.name, stableHooks)) {
11326
11387
  continue;
11388
+ }
11327
11389
  const rootIdentifier = getRootIdentifier(capture.node);
11328
11390
  if (!rootIdentifier)
11329
11391
  continue;
@@ -13183,4 +13245,4 @@ export {
13183
13245
  createBanInstancesOptions
13184
13246
  };
13185
13247
 
13186
- //# debugId=8ED77B08FB4A984564756E2164756E21
13248
+ //# debugId=37B24C45DE0AD08464756E2164756E21