@typescript-eslint/eslint-plugin 8.62.2-alpha.16 → 8.62.2-alpha.18

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.
@@ -340,11 +340,27 @@ exports.default = (0, util_1.createRule)({
340
340
  }
341
341
  function checkVariableDeclaration(node) {
342
342
  const tsNode = services.esTreeNodeToTSNodeMap.get(node);
343
- if (tsNode.initializer == null ||
344
- node.init == null ||
345
- node.id.typeAnnotation == null) {
343
+ if (tsNode.initializer == null || node.init == null) {
346
344
  return;
347
345
  }
346
+ if (node.parent.kind === 'using' &&
347
+ hasWellKnownSymbolWithThenableReturn(checker, tsNode.initializer, checker.getTypeAtLocation(tsNode.initializer), 'dispose')) {
348
+ context.report({
349
+ node: node.init,
350
+ messageId: 'voidReturnVariable',
351
+ });
352
+ }
353
+ if (node.id.typeAnnotation == null) {
354
+ return;
355
+ }
356
+ const variableType = services.getTypeAtLocation(node.id);
357
+ if (hasWellKnownSymbolWithVoidReturn(checker, tsNode.name, variableType, 'dispose') &&
358
+ hasWellKnownSymbolWithThenableReturn(checker, tsNode.initializer, checker.getTypeAtLocation(tsNode.initializer), 'dispose')) {
359
+ context.report({
360
+ node: node.init,
361
+ messageId: 'voidReturnVariable',
362
+ });
363
+ }
348
364
  // syntactically ignore some known-good cases to avoid touching type info
349
365
  if (!isPossiblyFunctionType(node.id.typeAnnotation)) {
350
366
  return;
@@ -763,3 +779,25 @@ function isStaticMember(node) {
763
779
  node.type === utils_1.AST_NODE_TYPES.AccessorProperty) &&
764
780
  node.static);
765
781
  }
782
+ function hasWellKnownSymbolWithThenableReturn(checker, node, type, symbolName) {
783
+ return tsutils
784
+ .unionConstituents(checker.getApparentType(type))
785
+ .some(typePart => {
786
+ const symbol = tsutils.getWellKnownSymbolPropertyOfType(typePart, symbolName, checker);
787
+ if (symbol == null) {
788
+ return false;
789
+ }
790
+ return isThenableReturningFunctionType(checker, node, checker.getTypeOfSymbolAtLocation(symbol, node));
791
+ });
792
+ }
793
+ function hasWellKnownSymbolWithVoidReturn(checker, node, type, symbolName) {
794
+ return tsutils
795
+ .unionConstituents(checker.getApparentType(type))
796
+ .some(typePart => {
797
+ const symbol = tsutils.getWellKnownSymbolPropertyOfType(typePart, symbolName, checker);
798
+ if (symbol == null) {
799
+ return false;
800
+ }
801
+ return isVoidReturningFunctionType(checker, node, checker.getTypeOfSymbolAtLocation(symbol, node));
802
+ });
803
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.62.2-alpha.16",
3
+ "version": "8.62.2-alpha.18",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -49,10 +49,10 @@
49
49
  "ignore": "^7.0.5",
50
50
  "natural-compare": "^1.4.0",
51
51
  "ts-api-utils": "^2.5.0",
52
- "@typescript-eslint/scope-manager": "8.62.2-alpha.16",
53
- "@typescript-eslint/type-utils": "8.62.2-alpha.16",
54
- "@typescript-eslint/visitor-keys": "8.62.2-alpha.16",
55
- "@typescript-eslint/utils": "8.62.2-alpha.16"
52
+ "@typescript-eslint/scope-manager": "8.62.2-alpha.18",
53
+ "@typescript-eslint/type-utils": "8.62.2-alpha.18",
54
+ "@typescript-eslint/utils": "8.62.2-alpha.18",
55
+ "@typescript-eslint/visitor-keys": "8.62.2-alpha.18"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/json-schema": "^7.0.15",
@@ -76,13 +76,13 @@
76
76
  "typescript": ">=4.8.4 <6.1.0",
77
77
  "unist-util-visit": "^5.0.0",
78
78
  "vitest": "^4.0.18",
79
- "@typescript-eslint/rule-schema-to-typescript-types": "8.62.2-alpha.16",
80
- "@typescript-eslint/rule-tester": "8.62.2-alpha.16"
79
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.62.2-alpha.18",
80
+ "@typescript-eslint/rule-tester": "8.62.2-alpha.18"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
84
84
  "typescript": ">=4.8.4 <6.1.0",
85
- "@typescript-eslint/parser": "^8.62.2-alpha.16"
85
+ "@typescript-eslint/parser": "^8.62.2-alpha.18"
86
86
  },
87
87
  "funding": {
88
88
  "type": "opencollective",