eslint-plugin-no-mistakes 0.20.0 → 0.20.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-no-mistakes",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "ESLint and Oxlint rules for deterministic no-mistakes code analysis",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,10 +21,10 @@
21
21
  "test": "vitest run --coverage"
22
22
  },
23
23
  "devDependencies": {
24
- "@typescript-eslint/parser": "^8.60.0",
25
- "@vitest/coverage-v8": "^4.1.7",
26
- "eslint": "^10.4.0",
27
- "oxlint": "^1.67.0",
24
+ "@typescript-eslint/parser": "^8.60.1",
25
+ "@vitest/coverage-v8": "^4.1.8",
26
+ "eslint": "^10.4.1",
27
+ "oxlint": "^1.68.0",
28
28
  "vitest": "^4.1.6"
29
29
  },
30
30
  "peerDependencies": {
@@ -4,34 +4,10 @@ const { rule } = require("../helpers");
4
4
 
5
5
  const TEST_FILE_PATTERN = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
6
6
  const MOCK_TEST_FILE_PATTERN = /\.mock\.test\.[cm]?[jt]sx?$/;
7
- const MOCK_METHODS = new Set([
8
- "fn",
9
- "mock",
10
- "doMock",
11
- "unmock",
12
- "doUnmock",
13
- "spyOn",
14
- "clearAllMocks",
15
- "resetAllMocks",
16
- "restoreAllMocks",
17
- "stubEnv",
18
- "stubGlobal",
19
- "setSystemTime",
20
- ]);
21
-
22
- const MOCK_CHAIN_METHODS = new Set([
23
- "mockImplementation",
24
- "mockImplementationOnce",
25
- "mockReturnValue",
26
- "mockReturnValueOnce",
27
- "mockResolvedValue",
28
- "mockResolvedValueOnce",
29
- "mockRejectedValue",
30
- "mockRejectedValueOnce",
31
- "mockReset",
32
- "mockRestore",
33
- "mockClear",
34
- ]);
7
+ // Only module-level mocking requires a `.mock.test` filename. `vi.fn()`,
8
+ // `vi.spyOn`, env stubs, and `.mock*()` chain helpers are test doubles, not
9
+ // module mocks (issue #388).
10
+ const MOCK_METHODS = new Set(["mock", "doMock", "unmock", "doUnmock"]);
35
11
 
36
12
  function isTestFile(filename) {
37
13
  return TEST_FILE_PATTERN.test(filename.replace(/\\/g, "/"));
@@ -88,22 +64,23 @@ function isMockingCall(node, context) {
88
64
  module.exports = rule(
89
65
  {
90
66
  type: "problem",
91
- docs: { description: "require .mock.test filenames for mock-heavy tests", recommended: false },
67
+ docs: {
68
+ description: "require .mock.test filenames for module-mocking tests",
69
+ recommended: false,
70
+ },
92
71
  schema: [],
93
72
  messages: {
94
- needsMock: "Tests using mocking APIs must use a .mock.test.<ext> filename.",
95
- unnecessaryMock: "Tests without mocking APIs must not use a .mock.test.<ext> filename.",
73
+ needsMock:
74
+ "Tests that mock modules (vi.mock/vi.doMock) must use a .mock.test.<ext> filename. vi.fn()/vi.spyOn stubs do not count.",
75
+ unnecessaryMock:
76
+ "Tests without module mocking (vi.mock/vi.doMock) must not use a .mock.test.<ext> filename.",
96
77
  },
97
78
  },
98
79
  (context) => {
99
80
  let usesMocking = false;
100
- function isMockChainCall(node) {
101
- if (node.callee.type !== "MemberExpression") return false;
102
- return MOCK_CHAIN_METHODS.has(propertyName(node.callee.property));
103
- }
104
81
  return {
105
82
  CallExpression(node) {
106
- if (isMockingCall(node, context) || isMockChainCall(node)) usesMocking = true;
83
+ if (isMockingCall(node, context)) usesMocking = true;
107
84
  },
108
85
  "Program:exit"(node) {
109
86
  if (!isTestFile(context.filename)) return;