@vitest/eslint-plugin 1.1.15 → 1.1.17

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/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.14";
26
+ const version = "1.1.16";
27
27
 
28
28
  function createEslintRule(rule) {
29
29
  const createRule = utils.ESLintUtils.RuleCreator(
@@ -271,6 +271,12 @@ const resolveVitestFn = (context, node, identifier) => {
271
271
  const maybeImport = resolveScope(scope, identifier);
272
272
  if (maybeImport === "local")
273
273
  return null;
274
+ if (maybeImport === "testContext")
275
+ return {
276
+ local: identifier,
277
+ original: null,
278
+ type: "testContext"
279
+ };
274
280
  if (maybeImport) {
275
281
  if (maybeImport.source === "vitest") {
276
282
  return {
@@ -300,6 +306,13 @@ const resolveScope = (scope, identifier) => {
300
306
  const ref = currentScope.set.get(identifier);
301
307
  if (ref && ref.defs.length > 0) {
302
308
  const def = ref.defs[ref.defs.length - 1];
309
+ const objectParam = isFunction(def.node) ? def.node.params.find((params) => params.type === utils.AST_NODE_TYPES.ObjectPattern) : void 0;
310
+ if (objectParam) {
311
+ const property = objectParam.properties.find((property2) => property2.type === utils.AST_NODE_TYPES.Property);
312
+ const key = property?.key.type === utils.AST_NODE_TYPES.Identifier ? property.key : void 0;
313
+ if (key?.name === identifier)
314
+ return "testContext";
315
+ }
303
316
  const importDetails = describePossibleImportDef(def);
304
317
  if (importDetails?.local === identifier)
305
318
  return importDetails;
@@ -1822,7 +1835,7 @@ const noMocksImport = createEslintRule({
1822
1835
  recommended: false
1823
1836
  },
1824
1837
  messages: {
1825
- noMocksImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`jest.mock\` and import from the original module path.`
1838
+ noMocksImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`vi.mock\` and import from the original module path.`
1826
1839
  },
1827
1840
  schema: []
1828
1841
  },
@@ -3681,8 +3694,12 @@ const requireLocalTestContextForConcurrentSnapshots = createEslintRule({
3681
3694
  create(context) {
3682
3695
  return {
3683
3696
  CallExpression(node) {
3684
- const isNotAnAssertion = !isTypeOfVitestFnCall(node, context, ["expect"]);
3685
- if (isNotAnAssertion)
3697
+ const vitestFnCall = parseVitestFnCall(node, context);
3698
+ if (vitestFnCall === null)
3699
+ return;
3700
+ if (vitestFnCall.type !== "expect")
3701
+ return;
3702
+ if (vitestFnCall.type === "expect" && vitestFnCall.head.type === "testContext")
3686
3703
  return;
3687
3704
  const isNotASnapshotAssertion = ![
3688
3705
  "toMatchSnapshot",
@@ -4162,12 +4179,6 @@ const preferExpectAssertions = createEslintRule({
4162
4179
  if (node.arguments.length < 2)
4163
4180
  return;
4164
4181
  const [, secondArg] = node.arguments;
4165
- if (secondArg?.type === utils.AST_NODE_TYPES.ArrowFunctionExpression && secondArg.params.length) {
4166
- if (secondArg?.params[0].type === utils.AST_NODE_TYPES.ObjectPattern) {
4167
- if (secondArg.params[0].properties[0].type === utils.AST_NODE_TYPES.Property && secondArg.params[0].properties[0].key.type === utils.AST_NODE_TYPES.Identifier && secondArg.params[0].properties[0].key.name === "expect")
4168
- return;
4169
- }
4170
- }
4171
4182
  if (!isFunction(secondArg) || !shouldCheckFunction(secondArg))
4172
4183
  return;
4173
4184
  hasExpectInLoop = false;
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.14";
7
+ const version = "1.1.16";
8
8
 
9
9
  function createEslintRule(rule) {
10
10
  const createRule = ESLintUtils.RuleCreator(
@@ -252,6 +252,12 @@ const resolveVitestFn = (context, node, identifier) => {
252
252
  const maybeImport = resolveScope(scope, identifier);
253
253
  if (maybeImport === "local")
254
254
  return null;
255
+ if (maybeImport === "testContext")
256
+ return {
257
+ local: identifier,
258
+ original: null,
259
+ type: "testContext"
260
+ };
255
261
  if (maybeImport) {
256
262
  if (maybeImport.source === "vitest") {
257
263
  return {
@@ -281,6 +287,13 @@ const resolveScope = (scope, identifier) => {
281
287
  const ref = currentScope.set.get(identifier);
282
288
  if (ref && ref.defs.length > 0) {
283
289
  const def = ref.defs[ref.defs.length - 1];
290
+ const objectParam = isFunction(def.node) ? def.node.params.find((params) => params.type === AST_NODE_TYPES.ObjectPattern) : void 0;
291
+ if (objectParam) {
292
+ const property = objectParam.properties.find((property2) => property2.type === AST_NODE_TYPES.Property);
293
+ const key = property?.key.type === AST_NODE_TYPES.Identifier ? property.key : void 0;
294
+ if (key?.name === identifier)
295
+ return "testContext";
296
+ }
284
297
  const importDetails = describePossibleImportDef(def);
285
298
  if (importDetails?.local === identifier)
286
299
  return importDetails;
@@ -1803,7 +1816,7 @@ const noMocksImport = createEslintRule({
1803
1816
  recommended: false
1804
1817
  },
1805
1818
  messages: {
1806
- noMocksImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`jest.mock\` and import from the original module path.`
1819
+ noMocksImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`vi.mock\` and import from the original module path.`
1807
1820
  },
1808
1821
  schema: []
1809
1822
  },
@@ -3662,8 +3675,12 @@ const requireLocalTestContextForConcurrentSnapshots = createEslintRule({
3662
3675
  create(context) {
3663
3676
  return {
3664
3677
  CallExpression(node) {
3665
- const isNotAnAssertion = !isTypeOfVitestFnCall(node, context, ["expect"]);
3666
- if (isNotAnAssertion)
3678
+ const vitestFnCall = parseVitestFnCall(node, context);
3679
+ if (vitestFnCall === null)
3680
+ return;
3681
+ if (vitestFnCall.type !== "expect")
3682
+ return;
3683
+ if (vitestFnCall.type === "expect" && vitestFnCall.head.type === "testContext")
3667
3684
  return;
3668
3685
  const isNotASnapshotAssertion = ![
3669
3686
  "toMatchSnapshot",
@@ -4143,12 +4160,6 @@ const preferExpectAssertions = createEslintRule({
4143
4160
  if (node.arguments.length < 2)
4144
4161
  return;
4145
4162
  const [, secondArg] = node.arguments;
4146
- if (secondArg?.type === AST_NODE_TYPES.ArrowFunctionExpression && secondArg.params.length) {
4147
- if (secondArg?.params[0].type === AST_NODE_TYPES.ObjectPattern) {
4148
- if (secondArg.params[0].properties[0].type === AST_NODE_TYPES.Property && secondArg.params[0].properties[0].key.type === AST_NODE_TYPES.Identifier && secondArg.params[0].properties[0].key.name === "expect")
4149
- return;
4150
- }
4151
- }
4152
4163
  if (!isFunction(secondArg) || !shouldCheckFunction(secondArg))
4153
4164
  return;
4154
4165
  hasExpectInLoop = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitest/eslint-plugin",
3
- "version": "1.1.15",
3
+ "version": "1.1.17",
4
4
  "license": "MIT",
5
5
  "description": "Eslint plugin for vitest",
6
6
  "repository": "vitest-dev/eslint-plugin-vitest",