eslint-plugin-absolute 0.11.0-beta.0 → 0.11.0-beta.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.
Files changed (2) hide show
  1. package/dist/index.js +35 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3653,6 +3653,39 @@ var noRedundantTypeAnnotation = createRule({
3653
3653
  return {};
3654
3654
  }
3655
3655
  const stringify = (type) => tsChecker.typeToString(type, undefined, ts2.TypeFormatFlags.NoTruncation | ts2.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
3656
+ const referencesTypeParam = (typeNode, name) => {
3657
+ let found = false;
3658
+ const visit = (node) => {
3659
+ if (found)
3660
+ return;
3661
+ if (ts2.isTypeReferenceNode(node) && ts2.isIdentifier(node.typeName) && node.typeName.text === name) {
3662
+ found = true;
3663
+ return;
3664
+ }
3665
+ ts2.forEachChild(node, visit);
3666
+ };
3667
+ visit(typeNode);
3668
+ return found;
3669
+ };
3670
+ const leansOnContextualInference = (initNode) => {
3671
+ const callLike = ts2.isCallExpression(initNode) || ts2.isNewExpression(initNode) ? initNode : null;
3672
+ if (!callLike)
3673
+ return false;
3674
+ if (callLike.typeArguments && callLike.typeArguments.length > 0) {
3675
+ return false;
3676
+ }
3677
+ const resolved = tsChecker.getResolvedSignature(callLike);
3678
+ const declaration = resolved?.declaration;
3679
+ if (declaration && !ts2.isJSDocSignature(declaration)) {
3680
+ const typeParams = declaration.typeParameters;
3681
+ if (!typeParams || typeParams.length === 0)
3682
+ return false;
3683
+ return typeParams.some((typeParam) => !declaration.parameters.some((parameter) => parameter.type !== undefined && referencesTypeParam(parameter.type, typeParam.name.text)));
3684
+ }
3685
+ const calleeType = tsChecker.getTypeAtLocation(callLike.expression);
3686
+ const signatures = ts2.isNewExpression(callLike) ? calleeType.getConstructSignatures() : calleeType.getCallSignatures();
3687
+ return signatures.some((signature) => (signature.getTypeParameters()?.length ?? 0) > 0);
3688
+ };
3656
3689
  return {
3657
3690
  VariableDeclarator(node) {
3658
3691
  if (node.id.type !== "Identifier")
@@ -3670,6 +3703,8 @@ var noRedundantTypeAnnotation = createRule({
3670
3703
  return;
3671
3704
  if (!ts2.isTypeNode(annotationTSNode))
3672
3705
  return;
3706
+ if (leansOnContextualInference(initTSNode))
3707
+ return;
3673
3708
  const annotationType = tsChecker.getTypeFromTypeNode(annotationTSNode);
3674
3709
  const initType = tsChecker.getTypeAtLocation(initTSNode);
3675
3710
  const aliasSymbol = ts2.isTypeReferenceNode(annotationTSNode) ? tsChecker.getSymbolAtLocation(annotationTSNode.typeName) : undefined;
package/package.json CHANGED
@@ -40,5 +40,5 @@
40
40
  "typecheck": "bun run tsc --noEmit"
41
41
  },
42
42
  "type": "module",
43
- "version": "0.11.0-beta.0"
43
+ "version": "0.11.0-beta.2"
44
44
  }