@typescript-eslint/eslint-plugin 8.71.3-alpha.14 → 8.71.3-alpha.16

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,6 +1,11 @@
1
1
  import type { TSESLint } from '@typescript-eslint/utils';
2
2
  export type MessageId = 'await' | 'awaitUsingOfNonAsyncDisposable' | 'convertToOrdinaryFor' | 'forAwaitOfNonAsyncIterable' | 'invalidPromiseAggregatorInput' | 'removeAwait';
3
- declare const _default: TSESLint.RuleModule<MessageId, [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
3
+ export type Options = [
4
+ {
5
+ allowMixedPromiseArrays?: boolean;
6
+ }
7
+ ];
8
+ declare const _default: TSESLint.RuleModule<MessageId, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
4
9
  name: string;
5
10
  };
6
11
  export default _default;
@@ -56,11 +56,22 @@ exports.default = (0, util_1.createRule)({
56
56
  invalidPromiseAggregatorInput: 'Unexpected iterable of non-Promise (non-"Thenable") values passed to promise aggregator.',
57
57
  removeAwait: 'Remove unnecessary `await`.',
58
58
  },
59
- schema: [],
59
+ schema: [
60
+ {
61
+ type: 'object',
62
+ additionalProperties: false,
63
+ properties: {
64
+ allowMixedPromiseArrays: {
65
+ type: 'boolean',
66
+ description: 'Whether to allow promise aggregators to receive iterables mixing Promise and non-Promise values, as long as at least one value may be a Promise.',
67
+ },
68
+ },
69
+ },
70
+ ],
60
71
  },
61
72
  // eslint-disable-next-line @typescript-eslint/no-deprecated -- For compatibility with ESLint 8, see #12842
62
- defaultOptions: [],
63
- create(context) {
73
+ defaultOptions: [{ allowMixedPromiseArrays: false }],
74
+ create(context, [{ allowMixedPromiseArrays = false }]) {
64
75
  const services = (0, util_1.getParserServices)(context);
65
76
  const checker = services.program.getTypeChecker();
66
77
  return {
@@ -104,6 +115,10 @@ exports.default = (0, util_1.createRule)({
104
115
  if (argument == null) {
105
116
  return;
106
117
  }
118
+ if (allowMixedPromiseArrays &&
119
+ hasMaybeAwaitableValue(services, argument)) {
120
+ return;
121
+ }
107
122
  if (argument.type === utils_1.TSESTree.AST_NODE_TYPES.ArrayExpression) {
108
123
  for (const element of argument.elements) {
109
124
  if (element == null) {
@@ -208,6 +223,13 @@ function isInvalidPromiseAggregatorInput(checker, node, type) {
208
223
  }
209
224
  return false;
210
225
  }
226
+ function hasMaybeAwaitableValue(services, node) {
227
+ const checker = services.program.getTypeChecker();
228
+ const tsNode = services.esTreeNodeToTSNodeMap.get(node);
229
+ return tsutils
230
+ .unionConstituents((0, util_1.getConstrainedTypeAtLocation)(services, node))
231
+ .some(part => getValueTypesOfArrayLike(part, checker)?.some(valueType => !isAlwaysNonAwaitableType(valueType, tsNode, checker)));
232
+ }
211
233
  function getValueTypesOfArrayLike(type, checker) {
212
234
  if (checker.isTupleType(type)) {
213
235
  return checker.getTypeArguments(type);
@@ -380,7 +380,7 @@ exports.default = (0, util_1.createRule)({
380
380
  return;
381
381
  }
382
382
  const propertyType = services.getTypeAtLocation(node.property);
383
- if (propertyType.isLiteral()) {
383
+ if ((0, util_1.isTypeLiteralType)(propertyType)) {
384
384
  const objectType = services.getTypeAtLocation(node.object);
385
385
  const propertyName = propertyType.isStringLiteral()
386
386
  ? propertyType.value
@@ -94,7 +94,7 @@ function describeLiteralType(type) {
94
94
  if ((0, util_1.isTypeBigIntLiteralType)(type)) {
95
95
  return `${type.value.negative ? '-' : ''}${type.value.base10Value}n`;
96
96
  }
97
- if (type.isLiteral()) {
97
+ if ((0, util_1.isTypeLiteralType)(type)) {
98
98
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
99
99
  return type.value.toString();
100
100
  }
@@ -66,7 +66,7 @@ function isPossiblyNonNullish(type) {
66
66
  .some(t => !isNullishType(t) && !(0, util_1.isTypeFlagSet)(t, ts.TypeFlags.Void));
67
67
  }
68
68
  function toStaticValue(type) {
69
- // type.isLiteral() only covers numbers/bigints and strings, hence the rest of the branches.
69
+ // isTypeLiteralType() only covers numbers/bigints and strings, hence the rest of the branches.
70
70
  if (tsutils.isBooleanLiteralType(type)) {
71
71
  return { value: tsutils.isTrueLiteralType(type) };
72
72
  }
@@ -76,7 +76,7 @@ function toStaticValue(type) {
76
76
  if (type.flags === ts.TypeFlags.Null) {
77
77
  return { value: null };
78
78
  }
79
- if (type.isLiteral()) {
79
+ if ((0, util_1.isTypeLiteralType)(type)) {
80
80
  return { value: (0, util_1.getValueOfLiteralType)(type) };
81
81
  }
82
82
  return undefined;
@@ -217,7 +217,7 @@ exports.default = (0, util_1.createRule)({
217
217
  return areMutuallyAssignable(uncast, cast);
218
218
  }
219
219
  function isTypeLiteral(type) {
220
- return type.isLiteral() || tsutils.isBooleanLiteralType(type);
220
+ return (0, util_1.isTypeLiteralType)(type) || tsutils.isBooleanLiteralType(type);
221
221
  }
222
222
  function hasIndexSignature(type) {
223
223
  return tsutils
@@ -1,5 +1,39 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ const tsutils = __importStar(require("ts-api-utils"));
3
37
  const util_1 = require("../util");
4
38
  exports.default = (0, util_1.createRule)({
5
39
  name: 'require-array-sort-compare',
@@ -40,7 +74,10 @@ exports.default = (0, util_1.createRule)({
40
74
  function isStringArrayNode(node) {
41
75
  const type = (0, util_1.getConstrainedTypeAtLocation)(services, node);
42
76
  if (checker.isArrayType(type) || checker.isTupleType(type)) {
43
- const typeArgs = checker.getTypeArguments(type);
77
+ // Before TS 5.1, a constrained type parameter's array type has an extra `this` type argument
78
+ const typeArgs = checker
79
+ .getTypeArguments(type)
80
+ .slice(0, type.target.typeParameters?.length);
44
81
  return typeArgs.every(arg => {
45
82
  const typeName = (0, util_1.getTypeName)(checker, checker.getBaseConstraintOfType(arg) ?? arg);
46
83
  return typeName === 'string';
@@ -56,7 +93,7 @@ exports.default = (0, util_1.createRule)({
56
93
  if (options.ignoreStringArrays && isStringArrayNode(callee.object)) {
57
94
  return;
58
95
  }
59
- if ((0, util_1.isTypeArrayTypeOrUnionOfArrayTypes)(calleeObjType, checker)) {
96
+ if (isAlwaysArray(calleeObjType, checker)) {
60
97
  context.report({ node: callee.parent, messageId: 'requireCompare' });
61
98
  }
62
99
  }
@@ -65,4 +102,9 @@ exports.default = (0, util_1.createRule)({
65
102
  };
66
103
  },
67
104
  });
105
+ function isAlwaysArray(type, checker) {
106
+ return tsutils
107
+ .unionConstituents(type)
108
+ .every(t => checker.isArrayType(t) || checker.isTupleType(t));
109
+ }
68
110
  //# sourceMappingURL=require-array-sort-compare.js.map
@@ -34,12 +34,13 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.isPossiblyTruthy = exports.isPossiblyFalsy = void 0;
37
+ const type_utils_1 = require("@typescript-eslint/type-utils");
37
38
  const tsutils = __importStar(require("ts-api-utils"));
38
39
  const ts = __importStar(require("typescript"));
39
40
  const getValueOfLiteralType_1 = require("./getValueOfLiteralType");
40
41
  // Truthiness utilities
41
42
  const isTruthyLiteral = (type) => tsutils.isTrueLiteralType(type) ||
42
- (type.isLiteral() && !!(0, getValueOfLiteralType_1.getValueOfLiteralType)(type));
43
+ ((0, type_utils_1.isTypeLiteralType)(type) && !!(0, getValueOfLiteralType_1.getValueOfLiteralType)(type));
43
44
  const isPossiblyFalsy = (type) => tsutils
44
45
  .unionConstituents(type)
45
46
  // Intersections like `string & {}` can also be possibly falsy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.71.3-alpha.14",
3
+ "version": "8.71.3-alpha.16",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -47,10 +47,10 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@eslint-community/regexpp": "^4.12.2",
50
- "@typescript-eslint/scope-manager": "8.71.3-alpha.14",
51
- "@typescript-eslint/type-utils": "8.71.3-alpha.14",
52
- "@typescript-eslint/utils": "8.71.3-alpha.14",
53
- "@typescript-eslint/visitor-keys": "8.71.3-alpha.14",
50
+ "@typescript-eslint/scope-manager": "8.71.3-alpha.16",
51
+ "@typescript-eslint/type-utils": "8.71.3-alpha.16",
52
+ "@typescript-eslint/utils": "8.71.3-alpha.16",
53
+ "@typescript-eslint/visitor-keys": "8.71.3-alpha.16",
54
54
  "ignore": "^7.0.5",
55
55
  "natural-compare": "^1.4.0",
56
56
  "ts-api-utils": "^2.5.0"
@@ -60,10 +60,10 @@
60
60
  "@types/mdast": "^4.0.4",
61
61
  "@types/natural-compare": "^1.4.3",
62
62
  "@types/react": "^18.3.21",
63
- "@typescript-eslint/rule-schema-to-typescript-types": "8.71.3-alpha.14",
64
- "@typescript-eslint/rule-tester": "8.71.3-alpha.14",
63
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.71.3-alpha.16",
64
+ "@typescript-eslint/rule-tester": "8.71.3-alpha.16",
65
65
  "@typescript/native": "npm:typescript@^7.0.2",
66
- "@vitest/coverage-v8": "^4.0.18",
66
+ "@vitest/coverage-v8": "^5.0.3",
67
67
  "ajv": "^6.12.6",
68
68
  "eslint": "^10.0.0",
69
69
  "json-schema": "^0.4.0",
@@ -78,10 +78,10 @@
78
78
  "tsx": "^4.7.2",
79
79
  "typescript": ">=4.8.4 <6.1.0",
80
80
  "unist-util-visit": "^5.0.0",
81
- "vitest": "^4.0.18"
81
+ "vitest": "^5.0.3"
82
82
  },
83
83
  "peerDependencies": {
84
- "@typescript-eslint/parser": "^8.71.3-alpha.14",
84
+ "@typescript-eslint/parser": "^8.71.3-alpha.16",
85
85
  "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
86
86
  "typescript": ">=4.8.4 <6.1.0"
87
87
  },