@vitest/eslint-plugin 1.1.13 → 1.1.14

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/README.md CHANGED
@@ -206,6 +206,7 @@ export default [
206
206
  | [valid-describe-callback](docs/rules/valid-describe-callback.md) | enforce valid describe callback | ✅ | 🌐 | | | |
207
207
  | [valid-expect](docs/rules/valid-expect.md) | enforce valid `expect()` usage | ✅ | 🌐 | 🔧 | | |
208
208
  | [valid-title](docs/rules/valid-title.md) | enforce valid titles | ✅ | 🌐 | 🔧 | | |
209
+ | [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | require promises that have expectations in their chain to be valid | | 🌐 | | | |
209
210
 
210
211
  <!-- end auto-generated rules list -->
211
212
 
package/dist/index.cjs CHANGED
@@ -23,7 +23,7 @@ function _interopNamespaceCompat(e) {
23
23
  const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
24
24
  const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
25
25
 
26
- const version = "1.1.12";
26
+ const version = "1.1.13";
27
27
 
28
28
  function createEslintRule(rule) {
29
29
  const createRule = utils.ESLintUtils.RuleCreator(
@@ -3377,6 +3377,19 @@ const paramsLocation = (params) => {
3377
3377
  end: last.loc.end
3378
3378
  };
3379
3379
  };
3380
+ const hasNonEachMembersAndParams = (vitestFnCall, functionExpression) => {
3381
+ return vitestFnCall.members.every((s) => getAccessorValue(s) !== "each") && functionExpression.params.length;
3382
+ };
3383
+ const reportUnexpectedReturnInDescribe = (blockStatement, context) => {
3384
+ blockStatement.body.forEach((node) => {
3385
+ if (node.type !== utils.AST_NODE_TYPES.ReturnStatement)
3386
+ return;
3387
+ context.report({
3388
+ messageId: "unexpectedReturnInDescribe",
3389
+ node
3390
+ });
3391
+ });
3392
+ };
3380
3393
  const validDescribeCallback = createEslintRule({
3381
3394
  name: RULE_NAME$i,
3382
3395
  meta: {
@@ -3408,42 +3421,53 @@ const validDescribeCallback = createEslintRule({
3408
3421
  loc: node.loc
3409
3422
  });
3410
3423
  }
3411
- const [, callback] = node.arguments;
3412
- if (!callback) {
3424
+ const [, arg2, arg3] = node.arguments;
3425
+ if (!arg2) {
3413
3426
  context.report({
3414
3427
  messageId: "nameAndCallback",
3415
3428
  loc: paramsLocation(node.arguments)
3416
3429
  });
3417
3430
  return;
3418
3431
  }
3419
- if (!isFunction(callback)) {
3432
+ if (!isFunction(arg2)) {
3433
+ if (arg3 && isFunction(arg3)) {
3434
+ if (hasNonEachMembersAndParams(vitestFnCall, arg3)) {
3435
+ context.report({
3436
+ messageId: "unexpectedDescribeArgument",
3437
+ node: arg3
3438
+ });
3439
+ }
3440
+ if (arg3.body.type === utils.AST_NODE_TYPES.CallExpression) {
3441
+ context.report({
3442
+ messageId: "unexpectedReturnInDescribe",
3443
+ node: arg3
3444
+ });
3445
+ }
3446
+ if (arg3.body.type === utils.AST_NODE_TYPES.BlockStatement) {
3447
+ reportUnexpectedReturnInDescribe(arg3.body, context);
3448
+ }
3449
+ return;
3450
+ }
3420
3451
  context.report({
3421
3452
  messageId: "secondArgumentMustBeFunction",
3422
3453
  loc: paramsLocation(node.arguments)
3423
3454
  });
3424
3455
  return;
3425
3456
  }
3426
- if (vitestFnCall.members.every((s) => getAccessorValue(s) !== "each") && callback.params.length) {
3457
+ if (hasNonEachMembersAndParams(vitestFnCall, arg2)) {
3427
3458
  context.report({
3428
3459
  messageId: "unexpectedDescribeArgument",
3429
- node: callback
3460
+ node: arg2
3430
3461
  });
3431
3462
  }
3432
- if (callback.body.type === utils.AST_NODE_TYPES.CallExpression) {
3463
+ if (arg2.body.type === utils.AST_NODE_TYPES.CallExpression) {
3433
3464
  context.report({
3434
3465
  messageId: "unexpectedReturnInDescribe",
3435
- node: callback
3466
+ node: arg2
3436
3467
  });
3437
3468
  }
3438
- if (callback.body.type === utils.AST_NODE_TYPES.BlockStatement) {
3439
- callback.body.body.forEach((node2) => {
3440
- if (node2.type === utils.AST_NODE_TYPES.ReturnStatement) {
3441
- context.report({
3442
- messageId: "unexpectedReturnInDescribe",
3443
- node: node2
3444
- });
3445
- }
3446
- });
3469
+ if (arg2.body.type === utils.AST_NODE_TYPES.BlockStatement) {
3470
+ reportUnexpectedReturnInDescribe(arg2.body, context);
3447
3471
  }
3448
3472
  }
3449
3473
  };
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { isAbsolute, posix } from 'node:path';
4
4
  import ts from 'typescript';
5
5
  import { createRequire } from 'node:module';
6
6
 
7
- const version = "1.1.12";
7
+ const version = "1.1.13";
8
8
 
9
9
  function createEslintRule(rule) {
10
10
  const createRule = ESLintUtils.RuleCreator(
@@ -3358,6 +3358,19 @@ const paramsLocation = (params) => {
3358
3358
  end: last.loc.end
3359
3359
  };
3360
3360
  };
3361
+ const hasNonEachMembersAndParams = (vitestFnCall, functionExpression) => {
3362
+ return vitestFnCall.members.every((s) => getAccessorValue(s) !== "each") && functionExpression.params.length;
3363
+ };
3364
+ const reportUnexpectedReturnInDescribe = (blockStatement, context) => {
3365
+ blockStatement.body.forEach((node) => {
3366
+ if (node.type !== AST_NODE_TYPES.ReturnStatement)
3367
+ return;
3368
+ context.report({
3369
+ messageId: "unexpectedReturnInDescribe",
3370
+ node
3371
+ });
3372
+ });
3373
+ };
3361
3374
  const validDescribeCallback = createEslintRule({
3362
3375
  name: RULE_NAME$i,
3363
3376
  meta: {
@@ -3389,42 +3402,53 @@ const validDescribeCallback = createEslintRule({
3389
3402
  loc: node.loc
3390
3403
  });
3391
3404
  }
3392
- const [, callback] = node.arguments;
3393
- if (!callback) {
3405
+ const [, arg2, arg3] = node.arguments;
3406
+ if (!arg2) {
3394
3407
  context.report({
3395
3408
  messageId: "nameAndCallback",
3396
3409
  loc: paramsLocation(node.arguments)
3397
3410
  });
3398
3411
  return;
3399
3412
  }
3400
- if (!isFunction(callback)) {
3413
+ if (!isFunction(arg2)) {
3414
+ if (arg3 && isFunction(arg3)) {
3415
+ if (hasNonEachMembersAndParams(vitestFnCall, arg3)) {
3416
+ context.report({
3417
+ messageId: "unexpectedDescribeArgument",
3418
+ node: arg3
3419
+ });
3420
+ }
3421
+ if (arg3.body.type === AST_NODE_TYPES.CallExpression) {
3422
+ context.report({
3423
+ messageId: "unexpectedReturnInDescribe",
3424
+ node: arg3
3425
+ });
3426
+ }
3427
+ if (arg3.body.type === AST_NODE_TYPES.BlockStatement) {
3428
+ reportUnexpectedReturnInDescribe(arg3.body, context);
3429
+ }
3430
+ return;
3431
+ }
3401
3432
  context.report({
3402
3433
  messageId: "secondArgumentMustBeFunction",
3403
3434
  loc: paramsLocation(node.arguments)
3404
3435
  });
3405
3436
  return;
3406
3437
  }
3407
- if (vitestFnCall.members.every((s) => getAccessorValue(s) !== "each") && callback.params.length) {
3438
+ if (hasNonEachMembersAndParams(vitestFnCall, arg2)) {
3408
3439
  context.report({
3409
3440
  messageId: "unexpectedDescribeArgument",
3410
- node: callback
3441
+ node: arg2
3411
3442
  });
3412
3443
  }
3413
- if (callback.body.type === AST_NODE_TYPES.CallExpression) {
3444
+ if (arg2.body.type === AST_NODE_TYPES.CallExpression) {
3414
3445
  context.report({
3415
3446
  messageId: "unexpectedReturnInDescribe",
3416
- node: callback
3447
+ node: arg2
3417
3448
  });
3418
3449
  }
3419
- if (callback.body.type === AST_NODE_TYPES.BlockStatement) {
3420
- callback.body.body.forEach((node2) => {
3421
- if (node2.type === AST_NODE_TYPES.ReturnStatement) {
3422
- context.report({
3423
- messageId: "unexpectedReturnInDescribe",
3424
- node: node2
3425
- });
3426
- }
3427
- });
3450
+ if (arg2.body.type === AST_NODE_TYPES.BlockStatement) {
3451
+ reportUnexpectedReturnInDescribe(arg2.body, context);
3428
3452
  }
3429
3453
  }
3430
3454
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitest/eslint-plugin",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "license": "MIT",
5
5
  "description": "Eslint plugin for vitest",
6
6
  "repository": "vitest-dev/eslint-plugin-vitest",