@vitest/eslint-plugin 1.6.7 → 1.6.9
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 +349 -377
- package/dist/{index.js → index.mjs} +102 -103
- package/package.json +34 -31
- /package/dist/{index.d.ts → index.d.mts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,50 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
let __typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
25
|
-
__typescript_eslint_utils = __toESM(__typescript_eslint_utils);
|
|
1
|
+
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
26
2
|
let node_module = require("node:module");
|
|
27
|
-
node_module = __toESM(node_module);
|
|
28
3
|
let node_path = require("node:path");
|
|
29
|
-
|
|
30
|
-
let __typescript_eslint_scope_manager = require("@typescript-eslint/scope-manager");
|
|
31
|
-
__typescript_eslint_scope_manager = __toESM(__typescript_eslint_scope_manager);
|
|
4
|
+
let _typescript_eslint_scope_manager = require("@typescript-eslint/scope-manager");
|
|
32
5
|
|
|
33
6
|
//#region package.json
|
|
34
|
-
var version = "1.6.
|
|
7
|
+
var version = "1.6.9";
|
|
35
8
|
|
|
36
9
|
//#endregion
|
|
37
10
|
//#region src/utils/index.ts
|
|
38
|
-
const createEslintRule =
|
|
11
|
+
const createEslintRule = _typescript_eslint_utils.ESLintUtils.RuleCreator((name) => `https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/${name}.md`);
|
|
39
12
|
const joinNames = (a, b) => a && b ? `${a}.${b}` : null;
|
|
40
|
-
const isFunction = (node) => node.type ===
|
|
13
|
+
const isFunction = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression || node.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression;
|
|
41
14
|
function getNodeName(node) {
|
|
42
15
|
if (isSupportedAccessor(node)) return getAccessorValue(node);
|
|
43
16
|
switch (node.type) {
|
|
44
|
-
case
|
|
45
|
-
case
|
|
46
|
-
case
|
|
47
|
-
case
|
|
17
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression: return getNodeName(node.tag);
|
|
18
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression: return joinNames(getNodeName(node.object), getNodeName(node.property));
|
|
19
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.NewExpression:
|
|
20
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.CallExpression: return getNodeName(node.callee);
|
|
48
21
|
}
|
|
49
22
|
return null;
|
|
50
23
|
}
|
|
@@ -58,7 +31,7 @@ const isSupportedAccessor = (node, value) => {
|
|
|
58
31
|
* the `name` will be compared to that of the `identifier`.
|
|
59
32
|
*/
|
|
60
33
|
const isIdentifier = (node, name) => {
|
|
61
|
-
return node.type ===
|
|
34
|
+
return node.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && (name === void 0 || node.name === name);
|
|
62
35
|
};
|
|
63
36
|
/**
|
|
64
37
|
* Checks if the given `node` is a `TemplateLiteral`.
|
|
@@ -69,7 +42,7 @@ const isIdentifier = (node, name) => {
|
|
|
69
42
|
* the `value` will be compared to that of the `TemplateLiteral`.
|
|
70
43
|
*/
|
|
71
44
|
const isTemplateLiteral = (node, value) => {
|
|
72
|
-
return node.type ===
|
|
45
|
+
return node.type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1 && (value === void 0 || node.quasis[0].value.raw === value);
|
|
73
46
|
};
|
|
74
47
|
/**
|
|
75
48
|
* Checks if the given `node` is a `StringLiteral`.
|
|
@@ -77,7 +50,7 @@ const isTemplateLiteral = (node, value) => {
|
|
|
77
50
|
* If a `value` is provided & the `node` is a `StringLiteral`,
|
|
78
51
|
* the `value` will be compared to that of the `StringLiteral`.
|
|
79
52
|
*/
|
|
80
|
-
const isStringLiteral = (node, value) => node.type ===
|
|
53
|
+
const isStringLiteral = (node, value) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof node.value === "string" && (value === void 0 || node.value === value);
|
|
81
54
|
/**
|
|
82
55
|
* Checks if the given `node` is a {@link StringNode}.
|
|
83
56
|
*/
|
|
@@ -86,16 +59,16 @@ const isStringNode = (node, specifics) => isStringLiteral(node, specifics) || is
|
|
|
86
59
|
* Gets the value of the given `AccessorNode`,
|
|
87
60
|
* account for the different node types.
|
|
88
61
|
*/
|
|
89
|
-
const getAccessorValue = (accessor) => accessor.type ===
|
|
62
|
+
const getAccessorValue = (accessor) => accessor.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier ? accessor.name : getStringValue(accessor);
|
|
90
63
|
/**
|
|
91
64
|
* Gets the value of the given `StringNode`.
|
|
92
65
|
*
|
|
93
66
|
* If the `node` is a `TemplateLiteral`, the `raw` value is used;
|
|
94
67
|
* otherwise, `value` is returned instead.
|
|
95
68
|
*/
|
|
96
|
-
const getStringValue = (node) => node?.type ===
|
|
69
|
+
const getStringValue = (node) => node?.type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral ? node.quasis[0].value.raw : node?.value;
|
|
97
70
|
const replaceAccessorFixer = (fixer, node, text) => {
|
|
98
|
-
return fixer.replaceText(node, node.type ===
|
|
71
|
+
return fixer.replaceText(node, node.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier ? text : `'${text}'`);
|
|
99
72
|
};
|
|
100
73
|
const removeExtraArgumentsFixer = (fixer, context, func, from) => {
|
|
101
74
|
const firstArg = func.arguments[from];
|
|
@@ -115,55 +88,55 @@ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__
|
|
|
115
88
|
|
|
116
89
|
//#endregion
|
|
117
90
|
//#region src/utils/types.ts
|
|
118
|
-
let UtilName = /* @__PURE__ */ function(UtilName
|
|
119
|
-
UtilName
|
|
120
|
-
UtilName
|
|
121
|
-
return UtilName
|
|
91
|
+
let UtilName = /* @__PURE__ */ function(UtilName) {
|
|
92
|
+
UtilName["vi"] = "vi";
|
|
93
|
+
UtilName["vitest"] = "vitest";
|
|
94
|
+
return UtilName;
|
|
122
95
|
}({});
|
|
123
|
-
let DescribeAlias = /* @__PURE__ */ function(DescribeAlias
|
|
124
|
-
DescribeAlias
|
|
125
|
-
DescribeAlias
|
|
126
|
-
DescribeAlias
|
|
127
|
-
return DescribeAlias
|
|
96
|
+
let DescribeAlias = /* @__PURE__ */ function(DescribeAlias) {
|
|
97
|
+
DescribeAlias["describe"] = "describe";
|
|
98
|
+
DescribeAlias["fdescribe"] = "fdescribe";
|
|
99
|
+
DescribeAlias["xdescribe"] = "xdescribe";
|
|
100
|
+
return DescribeAlias;
|
|
128
101
|
}({});
|
|
129
|
-
let TestCaseName = /* @__PURE__ */ function(TestCaseName
|
|
130
|
-
TestCaseName
|
|
131
|
-
TestCaseName
|
|
132
|
-
TestCaseName
|
|
133
|
-
TestCaseName
|
|
134
|
-
TestCaseName
|
|
135
|
-
TestCaseName
|
|
136
|
-
return TestCaseName
|
|
102
|
+
let TestCaseName = /* @__PURE__ */ function(TestCaseName) {
|
|
103
|
+
TestCaseName["fit"] = "fit";
|
|
104
|
+
TestCaseName["it"] = "it";
|
|
105
|
+
TestCaseName["test"] = "test";
|
|
106
|
+
TestCaseName["xit"] = "xit";
|
|
107
|
+
TestCaseName["xtest"] = "xtest";
|
|
108
|
+
TestCaseName["bench"] = "bench";
|
|
109
|
+
return TestCaseName;
|
|
137
110
|
}({});
|
|
138
|
-
let HookName = /* @__PURE__ */ function(HookName
|
|
139
|
-
HookName
|
|
140
|
-
HookName
|
|
141
|
-
HookName
|
|
142
|
-
HookName
|
|
143
|
-
return HookName
|
|
111
|
+
let HookName = /* @__PURE__ */ function(HookName) {
|
|
112
|
+
HookName["beforeAll"] = "beforeAll";
|
|
113
|
+
HookName["beforeEach"] = "beforeEach";
|
|
114
|
+
HookName["afterAll"] = "afterAll";
|
|
115
|
+
HookName["afterEach"] = "afterEach";
|
|
116
|
+
return HookName;
|
|
144
117
|
}({});
|
|
145
|
-
let ModifierName = /* @__PURE__ */ function(ModifierName
|
|
146
|
-
ModifierName
|
|
147
|
-
ModifierName
|
|
148
|
-
ModifierName
|
|
149
|
-
ModifierName
|
|
150
|
-
ModifierName
|
|
151
|
-
ModifierName
|
|
152
|
-
ModifierName
|
|
153
|
-
ModifierName
|
|
154
|
-
ModifierName
|
|
155
|
-
ModifierName
|
|
156
|
-
ModifierName
|
|
157
|
-
ModifierName
|
|
158
|
-
ModifierName
|
|
159
|
-
ModifierName
|
|
160
|
-
return ModifierName
|
|
118
|
+
let ModifierName = /* @__PURE__ */ function(ModifierName) {
|
|
119
|
+
ModifierName["to"] = "to";
|
|
120
|
+
ModifierName["have"] = "have";
|
|
121
|
+
ModifierName["not"] = "not";
|
|
122
|
+
ModifierName["rejects"] = "rejects";
|
|
123
|
+
ModifierName["resolves"] = "resolves";
|
|
124
|
+
ModifierName["returns"] = "returns";
|
|
125
|
+
ModifierName["branded"] = "branded";
|
|
126
|
+
ModifierName["asserts"] = "asserts";
|
|
127
|
+
ModifierName["constructorParameters"] = "constructorParameters";
|
|
128
|
+
ModifierName["parameters"] = "parameters";
|
|
129
|
+
ModifierName["thisParameter"] = "thisParameter";
|
|
130
|
+
ModifierName["guards"] = "guards";
|
|
131
|
+
ModifierName["instance"] = "instance";
|
|
132
|
+
ModifierName["items"] = "items";
|
|
133
|
+
return ModifierName;
|
|
161
134
|
}({});
|
|
162
|
-
let EqualityMatcher = /* @__PURE__ */ function(EqualityMatcher
|
|
163
|
-
EqualityMatcher
|
|
164
|
-
EqualityMatcher
|
|
165
|
-
EqualityMatcher
|
|
166
|
-
return EqualityMatcher
|
|
135
|
+
let EqualityMatcher = /* @__PURE__ */ function(EqualityMatcher) {
|
|
136
|
+
EqualityMatcher["toBe"] = "toBe";
|
|
137
|
+
EqualityMatcher["toEqual"] = "toEqual";
|
|
138
|
+
EqualityMatcher["toStrictEqual"] = "toStrictEqual";
|
|
139
|
+
return EqualityMatcher;
|
|
167
140
|
}({});
|
|
168
141
|
function isClassOrFunctionType(type) {
|
|
169
142
|
if (type.getCallSignatures().length > 0) return true;
|
|
@@ -1605,7 +1578,7 @@ const determineVitestFnType = (name) => {
|
|
|
1605
1578
|
const findModifiersAndMatcher = (members) => {
|
|
1606
1579
|
const modifiers = [];
|
|
1607
1580
|
for (const member of members) {
|
|
1608
|
-
if (member.parent?.type ===
|
|
1581
|
+
if (member.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && member.parent.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return {
|
|
1609
1582
|
matcher: member,
|
|
1610
1583
|
args: member.parent.parent.arguments,
|
|
1611
1584
|
modifiers
|
|
@@ -1635,12 +1608,12 @@ const findTopMostCallExpression = (node) => {
|
|
|
1635
1608
|
let topMostCallExpression = node;
|
|
1636
1609
|
let { parent } = node;
|
|
1637
1610
|
while (parent) {
|
|
1638
|
-
if (parent.type ===
|
|
1611
|
+
if (parent.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) {
|
|
1639
1612
|
topMostCallExpression = parent;
|
|
1640
1613
|
parent = parent.parent;
|
|
1641
1614
|
continue;
|
|
1642
1615
|
}
|
|
1643
|
-
if (parent.type !==
|
|
1616
|
+
if (parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) break;
|
|
1644
1617
|
parent = parent.parent;
|
|
1645
1618
|
}
|
|
1646
1619
|
return topMostCallExpression;
|
|
@@ -1651,9 +1624,9 @@ const parseVitestFnCallWithReasonInner = (node, context) => {
|
|
|
1651
1624
|
const [first, ...rest] = chain;
|
|
1652
1625
|
const lastLink = getAccessorValue(chain[chain.length - 1]);
|
|
1653
1626
|
if (lastLink === "each") {
|
|
1654
|
-
if (node.callee.type !==
|
|
1627
|
+
if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression) return null;
|
|
1655
1628
|
}
|
|
1656
|
-
if (node.callee.type ===
|
|
1629
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression && lastLink !== "each") return null;
|
|
1657
1630
|
const resolved = resolveVitestFn(context, node, getAccessorValue(first));
|
|
1658
1631
|
if (!resolved) return null;
|
|
1659
1632
|
const name = resolved.original ?? resolved.local;
|
|
@@ -1672,12 +1645,12 @@ const parseVitestFnCallWithReasonInner = (node, context) => {
|
|
|
1672
1645
|
const result = parseVitestExpectCall(parsedVitestFnCall, type);
|
|
1673
1646
|
if (typeof result === "string" && findTopMostCallExpression(node) !== node) return null;
|
|
1674
1647
|
if (result === "matcher-not-found") {
|
|
1675
|
-
if (node.parent?.type ===
|
|
1648
|
+
if (node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return "matcher-not-called";
|
|
1676
1649
|
}
|
|
1677
1650
|
return result;
|
|
1678
1651
|
}
|
|
1679
|
-
if (chain.slice(0, chain.length - 1).some((node
|
|
1680
|
-
if (node.parent?.type ===
|
|
1652
|
+
if (chain.slice(0, chain.length - 1).some((node) => node.parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression)) return null;
|
|
1653
|
+
if (node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression || node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
|
|
1681
1654
|
return {
|
|
1682
1655
|
...parsedVitestFnCall,
|
|
1683
1656
|
type
|
|
@@ -1687,9 +1660,9 @@ const joinChains = (a, b) => a && b ? [...a, ...b] : null;
|
|
|
1687
1660
|
function getNodeChain(node) {
|
|
1688
1661
|
if (isSupportedAccessor(node)) return [node];
|
|
1689
1662
|
switch (node.type) {
|
|
1690
|
-
case
|
|
1691
|
-
case
|
|
1692
|
-
case
|
|
1663
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression: return getNodeChain(node.tag);
|
|
1664
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression: return joinChains(getNodeChain(node.object), getNodeChain(node.property));
|
|
1665
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.CallExpression: return getNodeChain(node.callee);
|
|
1693
1666
|
}
|
|
1694
1667
|
return null;
|
|
1695
1668
|
}
|
|
@@ -1723,7 +1696,7 @@ const resolvePossibleAliasedGlobal = (global, context) => {
|
|
|
1723
1696
|
return null;
|
|
1724
1697
|
};
|
|
1725
1698
|
const isAncestorTestCaseCall = ({ parent }) => {
|
|
1726
|
-
return parent?.type ===
|
|
1699
|
+
return parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && parent.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && Object.prototype.hasOwnProperty.call(TestCaseName, parent.callee.name);
|
|
1727
1700
|
};
|
|
1728
1701
|
const resolveScope = (scope, identifier) => {
|
|
1729
1702
|
let currentScope = scope;
|
|
@@ -1731,13 +1704,13 @@ const resolveScope = (scope, identifier) => {
|
|
|
1731
1704
|
const ref = currentScope.set.get(identifier);
|
|
1732
1705
|
if (ref && ref.defs.length > 0) {
|
|
1733
1706
|
const def = ref.defs[ref.defs.length - 1];
|
|
1734
|
-
const objectParam = isFunction(def.node) ? def.node.params.find((params) => params.type ===
|
|
1707
|
+
const objectParam = isFunction(def.node) ? def.node.params.find((params) => params.type === _typescript_eslint_utils.AST_NODE_TYPES.ObjectPattern) : void 0;
|
|
1735
1708
|
if (objectParam) {
|
|
1736
|
-
const property = objectParam.properties.find((property
|
|
1737
|
-
if ((property?.key.type ===
|
|
1709
|
+
const property = objectParam.properties.find((property) => property.type === _typescript_eslint_utils.AST_NODE_TYPES.Property);
|
|
1710
|
+
if ((property?.key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier ? property.key : void 0)?.name === identifier) return "testContext";
|
|
1738
1711
|
}
|
|
1739
1712
|
/** if detect test function is created with `.extend()` */
|
|
1740
|
-
if (def.node.type ===
|
|
1713
|
+
if (def.node.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator && def.node.id.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && def.node.init?.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && def.node.init.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isIdentifier(def.node.init.callee.property, "extend")) {
|
|
1741
1714
|
const rootName = getNodeName(def.node.init.callee.object)?.split(".")[0];
|
|
1742
1715
|
if (rootName && rootName !== identifier) {
|
|
1743
1716
|
const resolved = resolveScope(currentScope, rootName);
|
|
@@ -1747,7 +1720,7 @@ const resolveScope = (scope, identifier) => {
|
|
|
1747
1720
|
};
|
|
1748
1721
|
}
|
|
1749
1722
|
}
|
|
1750
|
-
const namedParam = isFunction(def.node) ? def.node.params.find((params) => params.type ===
|
|
1723
|
+
const namedParam = isFunction(def.node) ? def.node.params.find((params) => params.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) : void 0;
|
|
1751
1724
|
if (namedParam && isAncestorTestCaseCall(namedParam.parent)) return "testContext";
|
|
1752
1725
|
const importDetails = describePossibleImportDef(def);
|
|
1753
1726
|
if (importDetails?.local === identifier) return importDetails;
|
|
@@ -1765,17 +1738,17 @@ const resolveScope = (scope, identifier) => {
|
|
|
1765
1738
|
* like an import), then `null` is returned instead.
|
|
1766
1739
|
*/
|
|
1767
1740
|
const findImportSourceNode = (node) => {
|
|
1768
|
-
if (node.type ===
|
|
1769
|
-
if (node.argument.type ===
|
|
1741
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression) {
|
|
1742
|
+
if (node.argument.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportExpression) return node.argument.source;
|
|
1770
1743
|
return null;
|
|
1771
1744
|
}
|
|
1772
|
-
if (node.type ===
|
|
1745
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && isIdentifier(node.callee, "require")) return node.arguments[0] ?? null;
|
|
1773
1746
|
return null;
|
|
1774
1747
|
};
|
|
1775
1748
|
const describeImportDefAsImport = (def) => {
|
|
1776
|
-
if (def.parent.type ===
|
|
1777
|
-
if (def.node.type !==
|
|
1778
|
-
if (def.node.imported.type !=
|
|
1749
|
+
if (def.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.TSImportEqualsDeclaration) return null;
|
|
1750
|
+
if (def.node.type !== _typescript_eslint_utils.AST_NODE_TYPES.ImportSpecifier) return null;
|
|
1751
|
+
if (def.node.imported.type != _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return null;
|
|
1779
1752
|
if (def.parent.importKind === "type") return null;
|
|
1780
1753
|
return {
|
|
1781
1754
|
source: def.parent.source.value,
|
|
@@ -1792,7 +1765,7 @@ const describeVariableDefAsImport = (def) => {
|
|
|
1792
1765
|
if (!def.node.init) return null;
|
|
1793
1766
|
const sourceNode = findImportSourceNode(def.node.init);
|
|
1794
1767
|
if (!sourceNode || !isStringNode(sourceNode)) return null;
|
|
1795
|
-
if (def.name.parent?.type !==
|
|
1768
|
+
if (def.name.parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.Property) return null;
|
|
1796
1769
|
if (!isSupportedAccessor(def.name.parent.key)) return null;
|
|
1797
1770
|
return {
|
|
1798
1771
|
source: getStringValue(sourceNode),
|
|
@@ -1801,14 +1774,14 @@ const describeVariableDefAsImport = (def) => {
|
|
|
1801
1774
|
};
|
|
1802
1775
|
};
|
|
1803
1776
|
const getTestCallExpressionsFromDeclaredVariables = (declaredVariables, context) => {
|
|
1804
|
-
return declaredVariables.reduce((acc, { references }) => acc.concat(references.map(({ identifier }) => identifier.parent).filter((node) => node?.type ===
|
|
1777
|
+
return declaredVariables.reduce((acc, { references }) => acc.concat(references.map(({ identifier }) => identifier.parent).filter((node) => node?.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && isTypeOfVitestFnCall(node, context, ["test"]))), []);
|
|
1805
1778
|
};
|
|
1806
1779
|
const getFirstMatcherArg = (expectFnCall) => {
|
|
1807
1780
|
const [firstArg] = expectFnCall.args;
|
|
1808
|
-
if (firstArg.type ===
|
|
1781
|
+
if (firstArg.type === _typescript_eslint_utils.AST_NODE_TYPES.SpreadElement) return firstArg;
|
|
1809
1782
|
return followTypeAssertionChain$1(firstArg);
|
|
1810
1783
|
};
|
|
1811
|
-
const isTypeCastExpression$1 = (node) => node.type ===
|
|
1784
|
+
const isTypeCastExpression$1 = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.TSAsExpression || node.type === _typescript_eslint_utils.AST_NODE_TYPES.TSTypeAssertion;
|
|
1812
1785
|
const followTypeAssertionChain$1 = (expression) => isTypeCastExpression$1(expression) ? followTypeAssertionChain$1(expression.expression) : expression;
|
|
1813
1786
|
|
|
1814
1787
|
//#endregion
|
|
@@ -1931,7 +1904,7 @@ var consistent_test_filename_default = createEslintRule({
|
|
|
1931
1904
|
//#endregion
|
|
1932
1905
|
//#region src/rules/consistent-test-it.ts
|
|
1933
1906
|
const RULE_NAME$78 = "consistent-test-it";
|
|
1934
|
-
const buildFixer = (callee, nodeName, preferredTestKeyword) => (fixer) => [fixer.replaceText(callee.type ===
|
|
1907
|
+
const buildFixer = (callee, nodeName, preferredTestKeyword) => (fixer) => [fixer.replaceText(callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression ? callee.object : callee, getPreferredNodeName(nodeName, preferredTestKeyword))];
|
|
1935
1908
|
function getPreferredNodeName(nodeName, preferredTestKeyword) {
|
|
1936
1909
|
if (nodeName === TestCaseName.fit) return "test.only";
|
|
1937
1910
|
return nodeName.startsWith("f") || nodeName.startsWith("x") ? nodeName.charAt(0) + preferredTestKeyword : preferredTestKeyword;
|
|
@@ -1995,7 +1968,7 @@ var consistent_test_it_default = createEslintRule({
|
|
|
1995
1968
|
fix: (fixer) => {
|
|
1996
1969
|
const remainingSpecifiers = node.specifiers.filter((spec) => spec !== specifier);
|
|
1997
1970
|
if (remainingSpecifiers.length > 0) {
|
|
1998
|
-
const hasPreferredSpecifier = remainingSpecifiers.some((spec) => spec.type ===
|
|
1971
|
+
const hasPreferredSpecifier = remainingSpecifiers.some((spec) => spec.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportSpecifier && spec.imported.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && spec.imported.name === testFnDisabled);
|
|
1999
1972
|
const importNames = remainingSpecifiers.map((spec) => sourceCode.getText(spec));
|
|
2000
1973
|
if (!hasPreferredSpecifier) importNames.push(testFnDisabled);
|
|
2001
1974
|
const importText = importNames.join(", ");
|
|
@@ -2009,14 +1982,14 @@ var consistent_test_it_default = createEslintRule({
|
|
|
2009
1982
|
}
|
|
2010
1983
|
},
|
|
2011
1984
|
CallExpression(node) {
|
|
2012
|
-
if (node.callee.type ===
|
|
1985
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && node.callee.name === "bench") return;
|
|
2013
1986
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
2014
1987
|
if (!vitestFnCall) return;
|
|
2015
1988
|
if (vitestFnCall.type === "describe") {
|
|
2016
1989
|
describeNestingLevel++;
|
|
2017
1990
|
return;
|
|
2018
1991
|
}
|
|
2019
|
-
const funcNode = node.callee.type ===
|
|
1992
|
+
const funcNode = node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
|
2020
1993
|
if (vitestFnCall.type === "test" && describeNestingLevel === 0 && !vitestFnCall.name.endsWith(testFnKeyWork)) {
|
|
2021
1994
|
const oppositeTestKeyword = getOppositeTestKeyword(testFnKeyWork);
|
|
2022
1995
|
context.report({
|
|
@@ -2077,10 +2050,10 @@ var consistent_vitest_vi_default = createEslintRule({
|
|
|
2077
2050
|
const oppositeUtilKeyword = getOppositeVitestUtilKeyword(utilKeyword);
|
|
2078
2051
|
return {
|
|
2079
2052
|
ImportDeclaration(node) {
|
|
2080
|
-
if (node.source.type !==
|
|
2053
|
+
if (node.source.type !== _typescript_eslint_utils.AST_NODE_TYPES.Literal || node.source.value !== "vitest") return;
|
|
2081
2054
|
for (const specifier of node.specifiers) {
|
|
2082
|
-
if (specifier.type !==
|
|
2083
|
-
if (specifier.imported.type !==
|
|
2055
|
+
if (specifier.type !== _typescript_eslint_utils.AST_NODE_TYPES.ImportSpecifier) continue;
|
|
2056
|
+
if (specifier.imported.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) continue;
|
|
2084
2057
|
if (specifier.local.name !== specifier.imported.name) continue;
|
|
2085
2058
|
if (specifier.imported.name === oppositeUtilKeyword) context.report({
|
|
2086
2059
|
node: specifier,
|
|
@@ -2106,7 +2079,7 @@ var consistent_vitest_vi_default = createEslintRule({
|
|
|
2106
2079
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
2107
2080
|
if (vitestFnCall?.type !== "vi") return;
|
|
2108
2081
|
if (!isSupportedAccessor(vitestFnCall.head.node, oppositeUtilKeyword)) return;
|
|
2109
|
-
const replaceNode = node.callee.type ===
|
|
2082
|
+
const replaceNode = node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression ? node.callee.object : node.callee;
|
|
2110
2083
|
context.report({
|
|
2111
2084
|
node: replaceNode,
|
|
2112
2085
|
data: {
|
|
@@ -2169,8 +2142,8 @@ var expect_expect_default = createEslintRule({
|
|
|
2169
2142
|
const assertFunctionRegexps = assertFunctionNames.map(buildPatternRegexp);
|
|
2170
2143
|
function checkCallExpression(nodes) {
|
|
2171
2144
|
for (const node of nodes) {
|
|
2172
|
-
const index = node.type ===
|
|
2173
|
-
if (node.type ===
|
|
2145
|
+
const index = node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression ? unchecked.indexOf(node) : -1;
|
|
2146
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.FunctionDeclaration) checkCallExpression(getTestCallExpressionsFromDeclaredVariables(context.sourceCode.getDeclaredVariables(node), context));
|
|
2174
2147
|
if (index !== -1) {
|
|
2175
2148
|
unchecked.splice(index, 1);
|
|
2176
2149
|
break;
|
|
@@ -2179,15 +2152,15 @@ var expect_expect_default = createEslintRule({
|
|
|
2179
2152
|
}
|
|
2180
2153
|
return {
|
|
2181
2154
|
CallExpression(node) {
|
|
2182
|
-
if (node.callee.type ===
|
|
2183
|
-
if (node?.callee?.type ===
|
|
2155
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && node.callee.name === "bench") return;
|
|
2156
|
+
if (node?.callee?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && node.callee.property.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && [
|
|
2184
2157
|
"skip",
|
|
2185
2158
|
"extend",
|
|
2186
2159
|
"scoped"
|
|
2187
2160
|
].includes(node.callee.property.name)) return;
|
|
2188
2161
|
const name = getNodeName(node) ?? "";
|
|
2189
2162
|
if (isTypeOfVitestFnCall(node, context, ["test"]) || additionalTestBlockFunctions.includes(name)) {
|
|
2190
|
-
if (node.callee.type ===
|
|
2163
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, "todo")) return;
|
|
2191
2164
|
unchecked.push(node);
|
|
2192
2165
|
} else if (assertFunctionRegexps.some((p) => p.test(name))) checkCallExpression(context.sourceCode.getAncestors(node));
|
|
2193
2166
|
},
|
|
@@ -2236,21 +2209,21 @@ var hoisted_apis_on_top_default = createEslintRule({
|
|
|
2236
2209
|
const nodesToReport = [];
|
|
2237
2210
|
return {
|
|
2238
2211
|
ImportDeclaration(node) {
|
|
2239
|
-
if (node.parent.type !==
|
|
2212
|
+
if (node.parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.Program) return;
|
|
2240
2213
|
lastImportEnd = node.range[1];
|
|
2241
2214
|
},
|
|
2242
2215
|
CallExpression(node) {
|
|
2243
|
-
if (node.callee.type !==
|
|
2216
|
+
if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return;
|
|
2244
2217
|
const { object, property } = node.callee;
|
|
2245
|
-
if (object.type !==
|
|
2218
|
+
if (object.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier || object.name !== "vi" || property.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
|
|
2246
2219
|
const apiName = property.name;
|
|
2247
2220
|
if (!hoistedAPIs.includes(apiName)) return;
|
|
2248
2221
|
if (apiName === "hoisted") {
|
|
2249
2222
|
let parent = node.parent;
|
|
2250
|
-
if (parent?.type ===
|
|
2251
|
-
if (parent?.type ===
|
|
2252
|
-
if ((parent?.type ===
|
|
2253
|
-
} else if (node.parent?.type ===
|
|
2223
|
+
if (parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression) parent = parent.parent;
|
|
2224
|
+
if (parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator) parent = parent.parent;
|
|
2225
|
+
if ((parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement || parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclaration) && parent.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.Program) return;
|
|
2226
|
+
} else if (node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement && node.parent.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.Program) return;
|
|
2254
2227
|
nodesToReport.push(node);
|
|
2255
2228
|
},
|
|
2256
2229
|
"Program:exit"() {
|
|
@@ -2259,7 +2232,7 @@ var hoisted_apis_on_top_default = createEslintRule({
|
|
|
2259
2232
|
suggestions.push({
|
|
2260
2233
|
messageId: "suggestMoveHoistedApiToTop",
|
|
2261
2234
|
*fix(fixer) {
|
|
2262
|
-
if (node.parent.type ===
|
|
2235
|
+
if (node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement) yield fixer.remove(node);
|
|
2263
2236
|
else yield fixer.replaceText(node, "undefined");
|
|
2264
2237
|
if (lastImportEnd != null) yield fixer.insertTextAfterRange([lastImportEnd, lastImportEnd], "\n" + context.sourceCode.getText(node) + ";");
|
|
2265
2238
|
else yield fixer.insertTextAfterRange([0, 0], context.sourceCode.getText(node) + ";\n");
|
|
@@ -2306,7 +2279,7 @@ var max_expects_default = createEslintRule({
|
|
|
2306
2279
|
create(context, [{ max }]) {
|
|
2307
2280
|
let assertsCount = 0;
|
|
2308
2281
|
const resetAssertCount = (node) => {
|
|
2309
|
-
if (node.parent?.type !==
|
|
2282
|
+
if (node.parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression || isTypeOfVitestFnCall(node.parent, context, ["test"])) assertsCount = 0;
|
|
2310
2283
|
};
|
|
2311
2284
|
return {
|
|
2312
2285
|
FunctionExpression: resetAssertCount,
|
|
@@ -2315,7 +2288,7 @@ var max_expects_default = createEslintRule({
|
|
|
2315
2288
|
"ArrowFunctionExpression:exit": resetAssertCount,
|
|
2316
2289
|
CallExpression(node) {
|
|
2317
2290
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
2318
|
-
if (vitestFnCall?.type !== "expect" || vitestFnCall.head.node.parent?.type ===
|
|
2291
|
+
if (vitestFnCall?.type !== "expect" || vitestFnCall.head.node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return;
|
|
2319
2292
|
assertsCount += 1;
|
|
2320
2293
|
if (assertsCount > max) context.report({
|
|
2321
2294
|
node,
|
|
@@ -2461,7 +2434,7 @@ var no_commented_out_tests_default = createEslintRule({
|
|
|
2461
2434
|
//#endregion
|
|
2462
2435
|
//#region src/rules/no-conditional-expect.ts
|
|
2463
2436
|
const RULE_NAME$70 = "no-conditional-expect";
|
|
2464
|
-
const isCatchCall = (node) => node.callee.type ===
|
|
2437
|
+
const isCatchCall = (node) => node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, "catch");
|
|
2465
2438
|
var no_conditional_expect_default = createEslintRule({
|
|
2466
2439
|
name: RULE_NAME$70,
|
|
2467
2440
|
meta: {
|
|
@@ -2691,17 +2664,17 @@ var no_done_callback_default = createEslintRule({
|
|
|
2691
2664
|
create(context) {
|
|
2692
2665
|
return { CallExpression(node) {
|
|
2693
2666
|
const isVitestEach = /\.each$|\.for$|\.concurrent$/.test(getNodeName(node.callee) ?? "");
|
|
2694
|
-
if (isVitestEach && node.callee.type !==
|
|
2667
|
+
if (isVitestEach && node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression) return;
|
|
2695
2668
|
if (context.sourceCode.getAncestors(node).some((ancestor) => {
|
|
2696
|
-
if (ancestor.type !==
|
|
2669
|
+
if (ancestor.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return false;
|
|
2697
2670
|
if (!isTypeOfVitestFnCall(ancestor, context, ["describe", "test"])) return false;
|
|
2698
|
-
return ancestor.callee.type ===
|
|
2671
|
+
return ancestor.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(ancestor.callee.property, "concurrent");
|
|
2699
2672
|
})) return;
|
|
2700
2673
|
const callback = findCallbackArg(node, isVitestEach, context);
|
|
2701
2674
|
const callbackArgIndex = Number(isVitestEach);
|
|
2702
2675
|
if (!callback || !isFunction(callback) || callback.params.length !== 1 + callbackArgIndex) return;
|
|
2703
2676
|
const argument = callback.params[callbackArgIndex];
|
|
2704
|
-
if (argument.type !==
|
|
2677
|
+
if (argument.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) {
|
|
2705
2678
|
context.report({
|
|
2706
2679
|
node: argument,
|
|
2707
2680
|
messageId: "noDoneCallback"
|
|
@@ -2737,7 +2710,7 @@ var no_done_callback_default = createEslintRule({
|
|
|
2737
2710
|
let beforeReplacement = `new Promise(${argument.name} => `;
|
|
2738
2711
|
let afterReplacement = ")";
|
|
2739
2712
|
let replaceBefore = true;
|
|
2740
|
-
if (body.type ===
|
|
2713
|
+
if (body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) {
|
|
2741
2714
|
beforeReplacement = `return ${beforeReplacement}{`;
|
|
2742
2715
|
afterReplacement += "}";
|
|
2743
2716
|
replaceBefore = false;
|
|
@@ -3015,21 +2988,21 @@ const isVitestImport = (node) => {
|
|
|
3015
2988
|
return node.source.value === "vitest";
|
|
3016
2989
|
};
|
|
3017
2990
|
const isVitestGlobalsImportSpecifier = (specifier) => {
|
|
3018
|
-
return specifier.type ===
|
|
2991
|
+
return specifier.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && VITEST_GLOBALS.has(specifier.imported.name);
|
|
3019
2992
|
};
|
|
3020
2993
|
const isVitestGlobalsProperty = (prop) => {
|
|
3021
|
-
return prop.type ===
|
|
2994
|
+
return prop.type === _typescript_eslint_utils.AST_NODE_TYPES.Property && prop.key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && VITEST_GLOBALS.has(prop.key.name);
|
|
3022
2995
|
};
|
|
3023
2996
|
const isVitestGlobalsFunction = (node) => {
|
|
3024
|
-
return node.callee.type ===
|
|
2997
|
+
return node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && VITEST_GLOBALS.has(node.callee.name);
|
|
3025
2998
|
};
|
|
3026
2999
|
const isRequireVitestCall = (node) => {
|
|
3027
|
-
if (node?.type !==
|
|
3000
|
+
if (node?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression || node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier || node.callee.name !== "require") return false;
|
|
3028
3001
|
const args = node.arguments;
|
|
3029
|
-
return args.length === 1 && args[0].type ===
|
|
3002
|
+
return args.length === 1 && args[0].type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && args[0].value === "vitest";
|
|
3030
3003
|
};
|
|
3031
3004
|
const isObjectPattern = (node) => {
|
|
3032
|
-
return node.type ===
|
|
3005
|
+
return node.type === _typescript_eslint_utils.AST_NODE_TYPES.ObjectPattern;
|
|
3033
3006
|
};
|
|
3034
3007
|
|
|
3035
3008
|
//#endregion
|
|
@@ -3136,7 +3109,7 @@ var no_interpolation_in_snapshots_default = createEslintRule({
|
|
|
3136
3109
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
3137
3110
|
if (vitestFnCall?.type !== "expect") return;
|
|
3138
3111
|
if (["toMatchInlineSnapshot", "toThrowErrorMatchingInlineSnapshot"].includes(getAccessorValue(vitestFnCall.matcher))) vitestFnCall.args.forEach((argument) => {
|
|
3139
|
-
if (argument.type ===
|
|
3112
|
+
if (argument.type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral && argument.expressions.length > 0) context.report({
|
|
3140
3113
|
messageId: "noInterpolationInSnapshots",
|
|
3141
3114
|
node: argument
|
|
3142
3115
|
});
|
|
@@ -3153,7 +3126,7 @@ const reportOnViolation = (context, node, { maxSize: lineLimit = 50, allowedSnap
|
|
|
3153
3126
|
const lineCount = node.loc.end.line - startLine;
|
|
3154
3127
|
if (!Object.keys(allowedSnapshots).every(node_path.isAbsolute)) throw new Error("All paths for allowedSnapshots must be absolute. You can use JS config and `path.resolve`");
|
|
3155
3128
|
let isAllowed = false;
|
|
3156
|
-
if (node.type ===
|
|
3129
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement && "left" in node.expression && node.expression.left.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.expression.left.property)) {
|
|
3157
3130
|
const allowedSnapshotsInFile = allowedSnapshots[context.filename];
|
|
3158
3131
|
if (allowedSnapshotsInFile) {
|
|
3159
3132
|
const snapshotName = getAccessorValue(node.expression.left.property);
|
|
@@ -3278,7 +3251,7 @@ var no_restricted_matchers_default = createEslintRule({
|
|
|
3278
3251
|
return { CallExpression(node) {
|
|
3279
3252
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
3280
3253
|
if (vitestFnCall?.type !== "expect") return;
|
|
3281
|
-
const chain = vitestFnCall.members.map((node
|
|
3254
|
+
const chain = vitestFnCall.members.map((node) => getAccessorValue(node)).join(".");
|
|
3282
3255
|
for (const [restriction, message] of Object.entries(restrictedChains)) if (isChainRestricted(chain, restriction)) {
|
|
3283
3256
|
context.report({
|
|
3284
3257
|
messageId: message ? "restrictedChainWithMessage" : "restrictedChain",
|
|
@@ -3347,11 +3320,11 @@ const RULE_NAME$54 = "no-standalone-expect";
|
|
|
3347
3320
|
const getBlockType = (statement, context) => {
|
|
3348
3321
|
const func = statement.parent;
|
|
3349
3322
|
if (!func) throw new Error("Unexpected block statement. If you feel like this is a bug report https://github.com/veritem/eslint-plugin-vitest/issues/new");
|
|
3350
|
-
if (func.type ===
|
|
3323
|
+
if (func.type === _typescript_eslint_utils.AST_NODE_TYPES.FunctionDeclaration) return "function";
|
|
3351
3324
|
if (isFunction(func) && func.parent) {
|
|
3352
3325
|
const expr = func.parent;
|
|
3353
|
-
if (expr.type ===
|
|
3354
|
-
if (expr.type ===
|
|
3326
|
+
if (expr.type === _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator) return "function";
|
|
3327
|
+
if (expr.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && isTypeOfVitestFnCall(expr, context, ["describe"])) return "describe";
|
|
3355
3328
|
}
|
|
3356
3329
|
return null;
|
|
3357
3330
|
};
|
|
@@ -3381,7 +3354,7 @@ var no_standalone_expect_default = createEslintRule({
|
|
|
3381
3354
|
CallExpression(node) {
|
|
3382
3355
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
3383
3356
|
if (vitestFnCall?.type === "expect") {
|
|
3384
|
-
if (vitestFnCall.head.node.parent?.type ===
|
|
3357
|
+
if (vitestFnCall.head.node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && vitestFnCall.members.length === 1 && !["assertions", "hasAssertions"].includes(getAccessorValue(vitestFnCall.members[0]))) return;
|
|
3385
3358
|
const parent = callStack[callStack.length - 1];
|
|
3386
3359
|
if (!parent || parent === DescribeAlias.describe) context.report({
|
|
3387
3360
|
node,
|
|
@@ -3390,11 +3363,11 @@ var no_standalone_expect_default = createEslintRule({
|
|
|
3390
3363
|
return;
|
|
3391
3364
|
}
|
|
3392
3365
|
if (vitestFnCall?.type === "test" || isCustomTestBlockFunction(node)) callStack.push("test");
|
|
3393
|
-
if (node.callee.type ===
|
|
3366
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression) callStack.push("template");
|
|
3394
3367
|
},
|
|
3395
3368
|
"CallExpression:exit"(node) {
|
|
3396
3369
|
const top = callStack[callStack.length - 1];
|
|
3397
|
-
if (top === "test" && (isTypeOfVitestFnCall(node, context, ["test"]) || isCustomTestBlockFunction(node)) && node.callee.type !==
|
|
3370
|
+
if (top === "test" && (isTypeOfVitestFnCall(node, context, ["test"]) || isCustomTestBlockFunction(node)) && node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || top === "template" && node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression) callStack.pop();
|
|
3398
3371
|
},
|
|
3399
3372
|
BlockStatement(statement) {
|
|
3400
3373
|
const blockType = getBlockType(statement, context);
|
|
@@ -3404,7 +3377,7 @@ var no_standalone_expect_default = createEslintRule({
|
|
|
3404
3377
|
if (getBlockType(statement, context)) callStack.pop();
|
|
3405
3378
|
},
|
|
3406
3379
|
ArrowFunctionExpression(node) {
|
|
3407
|
-
if (node.parent?.type !==
|
|
3380
|
+
if (node.parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) callStack.push("arrow");
|
|
3408
3381
|
},
|
|
3409
3382
|
"ArrowFunctionExpression:exit"() {
|
|
3410
3383
|
if (callStack[callStack.length - 1] === "arrow") callStack.pop();
|
|
@@ -3438,7 +3411,7 @@ var no_test_prefixes_default = createEslintRule({
|
|
|
3438
3411
|
vitestFnCall.name[0] === "f" ? "only" : "skip",
|
|
3439
3412
|
...vitestFnCall.members.map((m) => getAccessorValue(m))
|
|
3440
3413
|
].join(".");
|
|
3441
|
-
const funcNode = node.callee.type ===
|
|
3414
|
+
const funcNode = node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
|
3442
3415
|
context.report({
|
|
3443
3416
|
messageId: "usePreferredName",
|
|
3444
3417
|
node: node.callee,
|
|
@@ -3454,7 +3427,7 @@ var no_test_prefixes_default = createEslintRule({
|
|
|
3454
3427
|
const RULE_NAME$52 = "no-test-return-statement";
|
|
3455
3428
|
const getBody = (args) => {
|
|
3456
3429
|
const [, secondArg] = args;
|
|
3457
|
-
if (secondArg && isFunction(secondArg) && secondArg.body.type ===
|
|
3430
|
+
if (secondArg && isFunction(secondArg) && secondArg.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) return secondArg.body.body;
|
|
3458
3431
|
return [];
|
|
3459
3432
|
};
|
|
3460
3433
|
var no_test_return_statement_default = createEslintRule({
|
|
@@ -3472,7 +3445,7 @@ var no_test_return_statement_default = createEslintRule({
|
|
|
3472
3445
|
return {
|
|
3473
3446
|
CallExpression(node) {
|
|
3474
3447
|
if (!isTypeOfVitestFnCall(node, context, ["test"])) return;
|
|
3475
|
-
const returnStmt = getBody(node.arguments).find((stmt) => stmt.type ===
|
|
3448
|
+
const returnStmt = getBody(node.arguments).find((stmt) => stmt.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement);
|
|
3476
3449
|
if (!returnStmt) return;
|
|
3477
3450
|
context.report({
|
|
3478
3451
|
messageId: "noTestReturnStatement",
|
|
@@ -3481,7 +3454,7 @@ var no_test_return_statement_default = createEslintRule({
|
|
|
3481
3454
|
},
|
|
3482
3455
|
FunctionDeclaration(node) {
|
|
3483
3456
|
if (getTestCallExpressionsFromDeclaredVariables(context.sourceCode.getDeclaredVariables(node), context).length === 0) return;
|
|
3484
|
-
const returnStmt = node.body.body.find((stmt) => stmt.type ===
|
|
3457
|
+
const returnStmt = node.body.body.find((stmt) => stmt.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement);
|
|
3485
3458
|
if (!returnStmt) return;
|
|
3486
3459
|
context.report({
|
|
3487
3460
|
messageId: "noTestReturnStatement",
|
|
@@ -3497,15 +3470,15 @@ var no_test_return_statement_default = createEslintRule({
|
|
|
3497
3470
|
const eslintRequire = (0, node_module.createRequire)((0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve("eslint"));
|
|
3498
3471
|
const espreeParser = eslintRequire.resolve("espree");
|
|
3499
3472
|
const STATEMENT_LIST_PARENTS = new Set([
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3473
|
+
_typescript_eslint_utils.AST_NODE_TYPES.Program,
|
|
3474
|
+
_typescript_eslint_utils.AST_NODE_TYPES.BlockStatement,
|
|
3475
|
+
_typescript_eslint_utils.AST_NODE_TYPES.SwitchCase,
|
|
3476
|
+
_typescript_eslint_utils.AST_NODE_TYPES.SwitchStatement
|
|
3504
3477
|
]);
|
|
3505
3478
|
const isValidParent = (parentType) => {
|
|
3506
3479
|
return STATEMENT_LIST_PARENTS.has(parentType);
|
|
3507
3480
|
};
|
|
3508
|
-
const isTokenASemicolon = (token) => token.value === ";" && token.type ===
|
|
3481
|
+
const isTokenASemicolon = (token) => token.value === ";" && token.type === _typescript_eslint_utils.AST_TOKEN_TYPES.Punctuator;
|
|
3509
3482
|
/**
|
|
3510
3483
|
* Gets the actual last token.
|
|
3511
3484
|
*
|
|
@@ -3533,33 +3506,33 @@ const getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
|
|
|
3533
3506
|
return pairs;
|
|
3534
3507
|
};
|
|
3535
3508
|
const areTokensOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
|
|
3536
|
-
const isTypeCastExpression = (node) => node.type ===
|
|
3509
|
+
const isTypeCastExpression = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.TSAsExpression || node.type === _typescript_eslint_utils.AST_NODE_TYPES.TSTypeAssertion;
|
|
3537
3510
|
const followTypeAssertionChain = (expression) => isTypeCastExpression(expression) ? followTypeAssertionChain(expression.expression) : expression;
|
|
3538
3511
|
|
|
3539
3512
|
//#endregion
|
|
3540
3513
|
//#region src/utils/padding.ts
|
|
3541
|
-
let PaddingType = /* @__PURE__ */ function(PaddingType
|
|
3542
|
-
PaddingType
|
|
3543
|
-
PaddingType
|
|
3544
|
-
return PaddingType
|
|
3514
|
+
let PaddingType = /* @__PURE__ */ function(PaddingType) {
|
|
3515
|
+
PaddingType[PaddingType["Any"] = 0] = "Any";
|
|
3516
|
+
PaddingType[PaddingType["Always"] = 1] = "Always";
|
|
3517
|
+
return PaddingType;
|
|
3545
3518
|
}({});
|
|
3546
|
-
let StatementType = /* @__PURE__ */ function(StatementType
|
|
3547
|
-
StatementType
|
|
3548
|
-
StatementType
|
|
3549
|
-
StatementType
|
|
3550
|
-
StatementType
|
|
3551
|
-
StatementType
|
|
3552
|
-
StatementType
|
|
3553
|
-
StatementType
|
|
3554
|
-
StatementType
|
|
3555
|
-
StatementType
|
|
3556
|
-
StatementType
|
|
3557
|
-
StatementType
|
|
3558
|
-
StatementType
|
|
3559
|
-
StatementType
|
|
3560
|
-
StatementType
|
|
3561
|
-
StatementType
|
|
3562
|
-
return StatementType
|
|
3519
|
+
let StatementType = /* @__PURE__ */ function(StatementType) {
|
|
3520
|
+
StatementType[StatementType["Any"] = 0] = "Any";
|
|
3521
|
+
StatementType[StatementType["AfterAllToken"] = 1] = "AfterAllToken";
|
|
3522
|
+
StatementType[StatementType["AfterEachToken"] = 2] = "AfterEachToken";
|
|
3523
|
+
StatementType[StatementType["BeforeAllToken"] = 3] = "BeforeAllToken";
|
|
3524
|
+
StatementType[StatementType["BeforeEachToken"] = 4] = "BeforeEachToken";
|
|
3525
|
+
StatementType[StatementType["DescribeToken"] = 5] = "DescribeToken";
|
|
3526
|
+
StatementType[StatementType["ExpectToken"] = 6] = "ExpectToken";
|
|
3527
|
+
StatementType[StatementType["ExpectTypeOfToken"] = 7] = "ExpectTypeOfToken";
|
|
3528
|
+
StatementType[StatementType["FdescribeToken"] = 8] = "FdescribeToken";
|
|
3529
|
+
StatementType[StatementType["FitToken"] = 9] = "FitToken";
|
|
3530
|
+
StatementType[StatementType["ItToken"] = 10] = "ItToken";
|
|
3531
|
+
StatementType[StatementType["TestToken"] = 11] = "TestToken";
|
|
3532
|
+
StatementType[StatementType["XdescribeToken"] = 12] = "XdescribeToken";
|
|
3533
|
+
StatementType[StatementType["XitToken"] = 13] = "XitToken";
|
|
3534
|
+
StatementType[StatementType["XtestToken"] = 14] = "XtestToken";
|
|
3535
|
+
return StatementType;
|
|
3563
3536
|
}({});
|
|
3564
3537
|
const paddingAlwaysTester = (prevNode, nextNode, paddingContext) => {
|
|
3565
3538
|
const { sourceCode, ruleContext } = paddingContext;
|
|
@@ -3611,10 +3584,10 @@ const createScopeInfo = () => {
|
|
|
3611
3584
|
const createTokenTester = (tokenName) => {
|
|
3612
3585
|
return (node, sourceCode) => {
|
|
3613
3586
|
let activeNode = node;
|
|
3614
|
-
if (activeNode.type ===
|
|
3615
|
-
if (activeNode.expression.type ===
|
|
3587
|
+
if (activeNode.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement) {
|
|
3588
|
+
if (activeNode.expression.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression) activeNode = activeNode.expression.argument;
|
|
3616
3589
|
const token = sourceCode.getFirstToken(activeNode);
|
|
3617
|
-
return token?.type ===
|
|
3590
|
+
return token?.type === _typescript_eslint_utils.AST_TOKEN_TYPES.Identifier && token.value === tokenName;
|
|
3618
3591
|
}
|
|
3619
3592
|
return false;
|
|
3620
3593
|
};
|
|
@@ -3642,7 +3615,7 @@ const statementTesters = {
|
|
|
3642
3615
|
const nodeMatchesType = (node, statementType, paddingContext) => {
|
|
3643
3616
|
let innerStatementNode = node;
|
|
3644
3617
|
const { sourceCode } = paddingContext;
|
|
3645
|
-
while (innerStatementNode.type ===
|
|
3618
|
+
while (innerStatementNode.type === _typescript_eslint_utils.AST_NODE_TYPES.LabeledStatement) innerStatementNode = innerStatementNode.body;
|
|
3646
3619
|
if (Array.isArray(statementType)) return statementType.some((type) => nodeMatchesType(innerStatementNode, type, paddingContext));
|
|
3647
3620
|
return statementTesters[statementType](innerStatementNode, sourceCode);
|
|
3648
3621
|
};
|
|
@@ -3729,7 +3702,7 @@ const createPaddingRule = (name, description, configs, deprecated = false) => {
|
|
|
3729
3702
|
//#endregion
|
|
3730
3703
|
//#region src/rules/padding-around-after-all-blocks.ts
|
|
3731
3704
|
const RULE_NAME$51 = "padding-around-after-all-blocks";
|
|
3732
|
-
const config = [{
|
|
3705
|
+
const config$6 = [{
|
|
3733
3706
|
paddingType: PaddingType.Always,
|
|
3734
3707
|
prevStatementType: StatementType.Any,
|
|
3735
3708
|
nextStatementType: StatementType.AfterAllToken
|
|
@@ -3738,12 +3711,12 @@ const config = [{
|
|
|
3738
3711
|
prevStatementType: StatementType.AfterAllToken,
|
|
3739
3712
|
nextStatementType: StatementType.Any
|
|
3740
3713
|
}];
|
|
3741
|
-
var padding_around_after_all_blocks_default = createPaddingRule(RULE_NAME$51, "Enforce padding around `afterAll` blocks", config);
|
|
3714
|
+
var padding_around_after_all_blocks_default = createPaddingRule(RULE_NAME$51, "Enforce padding around `afterAll` blocks", config$6);
|
|
3742
3715
|
|
|
3743
3716
|
//#endregion
|
|
3744
3717
|
//#region src/rules/padding-around-after-each-blocks.ts
|
|
3745
3718
|
const RULE_NAME$50 = "padding-around-after-each-blocks";
|
|
3746
|
-
const config$
|
|
3719
|
+
const config$5 = [{
|
|
3747
3720
|
paddingType: PaddingType.Always,
|
|
3748
3721
|
prevStatementType: StatementType.Any,
|
|
3749
3722
|
nextStatementType: StatementType.AfterEachToken
|
|
@@ -3752,12 +3725,12 @@ const config$1 = [{
|
|
|
3752
3725
|
prevStatementType: StatementType.AfterEachToken,
|
|
3753
3726
|
nextStatementType: StatementType.Any
|
|
3754
3727
|
}];
|
|
3755
|
-
var padding_around_after_each_blocks_default = createPaddingRule(RULE_NAME$50, "Enforce padding around `afterEach` blocks", config$
|
|
3728
|
+
var padding_around_after_each_blocks_default = createPaddingRule(RULE_NAME$50, "Enforce padding around `afterEach` blocks", config$5);
|
|
3756
3729
|
|
|
3757
3730
|
//#endregion
|
|
3758
3731
|
//#region src/rules/padding-around-before-all-blocks.ts
|
|
3759
3732
|
const RULE_NAME$49 = "padding-around-before-all-blocks";
|
|
3760
|
-
const config$
|
|
3733
|
+
const config$4 = [{
|
|
3761
3734
|
paddingType: PaddingType.Always,
|
|
3762
3735
|
prevStatementType: StatementType.Any,
|
|
3763
3736
|
nextStatementType: StatementType.BeforeAllToken
|
|
@@ -3766,7 +3739,7 @@ const config$2 = [{
|
|
|
3766
3739
|
prevStatementType: StatementType.BeforeAllToken,
|
|
3767
3740
|
nextStatementType: StatementType.Any
|
|
3768
3741
|
}];
|
|
3769
|
-
var padding_around_before_all_blocks_default = createPaddingRule(RULE_NAME$49, "Enforce padding around `beforeAll` blocks", config$
|
|
3742
|
+
var padding_around_before_all_blocks_default = createPaddingRule(RULE_NAME$49, "Enforce padding around `beforeAll` blocks", config$4);
|
|
3770
3743
|
|
|
3771
3744
|
//#endregion
|
|
3772
3745
|
//#region src/rules/padding-around-before-each-blocks.ts
|
|
@@ -3785,7 +3758,7 @@ var padding_around_before_each_blocks_default = createPaddingRule(RULE_NAME$48,
|
|
|
3785
3758
|
//#endregion
|
|
3786
3759
|
//#region src/rules/padding-around-describe-blocks.ts
|
|
3787
3760
|
const RULE_NAME$47 = "padding-around-describe-blocks";
|
|
3788
|
-
const config$
|
|
3761
|
+
const config$2 = [{
|
|
3789
3762
|
paddingType: PaddingType.Always,
|
|
3790
3763
|
prevStatementType: StatementType.Any,
|
|
3791
3764
|
nextStatementType: [
|
|
@@ -3802,12 +3775,12 @@ const config$4 = [{
|
|
|
3802
3775
|
],
|
|
3803
3776
|
nextStatementType: StatementType.Any
|
|
3804
3777
|
}];
|
|
3805
|
-
var padding_around_describe_blocks_default = createPaddingRule(RULE_NAME$47, "Enforce padding around `describe` blocks", config$
|
|
3778
|
+
var padding_around_describe_blocks_default = createPaddingRule(RULE_NAME$47, "Enforce padding around `describe` blocks", config$2);
|
|
3806
3779
|
|
|
3807
3780
|
//#endregion
|
|
3808
3781
|
//#region src/rules/padding-around-expect-groups.ts
|
|
3809
3782
|
const RULE_NAME$46 = "padding-around-expect-groups";
|
|
3810
|
-
const config$
|
|
3783
|
+
const config$1 = [
|
|
3811
3784
|
{
|
|
3812
3785
|
paddingType: PaddingType.Always,
|
|
3813
3786
|
prevStatementType: StatementType.Any,
|
|
@@ -3839,12 +3812,12 @@ const config$5 = [
|
|
|
3839
3812
|
nextStatementType: StatementType.ExpectTypeOfToken
|
|
3840
3813
|
}
|
|
3841
3814
|
];
|
|
3842
|
-
var padding_around_expect_groups_default = createPaddingRule(RULE_NAME$46, "Enforce padding around `expect` groups", config$
|
|
3815
|
+
var padding_around_expect_groups_default = createPaddingRule(RULE_NAME$46, "Enforce padding around `expect` groups", config$1);
|
|
3843
3816
|
|
|
3844
3817
|
//#endregion
|
|
3845
3818
|
//#region src/rules/padding-around-test-blocks.ts
|
|
3846
3819
|
const RULE_NAME$45 = "padding-around-test-blocks";
|
|
3847
|
-
const config
|
|
3820
|
+
const config = [{
|
|
3848
3821
|
paddingType: PaddingType.Always,
|
|
3849
3822
|
prevStatementType: StatementType.Any,
|
|
3850
3823
|
nextStatementType: [
|
|
@@ -3865,19 +3838,19 @@ const config$6 = [{
|
|
|
3865
3838
|
],
|
|
3866
3839
|
nextStatementType: StatementType.Any
|
|
3867
3840
|
}];
|
|
3868
|
-
var padding_around_test_blocks_default = createPaddingRule(RULE_NAME$45, "Enforce padding around `test` blocks", config
|
|
3841
|
+
var padding_around_test_blocks_default = createPaddingRule(RULE_NAME$45, "Enforce padding around `test` blocks", config);
|
|
3869
3842
|
|
|
3870
3843
|
//#endregion
|
|
3871
3844
|
//#region src/rules/padding-around-all.ts
|
|
3872
3845
|
const RULE_NAME$44 = "padding-around-all";
|
|
3873
3846
|
var padding_around_all_default = createPaddingRule(RULE_NAME$44, "Enforce padding around vitest functions", [
|
|
3874
|
-
...config,
|
|
3875
|
-
...config$1,
|
|
3876
|
-
...config$2,
|
|
3877
|
-
...config$3,
|
|
3878
|
-
...config$4,
|
|
3847
|
+
...config$6,
|
|
3879
3848
|
...config$5,
|
|
3880
|
-
...config$
|
|
3849
|
+
...config$4,
|
|
3850
|
+
...config$3,
|
|
3851
|
+
...config$2,
|
|
3852
|
+
...config$1,
|
|
3853
|
+
...config
|
|
3881
3854
|
]);
|
|
3882
3855
|
|
|
3883
3856
|
//#endregion
|
|
@@ -3891,7 +3864,7 @@ const MOCK_CALL_RESET_METHODS = [
|
|
|
3891
3864
|
];
|
|
3892
3865
|
const hasMatchersToCombine = (target) => MATCHERS_TO_COMBINE.some((matcher) => matcher === target);
|
|
3893
3866
|
const getExpectText = (callee, source) => {
|
|
3894
|
-
if (callee.type !==
|
|
3867
|
+
if (callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
|
|
3895
3868
|
return source.getText(callee.object);
|
|
3896
3869
|
};
|
|
3897
3870
|
const getArgumentsText = (callExpression, source) => callExpression.arguments.map((arg) => source.getText(arg)).join(", ");
|
|
@@ -3905,11 +3878,11 @@ const getMatcherName = (vitestFnCall) => {
|
|
|
3905
3878
|
return validExpectCall ? getAccessorValue(validExpectCall.matcher) : null;
|
|
3906
3879
|
};
|
|
3907
3880
|
const getExpectArgText = ({ callee }) => {
|
|
3908
|
-
if (callee.type !==
|
|
3881
|
+
if (callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
|
|
3909
3882
|
const { object } = callee;
|
|
3910
|
-
if (object.type !==
|
|
3883
|
+
if (object.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return null;
|
|
3911
3884
|
const [firstArgument] = object.arguments;
|
|
3912
|
-
if (firstArgument.type !==
|
|
3885
|
+
if (firstArgument.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return null;
|
|
3913
3886
|
return firstArgument.name;
|
|
3914
3887
|
};
|
|
3915
3888
|
const getSharedExpectArgText = (firstCallExpression, secondCallExpression) => {
|
|
@@ -3919,16 +3892,16 @@ const getSharedExpectArgText = (firstCallExpression, secondCallExpression) => {
|
|
|
3919
3892
|
return firstArgText;
|
|
3920
3893
|
};
|
|
3921
3894
|
const isTargetMockResetCall = (statement, expectArgText, minLine, maxLine) => {
|
|
3922
|
-
if (statement.type !==
|
|
3923
|
-
if (statement.expression.type !==
|
|
3895
|
+
if (statement.type !== _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
3896
|
+
if (statement.expression.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return false;
|
|
3924
3897
|
const statementLine = statement.loc.start.line;
|
|
3925
3898
|
if (statementLine <= minLine || statementLine >= maxLine) return false;
|
|
3926
3899
|
const { callee } = statement.expression;
|
|
3927
|
-
if (callee.type !==
|
|
3900
|
+
if (callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return false;
|
|
3928
3901
|
const { object, property } = callee;
|
|
3929
|
-
if (object.type !==
|
|
3902
|
+
if (object.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return false;
|
|
3930
3903
|
if (object.name !== expectArgText) return false;
|
|
3931
|
-
if (property.type !==
|
|
3904
|
+
if (property.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return false;
|
|
3932
3905
|
return MOCK_CALL_RESET_METHODS.some((method) => method === property.name);
|
|
3933
3906
|
};
|
|
3934
3907
|
const hasMockResetBetween = (body, firstCallExpression, secondCallExpression) => {
|
|
@@ -3939,7 +3912,7 @@ const hasMockResetBetween = (body, firstCallExpression, secondCallExpression) =>
|
|
|
3939
3912
|
if (!expectArgText) return false;
|
|
3940
3913
|
return body.some((statement) => isTargetMockResetCall(statement, expectArgText, minLine, maxLine));
|
|
3941
3914
|
};
|
|
3942
|
-
const getMemberProperty = (expression) => expression.callee.type ===
|
|
3915
|
+
const getMemberProperty = (expression) => expression.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression ? expression.callee.property : null;
|
|
3943
3916
|
var prefer_called_exactly_once_with_default = createEslintRule({
|
|
3944
3917
|
name: RULE_NAME$43,
|
|
3945
3918
|
meta: {
|
|
@@ -3951,7 +3924,7 @@ var prefer_called_exactly_once_with_default = createEslintRule({
|
|
|
3951
3924
|
},
|
|
3952
3925
|
create(context) {
|
|
3953
3926
|
const { sourceCode } = context;
|
|
3954
|
-
const getCallExpressions = (body) => body.filter((node) => node.type ===
|
|
3927
|
+
const getCallExpressions = (body) => body.filter((node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement).flatMap((node) => node.expression.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression ? node.expression : []);
|
|
3955
3928
|
const checkBlockBody = (body) => {
|
|
3956
3929
|
const callExpressions = getCallExpressions(body);
|
|
3957
3930
|
const expectMatcherMap = /* @__PURE__ */ new Map();
|
|
@@ -4009,7 +3982,7 @@ var prefer_called_exactly_once_with_default = createEslintRule({
|
|
|
4009
3982
|
//#endregion
|
|
4010
3983
|
//#region src/rules/prefer-called-once.ts
|
|
4011
3984
|
const RULE_NAME$42 = "prefer-called-once";
|
|
4012
|
-
const isOneLiteral = (node) => node.type ===
|
|
3985
|
+
const isOneLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === 1;
|
|
4013
3986
|
var prefer_called_once_default = createEslintRule({
|
|
4014
3987
|
name: RULE_NAME$42,
|
|
4015
3988
|
meta: {
|
|
@@ -4094,7 +4067,7 @@ var prefer_called_with_default = createEslintRule({
|
|
|
4094
4067
|
return { CallExpression(node) {
|
|
4095
4068
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4096
4069
|
if (vitestFnCall?.type !== "expect") return;
|
|
4097
|
-
if (vitestFnCall.modifiers.some((node
|
|
4070
|
+
if (vitestFnCall.modifiers.some((node) => getAccessorValue(node) === "not")) return;
|
|
4098
4071
|
const { matcher } = vitestFnCall;
|
|
4099
4072
|
const matcherName = getAccessorValue(matcher);
|
|
4100
4073
|
if (["toBeCalled", "toHaveBeenCalled"].includes(matcherName)) context.report({
|
|
@@ -4109,7 +4082,7 @@ var prefer_called_with_default = createEslintRule({
|
|
|
4109
4082
|
|
|
4110
4083
|
//#endregion
|
|
4111
4084
|
//#region src/utils/msc.ts
|
|
4112
|
-
const isBooleanLiteral = (node) => node.type ===
|
|
4085
|
+
const isBooleanLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof node.value === "boolean";
|
|
4113
4086
|
/**
|
|
4114
4087
|
* Checks if the given `ParsedExpectMatcher` is either a call to one of the equality matchers,
|
|
4115
4088
|
* with a boolean` literal as the sole argument, *or* is a call to `toBeTruthy` or `toBeFalsy`.
|
|
@@ -4121,14 +4094,14 @@ const isBooleanEqualityMatcher = (expectFnCall) => {
|
|
|
4121
4094
|
const arg = getFirstMatcherArg(expectFnCall);
|
|
4122
4095
|
return Object.prototype.hasOwnProperty.call(EqualityMatcher, matcherName) && isBooleanLiteral(arg);
|
|
4123
4096
|
};
|
|
4124
|
-
const isInstanceOfBinaryExpression = (node, className) => node.type ===
|
|
4097
|
+
const isInstanceOfBinaryExpression = (node, className) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.BinaryExpression && node.operator === "instanceof" && isSupportedAccessor(node.right, className);
|
|
4125
4098
|
const hasOnlyOneArgument = (call) => call.arguments.length === 1;
|
|
4126
4099
|
|
|
4127
4100
|
//#endregion
|
|
4128
4101
|
//#region src/rules/prefer-comparison-matcher.ts
|
|
4129
4102
|
const RULE_NAME$39 = "prefer-comparison-matcher";
|
|
4130
4103
|
const isString = (node) => {
|
|
4131
|
-
return isStringNode(node) || node?.type ===
|
|
4104
|
+
return isStringNode(node) || node?.type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral;
|
|
4132
4105
|
};
|
|
4133
4106
|
const isComparingToString = (expression) => {
|
|
4134
4107
|
return isString(expression.left) || isString(expression.right);
|
|
@@ -4168,11 +4141,11 @@ var prefer_comparison_matcher_default = createEslintRule({
|
|
|
4168
4141
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4169
4142
|
if (vitestFnCall?.type !== "expect" || vitestFnCall.args.length === 0) return;
|
|
4170
4143
|
const { parent: expect } = vitestFnCall.head.node;
|
|
4171
|
-
if (expect?.type !==
|
|
4144
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4172
4145
|
const { arguments: [comparison], range: [, expectCallEnd] } = expect;
|
|
4173
4146
|
const { matcher } = vitestFnCall;
|
|
4174
4147
|
const matcherArg = getFirstMatcherArg(vitestFnCall);
|
|
4175
|
-
if (comparison?.type !==
|
|
4148
|
+
if (comparison?.type !== _typescript_eslint_utils.AST_NODE_TYPES.BinaryExpression || isComparingToString(comparison) || !Object.prototype.hasOwnProperty.call(EqualityMatcher, getAccessorValue(matcher)) || !isBooleanLiteral(matcherArg)) return;
|
|
4176
4149
|
const [modifier] = vitestFnCall.modifiers;
|
|
4177
4150
|
const hasNot = vitestFnCall.modifiers.some((nod) => getAccessorValue(nod) === "not");
|
|
4178
4151
|
const preferredMatcher = determineMatcher(comparison.operator, matcherArg.value === hasNot);
|
|
@@ -4215,9 +4188,9 @@ var prefer_describe_function_title_default = createEslintRule({
|
|
|
4215
4188
|
if (node.arguments.length < 2) return;
|
|
4216
4189
|
const scope = getModuleScope(context, node);
|
|
4217
4190
|
const [argument] = node.arguments;
|
|
4218
|
-
if (argument.type ===
|
|
4191
|
+
if (argument.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && argument.object.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && argument.property.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) {
|
|
4219
4192
|
const identifierName = argument.object.name;
|
|
4220
|
-
if ((scope?.set.get(identifierName)?.defs[0])?.type !==
|
|
4193
|
+
if ((scope?.set.get(identifierName)?.defs[0])?.type !== _typescript_eslint_scope_manager.DefinitionType.ImportBinding || argument.property.name !== "name") return;
|
|
4221
4194
|
context.report({
|
|
4222
4195
|
node: argument,
|
|
4223
4196
|
messageId: "preferFunction",
|
|
@@ -4227,13 +4200,13 @@ var prefer_describe_function_title_default = createEslintRule({
|
|
|
4227
4200
|
});
|
|
4228
4201
|
return;
|
|
4229
4202
|
}
|
|
4230
|
-
if (argument.type !==
|
|
4203
|
+
if (argument.type !== _typescript_eslint_utils.AST_NODE_TYPES.Literal || typeof argument.value !== "string") return;
|
|
4231
4204
|
const describedTitle = argument.value;
|
|
4232
4205
|
if (parseVitestFnCall(node, context)?.type !== "describe") return;
|
|
4233
4206
|
const scopedFunction = scope?.set.get(describedTitle)?.defs[0];
|
|
4234
|
-
if (scopedFunction?.type !==
|
|
4207
|
+
if (scopedFunction?.type !== _typescript_eslint_scope_manager.DefinitionType.ImportBinding) return;
|
|
4235
4208
|
if (parsePluginSettings(context.settings).typecheck) {
|
|
4236
|
-
if (!isClassOrFunctionType(
|
|
4209
|
+
if (!isClassOrFunctionType(_typescript_eslint_utils.ESLintUtils.getParserServices(context).getTypeAtLocation(scopedFunction.node))) return;
|
|
4237
4210
|
}
|
|
4238
4211
|
context.report({
|
|
4239
4212
|
node: argument,
|
|
@@ -4323,16 +4296,16 @@ var prefer_equality_matcher_default = createEslintRule({
|
|
|
4323
4296
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4324
4297
|
if (vitestFnCall?.type !== "expect" || vitestFnCall.args.length === 0) return;
|
|
4325
4298
|
const { parent: expect } = vitestFnCall.head.node;
|
|
4326
|
-
if (expect?.type !==
|
|
4299
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4327
4300
|
const { arguments: [comparison], range: [, expectCallEnd] } = expect;
|
|
4328
4301
|
const { matcher } = vitestFnCall;
|
|
4329
4302
|
const matcherArg = getFirstMatcherArg(vitestFnCall);
|
|
4330
|
-
if (comparison?.type !==
|
|
4303
|
+
if (comparison?.type !== _typescript_eslint_utils.AST_NODE_TYPES.BinaryExpression || comparison.operator !== "===" && comparison.operator !== "!==" || !Object.prototype.hasOwnProperty.call(EqualityMatcher, getAccessorValue(matcher)) || !isBooleanLiteral(matcherArg)) return;
|
|
4331
4304
|
const matcherValue = matcherArg.value;
|
|
4332
4305
|
const [modifier] = vitestFnCall.modifiers;
|
|
4333
4306
|
const hasNot = vitestFnCall.modifiers.some((nod) => getAccessorValue(nod) === "not");
|
|
4334
4307
|
const addNotModifier = (comparison.operator === "!==" ? !matcherValue : matcherValue) === hasNot;
|
|
4335
|
-
const buildFixer
|
|
4308
|
+
const buildFixer = (equalityMatcher) => (fixer) => {
|
|
4336
4309
|
const { sourceCode } = context;
|
|
4337
4310
|
let modifierText = modifier && getAccessorValue(modifier) !== "not" ? `.${getAccessorValue(modifier)}` : "";
|
|
4338
4311
|
if (addNotModifier) modifierText += `.${ModifierName.not}`;
|
|
@@ -4351,7 +4324,7 @@ var prefer_equality_matcher_default = createEslintRule({
|
|
|
4351
4324
|
].map((equalityMatcher) => ({
|
|
4352
4325
|
messageId: "suggestEqualityMatcher",
|
|
4353
4326
|
data: { equalityMatcher },
|
|
4354
|
-
fix: buildFixer
|
|
4327
|
+
fix: buildFixer(equalityMatcher)
|
|
4355
4328
|
})),
|
|
4356
4329
|
node: matcher
|
|
4357
4330
|
});
|
|
@@ -4365,8 +4338,8 @@ const RULE_NAME$35 = "prefer-expect-assertions";
|
|
|
4365
4338
|
const isFirstStatement = (node) => {
|
|
4366
4339
|
let parent = node;
|
|
4367
4340
|
while (parent) {
|
|
4368
|
-
if (parent.parent?.type ===
|
|
4369
|
-
if (parent.parent?.type ===
|
|
4341
|
+
if (parent.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) return parent.parent.body[0] === parent;
|
|
4342
|
+
if (parent.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression) return true;
|
|
4370
4343
|
parent = parent.parent;
|
|
4371
4344
|
}
|
|
4372
4345
|
throw new Error("Could not find parent block statement");
|
|
@@ -4453,7 +4426,7 @@ var prefer_expect_assertions_default = createEslintRule({
|
|
|
4453
4426
|
return;
|
|
4454
4427
|
}
|
|
4455
4428
|
const [arg] = expectFnCall.args;
|
|
4456
|
-
if (arg.type ===
|
|
4429
|
+
if (arg.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof arg.value === "number" && Number.isInteger(arg.value)) return;
|
|
4457
4430
|
context.report({
|
|
4458
4431
|
messageId: "assertionsRequiresNumberArgument",
|
|
4459
4432
|
node: arg
|
|
@@ -4480,9 +4453,9 @@ var prefer_expect_assertions_default = createEslintRule({
|
|
|
4480
4453
|
inTestCaseCall = true;
|
|
4481
4454
|
return;
|
|
4482
4455
|
}
|
|
4483
|
-
if (vitestFnCall?.head.type === "testContext" && vitestFnCall.members[0] && vitestFnCall.members[0].type ===
|
|
4456
|
+
if (vitestFnCall?.head.type === "testContext" && vitestFnCall.members[0] && vitestFnCall.members[0].type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && vitestFnCall.members[0].name === "expect") testContextName = `${vitestFnCall.head.local}`;
|
|
4484
4457
|
if (vitestFnCall?.type === "expect" && inTestCaseCall) {
|
|
4485
|
-
if (expressionDepth === 1 && isFirstStatement(node) && vitestFnCall.head.node.parent?.type ===
|
|
4458
|
+
if (expressionDepth === 1 && isFirstStatement(node) && vitestFnCall.head.node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && vitestFnCall.members.length === 1 && ["assertions", "hasAssertions"].includes(getAccessorValue(vitestFnCall.members[0]))) {
|
|
4486
4459
|
checkExpectHasAssertions(vitestFnCall, node);
|
|
4487
4460
|
hasExpectAssertAsFirstStatement = true;
|
|
4488
4461
|
}
|
|
@@ -4503,7 +4476,7 @@ var prefer_expect_assertions_default = createEslintRule({
|
|
|
4503
4476
|
return;
|
|
4504
4477
|
}
|
|
4505
4478
|
const suggestions = [];
|
|
4506
|
-
if (secondArg.body.type ===
|
|
4479
|
+
if (secondArg.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) {
|
|
4507
4480
|
const prefix = testContextName ? `${testContextName}.` : "";
|
|
4508
4481
|
suggestions.push(["suggestAddingHasAssertions", `${prefix}expect.hasAssertions();`], ["suggestAddingAssertions", `${prefix}expect.assertions();`]);
|
|
4509
4482
|
}
|
|
@@ -4539,9 +4512,9 @@ var prefer_expect_resolves_default = createEslintRule({
|
|
|
4539
4512
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4540
4513
|
if (vitestFnCall?.type !== "expect") return;
|
|
4541
4514
|
const { parent } = vitestFnCall.head.node;
|
|
4542
|
-
if (parent?.type !==
|
|
4515
|
+
if (parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4543
4516
|
const [awaitNode] = parent.arguments;
|
|
4544
|
-
if (awaitNode?.type ===
|
|
4517
|
+
if (awaitNode?.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression) context.report({
|
|
4545
4518
|
node: awaitNode,
|
|
4546
4519
|
messageId: "expectResolves",
|
|
4547
4520
|
fix(fixer) {
|
|
@@ -4584,14 +4557,14 @@ var prefer_expect_type_of_default = createEslintRule({
|
|
|
4584
4557
|
return { CallExpression(node) {
|
|
4585
4558
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4586
4559
|
if (vitestFnCall?.type !== "expect") return;
|
|
4587
|
-
if (vitestFnCall.head.node.parent?.type !==
|
|
4560
|
+
if (vitestFnCall.head.node.parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4588
4561
|
const [firstArg] = vitestFnCall.head.node.parent.arguments;
|
|
4589
|
-
if (!firstArg || firstArg.type !==
|
|
4562
|
+
if (!firstArg || firstArg.type !== _typescript_eslint_utils.AST_NODE_TYPES.UnaryExpression) return;
|
|
4590
4563
|
if (firstArg.operator !== "typeof") return;
|
|
4591
4564
|
const matcherName = getAccessorValue(vitestFnCall.matcher);
|
|
4592
4565
|
if (matcherName !== "toBe" && matcherName !== "toEqual") return;
|
|
4593
4566
|
const [matcherArg] = vitestFnCall.args;
|
|
4594
|
-
if (!matcherArg || matcherArg.type !==
|
|
4567
|
+
if (!matcherArg || matcherArg.type !== _typescript_eslint_utils.AST_NODE_TYPES.Literal) return;
|
|
4595
4568
|
if (typeof matcherArg.value !== "string") return;
|
|
4596
4569
|
const typeString = matcherArg.value;
|
|
4597
4570
|
const expectTypeOfMatcher = typeMatchers[typeString];
|
|
@@ -4729,12 +4702,12 @@ var prefer_import_in_mock_default = createEslintRule({
|
|
|
4729
4702
|
create(context, options) {
|
|
4730
4703
|
const fixable = options[0].fixable;
|
|
4731
4704
|
return { CallExpression(node) {
|
|
4732
|
-
if (node.callee.type !==
|
|
4705
|
+
if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return;
|
|
4733
4706
|
if (parseVitestFnCall(node, context)?.type !== "vi") return false;
|
|
4734
4707
|
const { property } = node.callee;
|
|
4735
|
-
if (property.type !=
|
|
4708
|
+
if (property.type != _typescript_eslint_utils.AST_NODE_TYPES.Identifier || property.name != "mock") return;
|
|
4736
4709
|
const pathArg = node.arguments[0];
|
|
4737
|
-
if (pathArg && pathArg.type ===
|
|
4710
|
+
if (pathArg && pathArg.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal) context.report({
|
|
4738
4711
|
messageId: "preferImport",
|
|
4739
4712
|
data: { path: pathArg.value },
|
|
4740
4713
|
node,
|
|
@@ -4898,9 +4871,9 @@ var prefer_lowercase_title_default = createEslintRule({
|
|
|
4898
4871
|
node: node.arguments[0],
|
|
4899
4872
|
data: { method: vitestFnCall.name },
|
|
4900
4873
|
fix: (fixer) => {
|
|
4901
|
-
const description
|
|
4874
|
+
const description = getStringValue(firstArgument);
|
|
4902
4875
|
const rangeIgnoreQuotes = [firstArgument.range[0] + 1, firstArgument.range[1] - 1];
|
|
4903
|
-
const newDescription = lowercaseFirstCharacterOnly ? description
|
|
4876
|
+
const newDescription = lowercaseFirstCharacterOnly ? description.substring(0, 1).toLowerCase() + description.substring(1) : description.toLowerCase();
|
|
4904
4877
|
return [fixer.replaceTextRange(rangeIgnoreQuotes, newDescription)];
|
|
4905
4878
|
}
|
|
4906
4879
|
});
|
|
@@ -4919,8 +4892,8 @@ const withOnce$1 = (name, addOnce) => {
|
|
|
4919
4892
|
return `${name}${addOnce ? "Once" : ""}`;
|
|
4920
4893
|
};
|
|
4921
4894
|
const findSingleReturnArgumentNode$1 = (fnNode) => {
|
|
4922
|
-
if (fnNode.body.type !==
|
|
4923
|
-
if (fnNode.body.body[0]?.type ===
|
|
4895
|
+
if (fnNode.body.type !== _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) return fnNode.body;
|
|
4896
|
+
if (fnNode.body.body[0]?.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement) return fnNode.body.body[0].argument;
|
|
4924
4897
|
return null;
|
|
4925
4898
|
};
|
|
4926
4899
|
var prefer_mock_promise_shorthand_default = createEslintRule({
|
|
@@ -4937,7 +4910,7 @@ var prefer_mock_promise_shorthand_default = createEslintRule({
|
|
|
4937
4910
|
},
|
|
4938
4911
|
create(context) {
|
|
4939
4912
|
const report = (property, isOnce, outerArgNode, innerArgNode = outerArgNode) => {
|
|
4940
|
-
if (innerArgNode?.type !==
|
|
4913
|
+
if (innerArgNode?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4941
4914
|
const argName = getNodeName(innerArgNode);
|
|
4942
4915
|
if (argName !== "Promise.resolve" && argName !== "Promise.reject") return;
|
|
4943
4916
|
const replacement = withOnce$1(argName.endsWith("reject") ? "mockRejectedValue" : "mockResolvedValue", isOnce);
|
|
@@ -4953,7 +4926,7 @@ var prefer_mock_promise_shorthand_default = createEslintRule({
|
|
|
4953
4926
|
});
|
|
4954
4927
|
};
|
|
4955
4928
|
return { CallExpression(node) {
|
|
4956
|
-
if (node.callee.type !==
|
|
4929
|
+
if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || !isSupportedAccessor(node.callee.property) || node.arguments.length === 0) return;
|
|
4957
4930
|
const mockFnName = getAccessorValue(node.callee.property);
|
|
4958
4931
|
const isOnce = mockFnName.endsWith("Once");
|
|
4959
4932
|
if (mockFnName === withOnce$1("mockReturnValue", isOnce)) report(node.callee.property, isOnce, node.arguments[0]);
|
|
@@ -4973,8 +4946,8 @@ const withOnce = (name, addOnce) => {
|
|
|
4973
4946
|
return `${name}${addOnce ? "Once" : ""}`;
|
|
4974
4947
|
};
|
|
4975
4948
|
const findSingleReturnArgumentNode = (fnNode) => {
|
|
4976
|
-
if (fnNode.body.type !==
|
|
4977
|
-
if (fnNode.body.body[0]?.type ===
|
|
4949
|
+
if (fnNode.body.type !== _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) return fnNode.body;
|
|
4950
|
+
if (fnNode.body.body[0]?.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement) return fnNode.body.body[0].argument;
|
|
4978
4951
|
return null;
|
|
4979
4952
|
};
|
|
4980
4953
|
var prefer_mock_return_shorthand_default = createEslintRule({
|
|
@@ -4991,7 +4964,7 @@ var prefer_mock_return_shorthand_default = createEslintRule({
|
|
|
4991
4964
|
},
|
|
4992
4965
|
create(context) {
|
|
4993
4966
|
return { CallExpression(node) {
|
|
4994
|
-
if (node.callee.type !==
|
|
4967
|
+
if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || !isSupportedAccessor(node.callee.property) || node.arguments.length === 0) return;
|
|
4995
4968
|
const { property } = node.callee;
|
|
4996
4969
|
const mockFnName = getAccessorValue(property);
|
|
4997
4970
|
const isOnce = mockFnName.endsWith("Once");
|
|
@@ -5000,8 +4973,8 @@ var prefer_mock_return_shorthand_default = createEslintRule({
|
|
|
5000
4973
|
if (!isFunction(arg) || arg.params.length !== 0 || arg.async) return;
|
|
5001
4974
|
const replacement = withOnce("mockReturnValue", isOnce);
|
|
5002
4975
|
const returnNode = findSingleReturnArgumentNode(arg);
|
|
5003
|
-
if (!returnNode || returnNode.type ===
|
|
5004
|
-
if (returnNode.type ===
|
|
4976
|
+
if (!returnNode || returnNode.type === _typescript_eslint_utils.AST_NODE_TYPES.UpdateExpression) return;
|
|
4977
|
+
if (returnNode.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) {
|
|
5005
4978
|
if (context.sourceCode.getScope(returnNode).through.some((v) => v.resolved?.defs.some((n) => n.type === "Variable" && n.parent.kind !== "const"))) return;
|
|
5006
4979
|
}
|
|
5007
4980
|
context.report({
|
|
@@ -5100,18 +5073,18 @@ var prefer_snapshot_hint_default = createEslintRule({
|
|
|
5100
5073
|
const RULE_NAME$24 = "prefer-spy-on";
|
|
5101
5074
|
const findNodeObject = (node) => {
|
|
5102
5075
|
if ("object" in node) return node.object;
|
|
5103
|
-
if (node.callee.type ===
|
|
5076
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return node.callee.object;
|
|
5104
5077
|
return null;
|
|
5105
5078
|
};
|
|
5106
5079
|
const getVitestFnCall = (node) => {
|
|
5107
|
-
if (node.type !==
|
|
5080
|
+
if (node.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && node.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
|
|
5108
5081
|
const obj = findNodeObject(node);
|
|
5109
5082
|
if (!obj) return null;
|
|
5110
|
-
if (obj.type ===
|
|
5083
|
+
if (obj.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && getNodeName(node.callee) === "vi.fn" ? node : null;
|
|
5111
5084
|
return getVitestFnCall(obj);
|
|
5112
5085
|
};
|
|
5113
5086
|
const getAutoFixMockImplementation = (vitestFnCall, context) => {
|
|
5114
|
-
if (vitestFnCall.parent?.type ===
|
|
5087
|
+
if (vitestFnCall.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && vitestFnCall.parent.property.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && vitestFnCall.parent.property.name === "mockImplementation") return "";
|
|
5115
5088
|
const [arg] = vitestFnCall.arguments;
|
|
5116
5089
|
const argSource = arg && context.sourceCode.getText(arg);
|
|
5117
5090
|
return argSource ? `.mockImplementation(${argSource})` : ".mockImplementation()";
|
|
@@ -5131,14 +5104,14 @@ var prefer_spy_on_default = createEslintRule({
|
|
|
5131
5104
|
create(context) {
|
|
5132
5105
|
return { AssignmentExpression(node) {
|
|
5133
5106
|
const { left, right } = node;
|
|
5134
|
-
if (left.type !==
|
|
5107
|
+
if (left.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return;
|
|
5135
5108
|
const vitestFnCall = getVitestFnCall(right);
|
|
5136
5109
|
if (!vitestFnCall) return;
|
|
5137
5110
|
context.report({
|
|
5138
5111
|
node,
|
|
5139
5112
|
messageId: "useViSpayOn",
|
|
5140
5113
|
fix(fixer) {
|
|
5141
|
-
const lefPropQuote = left.property.type ===
|
|
5114
|
+
const lefPropQuote = left.property.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && !left.computed ? "'" : "";
|
|
5142
5115
|
const mockImplementation = getAutoFixMockImplementation(vitestFnCall, context);
|
|
5143
5116
|
return [
|
|
5144
5117
|
fixer.insertTextBefore(left, "vi.spyOn("),
|
|
@@ -5226,7 +5199,7 @@ var prefer_strict_equal_default = createEslintRule({
|
|
|
5226
5199
|
//#endregion
|
|
5227
5200
|
//#region src/rules/prefer-to-be-falsy.ts
|
|
5228
5201
|
const RULE_NAME$21 = "prefer-to-be-falsy";
|
|
5229
|
-
const isFalseLiteral = (node) => node.type ===
|
|
5202
|
+
const isFalseLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === false;
|
|
5230
5203
|
var prefer_to_be_falsy_default = createEslintRule({
|
|
5231
5204
|
name: RULE_NAME$21,
|
|
5232
5205
|
meta: {
|
|
@@ -5280,7 +5253,7 @@ var prefer_to_be_object_default = createEslintRule({
|
|
|
5280
5253
|
return;
|
|
5281
5254
|
}
|
|
5282
5255
|
const { parent: expectTypeOf } = vitestFnCall.head.node;
|
|
5283
|
-
if (expectTypeOf?.type !==
|
|
5256
|
+
if (expectTypeOf?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
5284
5257
|
const [expectTypeOfArgs] = expectTypeOf.arguments;
|
|
5285
5258
|
if (!expectTypeOfArgs || !isBooleanEqualityMatcher(vitestFnCall) || !isInstanceOfBinaryExpression(expectTypeOfArgs, "Object")) return;
|
|
5286
5259
|
context.report({
|
|
@@ -5292,10 +5265,10 @@ var prefer_to_be_object_default = createEslintRule({
|
|
|
5292
5265
|
if (vitestFnCall.args.length) {
|
|
5293
5266
|
const [matcherArg] = vitestFnCall.args;
|
|
5294
5267
|
fixes.push(fixer.remove(matcherArg));
|
|
5295
|
-
invertCondition = matcherArg.type ===
|
|
5268
|
+
invertCondition = matcherArg.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && followTypeAssertionChain$1(matcherArg).value === false;
|
|
5296
5269
|
}
|
|
5297
5270
|
if (invertCondition) {
|
|
5298
|
-
const notModifier = vitestFnCall.modifiers.find((node
|
|
5271
|
+
const notModifier = vitestFnCall.modifiers.find((node) => getAccessorValue(node) === "not");
|
|
5299
5272
|
fixes.push(notModifier ? fixer.removeRange([notModifier.range[0] - 1, notModifier.range[1]]) : fixer.insertTextBefore(vitestFnCall.matcher, "not."));
|
|
5300
5273
|
}
|
|
5301
5274
|
return fixes;
|
|
@@ -5308,7 +5281,7 @@ var prefer_to_be_object_default = createEslintRule({
|
|
|
5308
5281
|
//#endregion
|
|
5309
5282
|
//#region src/rules/prefer-to-be-truthy.ts
|
|
5310
5283
|
const RULE_NAME$19 = "prefer-to-be-truthy";
|
|
5311
|
-
const isTrueLiteral = (node) => node.type ===
|
|
5284
|
+
const isTrueLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === true;
|
|
5312
5285
|
var prefer_to_be_truthy_default = createEslintRule({
|
|
5313
5286
|
name: RULE_NAME$19,
|
|
5314
5287
|
meta: {
|
|
@@ -5337,16 +5310,16 @@ var prefer_to_be_truthy_default = createEslintRule({
|
|
|
5337
5310
|
//#endregion
|
|
5338
5311
|
//#region src/rules/prefer-to-be.ts
|
|
5339
5312
|
const RULE_NAME$18 = "prefer-to-be";
|
|
5340
|
-
const isNullLiteral = (node) => node.type ===
|
|
5313
|
+
const isNullLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === null;
|
|
5341
5314
|
const isNullEqualityMatcher = (expectFnCall) => isNullLiteral(getFirstMatcherArg(expectFnCall));
|
|
5342
5315
|
const isFirstArgumentIdentifier = (expectFnCall, name) => isIdentifier(getFirstMatcherArg(expectFnCall), name);
|
|
5343
5316
|
const isFloat = (v) => Math.floor(v) !== Math.ceil(v);
|
|
5344
5317
|
const shouldUseToBe = (expectFnCall) => {
|
|
5345
5318
|
let firstArg = getFirstMatcherArg(expectFnCall);
|
|
5346
|
-
if (firstArg.type ===
|
|
5347
|
-
if (firstArg.type ===
|
|
5348
|
-
if (firstArg.type ===
|
|
5349
|
-
return firstArg.type ===
|
|
5319
|
+
if (firstArg.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof firstArg.value === "number" && isFloat(firstArg.value)) return false;
|
|
5320
|
+
if (firstArg.type === _typescript_eslint_utils.AST_NODE_TYPES.UnaryExpression && firstArg.operator === "-") firstArg = firstArg.argument;
|
|
5321
|
+
if (firstArg.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal) return !("regex" in firstArg);
|
|
5322
|
+
return firstArg.type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral;
|
|
5350
5323
|
};
|
|
5351
5324
|
const reportPreferToBe = (context, whatToBe, expectFnCall, func, modifierNode) => {
|
|
5352
5325
|
context.report({
|
|
@@ -5383,7 +5356,7 @@ var prefer_to_be_default = createEslintRule({
|
|
|
5383
5356
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
5384
5357
|
if (vitestFnCall?.type !== "expect") return;
|
|
5385
5358
|
const matcherName = getAccessorValue(vitestFnCall.matcher);
|
|
5386
|
-
const notModifier = vitestFnCall.modifiers.find((node
|
|
5359
|
+
const notModifier = vitestFnCall.modifiers.find((node) => getAccessorValue(node) === "not");
|
|
5387
5360
|
if (notModifier && ["toBeUndefined", "toBeDefined"].includes(matcherName)) {
|
|
5388
5361
|
reportPreferToBe(context, matcherName === "toBeDefined" ? "Undefined" : "Defined", vitestFnCall, node, notModifier);
|
|
5389
5362
|
return;
|
|
@@ -5409,7 +5382,7 @@ var prefer_to_be_default = createEslintRule({
|
|
|
5409
5382
|
//#endregion
|
|
5410
5383
|
//#region src/rules/prefer-to-contain.ts
|
|
5411
5384
|
const RULE_NAME$17 = "prefer-to-contain";
|
|
5412
|
-
const isFixableIncludesCallExpression = (node) => node.type ===
|
|
5385
|
+
const isFixableIncludesCallExpression = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, "includes") && hasOnlyOneArgument(node) && node.arguments[0].type !== _typescript_eslint_utils.AST_NODE_TYPES.SpreadElement;
|
|
5413
5386
|
var prefer_to_contain_default = createEslintRule({
|
|
5414
5387
|
name: RULE_NAME$17,
|
|
5415
5388
|
meta: {
|
|
@@ -5427,11 +5400,11 @@ var prefer_to_contain_default = createEslintRule({
|
|
|
5427
5400
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
5428
5401
|
if (vitestFnCall?.type !== "expect" || vitestFnCall.args.length === 0) return;
|
|
5429
5402
|
const { parent: expect } = vitestFnCall.head.node;
|
|
5430
|
-
if (expect?.type !==
|
|
5403
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
5431
5404
|
const { arguments: [includesCall], range: [, expectCallEnd] } = expect;
|
|
5432
5405
|
const { matcher } = vitestFnCall;
|
|
5433
5406
|
const matcherArg = getFirstMatcherArg(vitestFnCall);
|
|
5434
|
-
if (!includesCall || matcherArg.type ===
|
|
5407
|
+
if (!includesCall || matcherArg.type === _typescript_eslint_utils.AST_NODE_TYPES.SpreadElement || !Object.prototype.hasOwnProperty.call(EqualityMatcher, getAccessorValue(matcher)) || !isBooleanLiteral(matcherArg) || !isFixableIncludesCallExpression(includesCall)) return;
|
|
5435
5408
|
const hasNot = vitestFnCall.modifiers.some((nod) => getAccessorValue(nod) === "not");
|
|
5436
5409
|
context.report({
|
|
5437
5410
|
fix(fixer) {
|
|
@@ -5470,10 +5443,10 @@ var prefer_to_have_length_default = createEslintRule({
|
|
|
5470
5443
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
5471
5444
|
if (vitestFnCall?.type !== "expect") return;
|
|
5472
5445
|
const { parent: expect } = vitestFnCall.head.node;
|
|
5473
|
-
if (expect?.type !==
|
|
5446
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
5474
5447
|
const [argument] = expect.arguments;
|
|
5475
5448
|
const { matcher } = vitestFnCall;
|
|
5476
|
-
if (!Object.prototype.hasOwnProperty.call(EqualityMatcher, getAccessorValue(matcher)) || argument?.type !==
|
|
5449
|
+
if (!Object.prototype.hasOwnProperty.call(EqualityMatcher, getAccessorValue(matcher)) || argument?.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || !isSupportedAccessor(argument.property, "length")) return;
|
|
5477
5450
|
context.report({
|
|
5478
5451
|
node: matcher,
|
|
5479
5452
|
messageId: "preferToHaveLength",
|
|
@@ -5495,7 +5468,7 @@ const isTargetedTestCase = (vitestFnCall) => {
|
|
|
5495
5468
|
};
|
|
5496
5469
|
function isEmptyFunction(node) {
|
|
5497
5470
|
if (!isFunction(node)) return false;
|
|
5498
|
-
return node.body.type ===
|
|
5471
|
+
return node.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement && !node.body.body.length;
|
|
5499
5472
|
}
|
|
5500
5473
|
function createTodoFixer(vitestFnCall, fixer) {
|
|
5501
5474
|
if (vitestFnCall.members.length) return replaceAccessorFixer(fixer, vitestFnCall.members[0], "todo");
|
|
@@ -5560,9 +5533,9 @@ var prefer_vi_mocked_default = createEslintRule({
|
|
|
5560
5533
|
create(context) {
|
|
5561
5534
|
function check(node) {
|
|
5562
5535
|
const { typeAnnotation } = node;
|
|
5563
|
-
if (typeAnnotation.type !==
|
|
5536
|
+
if (typeAnnotation.type !== _typescript_eslint_utils.AST_NODE_TYPES.TSTypeReference) return;
|
|
5564
5537
|
const { typeName } = typeAnnotation;
|
|
5565
|
-
if (typeName.type !==
|
|
5538
|
+
if (typeName.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
|
|
5566
5539
|
if (!mockTypes.includes(typeName.name)) return;
|
|
5567
5540
|
const fnName = context.sourceCode.text.slice(...followTypeAssertionChain(node.expression).range);
|
|
5568
5541
|
context.report({
|
|
@@ -5575,7 +5548,7 @@ var prefer_vi_mocked_default = createEslintRule({
|
|
|
5575
5548
|
}
|
|
5576
5549
|
return {
|
|
5577
5550
|
TSAsExpression(node) {
|
|
5578
|
-
if (node.parent.type ===
|
|
5551
|
+
if (node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.TSAsExpression) return;
|
|
5579
5552
|
check(node);
|
|
5580
5553
|
},
|
|
5581
5554
|
TSTypeAssertion(node) {
|
|
@@ -5608,7 +5581,7 @@ var require_awaited_expect_poll_default = createEslintRule({
|
|
|
5608
5581
|
const nodeToReport = vitestFnCall.members[0].parent;
|
|
5609
5582
|
if (reported.has(nodeToReport)) return;
|
|
5610
5583
|
const topMostNode = skipSequenceExpressions(skipMatchersAndModifiers(vitestFnCall.head.node));
|
|
5611
|
-
if (topMostNode.parent?.type ===
|
|
5584
|
+
if (topMostNode.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression || topMostNode.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement) return;
|
|
5612
5585
|
context.report({
|
|
5613
5586
|
node: nodeToReport,
|
|
5614
5587
|
messageId: "notAwaited",
|
|
@@ -5624,12 +5597,12 @@ function memberRequiresAwait(member) {
|
|
|
5624
5597
|
}
|
|
5625
5598
|
function skipMatchersAndModifiers(node) {
|
|
5626
5599
|
let currentNode = node;
|
|
5627
|
-
while (currentNode.parent.type ===
|
|
5600
|
+
while (currentNode.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || currentNode.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) currentNode = currentNode.parent;
|
|
5628
5601
|
return currentNode;
|
|
5629
5602
|
}
|
|
5630
5603
|
function skipSequenceExpressions(node) {
|
|
5631
5604
|
let currentNode = node;
|
|
5632
|
-
while (currentNode.parent?.type ===
|
|
5605
|
+
while (currentNode.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.SequenceExpression && currentNode.parent.expressions.at(-1) === currentNode) currentNode = currentNode.parent;
|
|
5633
5606
|
return currentNode;
|
|
5634
5607
|
}
|
|
5635
5608
|
|
|
@@ -5641,13 +5614,13 @@ const isVitestFnCall = (node, context) => {
|
|
|
5641
5614
|
return !!getNodeName(node)?.startsWith("vi");
|
|
5642
5615
|
};
|
|
5643
5616
|
const isNullOrUndefined = (node) => {
|
|
5644
|
-
return node.type ===
|
|
5617
|
+
return node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === null || isIdentifier(node, "undefined");
|
|
5645
5618
|
};
|
|
5646
5619
|
const shouldBeInHook = (node, context, allowedFunctionCalls = []) => {
|
|
5647
5620
|
switch (node.type) {
|
|
5648
|
-
case
|
|
5649
|
-
case
|
|
5650
|
-
case
|
|
5621
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement: return shouldBeInHook(node.expression, context, allowedFunctionCalls);
|
|
5622
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.CallExpression: return !(isVitestFnCall(node, context) || allowedFunctionCalls.includes(getNodeName(node)));
|
|
5623
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclaration:
|
|
5651
5624
|
if (node.kind === "const") return false;
|
|
5652
5625
|
return node.declarations.some(({ init }) => init !== null && !isNullOrUndefined(init));
|
|
5653
5626
|
default: return false;
|
|
@@ -5686,7 +5659,7 @@ var require_hook_default = createEslintRule({
|
|
|
5686
5659
|
CallExpression(node) {
|
|
5687
5660
|
if (!isTypeOfVitestFnCall(node, context, ["describe"]) || node.arguments.length < 2) return;
|
|
5688
5661
|
const [, testFn] = node.arguments;
|
|
5689
|
-
if (!isFunction(testFn) || testFn.body.type !==
|
|
5662
|
+
if (!isFunction(testFn) || testFn.body.type !== _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) return;
|
|
5690
5663
|
checkBlockBody(testFn.body.body);
|
|
5691
5664
|
}
|
|
5692
5665
|
};
|
|
@@ -5721,10 +5694,10 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5721
5694
|
const firstMember = vitestFnCall.members[0];
|
|
5722
5695
|
if (firstMember && getAccessorValue(firstMember) === "setConfig") {
|
|
5723
5696
|
const arg = node.arguments[0];
|
|
5724
|
-
if (arg && arg.type ===
|
|
5725
|
-
for (const prop of arg.properties) if (prop.type ===
|
|
5697
|
+
if (arg && arg.type === _typescript_eslint_utils.AST_NODE_TYPES.ObjectExpression) {
|
|
5698
|
+
for (const prop of arg.properties) if (prop.type === _typescript_eslint_utils.AST_NODE_TYPES.Property) {
|
|
5726
5699
|
const key = prop.key;
|
|
5727
|
-
if ((key.type ===
|
|
5700
|
+
if ((key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && key.name === "testTimeout" || key.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && key.value === "testTimeout") && prop.value.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof prop.value.value === "number" && prop.value.value >= 0) {
|
|
5728
5701
|
const endOffset = node.range ? node.range[1] : 0;
|
|
5729
5702
|
setConfigPositions.push(endOffset);
|
|
5730
5703
|
break;
|
|
@@ -5740,7 +5713,7 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5740
5713
|
return v === "todo" || v === "skip";
|
|
5741
5714
|
}) || vitestFnCall.name.startsWith("x")) return;
|
|
5742
5715
|
const args = node.arguments;
|
|
5743
|
-
if (!args.some((a) => a.type ===
|
|
5716
|
+
if (!args.some((a) => a.type === _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression || a.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression)) return;
|
|
5744
5717
|
/**
|
|
5745
5718
|
* If there is a setConfig call *before* this test that sets testTimeout,
|
|
5746
5719
|
* exempt this test. Note: we compare source positions (character offsets)
|
|
@@ -5751,7 +5724,7 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5751
5724
|
let foundNumericTimeout = false;
|
|
5752
5725
|
let foundObjectTimeout = false;
|
|
5753
5726
|
for (const a of args) {
|
|
5754
|
-
if (a.type ===
|
|
5727
|
+
if (a.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof a.value === "number") if (a.value >= 0) foundNumericTimeout = true;
|
|
5755
5728
|
else {
|
|
5756
5729
|
context.report({
|
|
5757
5730
|
node,
|
|
@@ -5759,10 +5732,10 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5759
5732
|
});
|
|
5760
5733
|
return;
|
|
5761
5734
|
}
|
|
5762
|
-
if (a.type ===
|
|
5763
|
-
if (prop.type !==
|
|
5735
|
+
if (a.type === _typescript_eslint_utils.AST_NODE_TYPES.ObjectExpression) for (const prop of a.properties) {
|
|
5736
|
+
if (prop.type !== _typescript_eslint_utils.AST_NODE_TYPES.Property) continue;
|
|
5764
5737
|
const key = prop.key;
|
|
5765
|
-
if (key.type ===
|
|
5738
|
+
if (key.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && key.name === "timeout" || key.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && key.value === "timeout") if (prop.value.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof prop.value.value === "number" && prop.value.value >= 0) foundObjectTimeout = true;
|
|
5766
5739
|
else {
|
|
5767
5740
|
context.report({
|
|
5768
5741
|
node,
|
|
@@ -5801,8 +5774,8 @@ var require_local_test_context_for_concurrent_snapshots_default = createEslintRu
|
|
|
5801
5774
|
if (vitestFnCall === null) return;
|
|
5802
5775
|
if (vitestFnCall.type !== "expect") return;
|
|
5803
5776
|
if (vitestFnCall.type === "expect" && vitestFnCall.head.type === "testContext") return;
|
|
5804
|
-
if (node.callee.type !==
|
|
5805
|
-
if (node.callee.property.type !==
|
|
5777
|
+
if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return;
|
|
5778
|
+
if (node.callee.property.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
|
|
5806
5779
|
if (![
|
|
5807
5780
|
"toMatchSnapshot",
|
|
5808
5781
|
"toMatchInlineSnapshot",
|
|
@@ -5811,9 +5784,9 @@ var require_local_test_context_for_concurrent_snapshots_default = createEslintRu
|
|
|
5811
5784
|
"toThrowErrorMatchingInlineSnapshot"
|
|
5812
5785
|
].includes(node.callee.property.name)) return;
|
|
5813
5786
|
if (!context.sourceCode.getAncestors(node).some((ancestor) => {
|
|
5814
|
-
if (ancestor.type !==
|
|
5787
|
+
if (ancestor.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return false;
|
|
5815
5788
|
if (!isTypeOfVitestFnCall(ancestor, context, ["describe", "test"])) return false;
|
|
5816
|
-
return ancestor.callee.type ===
|
|
5789
|
+
return ancestor.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(ancestor.callee.property, "concurrent");
|
|
5817
5790
|
})) return;
|
|
5818
5791
|
context.report({
|
|
5819
5792
|
node,
|
|
@@ -5977,7 +5950,7 @@ const hasNonEachMembersAndParams = (vitestFnCall, functionExpression) => {
|
|
|
5977
5950
|
};
|
|
5978
5951
|
const reportUnexpectedReturnInDescribe = (blockStatement, context) => {
|
|
5979
5952
|
blockStatement.body.forEach((node) => {
|
|
5980
|
-
if (node.type !==
|
|
5953
|
+
if (node.type !== _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement) return;
|
|
5981
5954
|
context.report({
|
|
5982
5955
|
messageId: "unexpectedReturnInDescribe",
|
|
5983
5956
|
node
|
|
@@ -6004,7 +5977,7 @@ var valid_describe_callback_default = createEslintRule({
|
|
|
6004
5977
|
return { CallExpression(node) {
|
|
6005
5978
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
6006
5979
|
if (vitestFnCall?.type !== "describe") return;
|
|
6007
|
-
if (vitestFnCall?.members[0]?.type ===
|
|
5980
|
+
if (vitestFnCall?.members[0]?.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && vitestFnCall.members[0].name === "todo") return;
|
|
6008
5981
|
if (node.arguments.length < 1) return context.report({
|
|
6009
5982
|
messageId: "nameAndCallback",
|
|
6010
5983
|
loc: node.loc
|
|
@@ -6023,11 +5996,11 @@ var valid_describe_callback_default = createEslintRule({
|
|
|
6023
5996
|
messageId: "unexpectedDescribeArgument",
|
|
6024
5997
|
node: arg3
|
|
6025
5998
|
});
|
|
6026
|
-
if (arg3.body.type ===
|
|
5999
|
+
if (arg3.body.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) context.report({
|
|
6027
6000
|
messageId: "unexpectedReturnInDescribe",
|
|
6028
6001
|
node: arg3
|
|
6029
6002
|
});
|
|
6030
|
-
if (arg3.body.type ===
|
|
6003
|
+
if (arg3.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) reportUnexpectedReturnInDescribe(arg3.body, context);
|
|
6031
6004
|
return;
|
|
6032
6005
|
}
|
|
6033
6006
|
context.report({
|
|
@@ -6040,11 +6013,11 @@ var valid_describe_callback_default = createEslintRule({
|
|
|
6040
6013
|
messageId: "unexpectedDescribeArgument",
|
|
6041
6014
|
node: arg2
|
|
6042
6015
|
});
|
|
6043
|
-
if (arg2.body.type ===
|
|
6016
|
+
if (arg2.body.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) context.report({
|
|
6044
6017
|
messageId: "unexpectedReturnInDescribe",
|
|
6045
6018
|
node: arg2
|
|
6046
6019
|
});
|
|
6047
|
-
if (arg2.body.type ===
|
|
6020
|
+
if (arg2.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) reportUnexpectedReturnInDescribe(arg2.body, context);
|
|
6048
6021
|
} };
|
|
6049
6022
|
}
|
|
6050
6023
|
});
|
|
@@ -6053,7 +6026,7 @@ var valid_describe_callback_default = createEslintRule({
|
|
|
6053
6026
|
//#region src/rules/valid-expect-in-promise.ts
|
|
6054
6027
|
const RULE_NAME$5 = "valid-expect-in-promise";
|
|
6055
6028
|
const isPromiseChainCall = (node) => {
|
|
6056
|
-
if (node.type ===
|
|
6029
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property)) {
|
|
6057
6030
|
if (node.arguments.length === 0) return false;
|
|
6058
6031
|
switch (getAccessorValue(node.callee.property)) {
|
|
6059
6032
|
case "then": return node.arguments.length < 3;
|
|
@@ -6067,7 +6040,7 @@ const isTestCaseCallWithCallbackArg = (node, context) => {
|
|
|
6067
6040
|
const vitestCallFn = parseVitestFnCall(node, context);
|
|
6068
6041
|
if (vitestCallFn?.type !== "test") return false;
|
|
6069
6042
|
const isVitestEach = vitestCallFn.members.some((s) => getAccessorValue(s) === "each");
|
|
6070
|
-
if (isVitestEach && node.callee.type !==
|
|
6043
|
+
if (isVitestEach && node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression) return true;
|
|
6071
6044
|
const [, callback] = node.arguments;
|
|
6072
6045
|
const callbackArgIndex = Number(isVitestEach);
|
|
6073
6046
|
return callback && isFunction(callback) && callback.params.length === 1 + callbackArgIndex;
|
|
@@ -6075,11 +6048,11 @@ const isTestCaseCallWithCallbackArg = (node, context) => {
|
|
|
6075
6048
|
const isPromiseMethodThatUsesValue = (node, identifier) => {
|
|
6076
6049
|
const { name } = identifier;
|
|
6077
6050
|
if (node.argument === null) return false;
|
|
6078
|
-
if (node.argument.type ===
|
|
6051
|
+
if (node.argument.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && node.argument.arguments.length > 0) {
|
|
6079
6052
|
const nodeName = getNodeName(node.argument);
|
|
6080
6053
|
if (["Promise.all", "Promise.allSettled"].includes(nodeName)) {
|
|
6081
6054
|
const [firstArg] = node.argument.arguments;
|
|
6082
|
-
if (firstArg.type ===
|
|
6055
|
+
if (firstArg.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrayExpression && firstArg.elements.some((nod) => nod && isIdentifier(nod, name))) return true;
|
|
6083
6056
|
}
|
|
6084
6057
|
if (["Promise.resolve", "Promise.reject"].includes(nodeName) && node.argument.arguments.length === 1) return isIdentifier(node.argument.arguments[0], name);
|
|
6085
6058
|
}
|
|
@@ -6091,8 +6064,8 @@ const isPromiseMethodThatUsesValue = (node, identifier) => {
|
|
|
6091
6064
|
*/
|
|
6092
6065
|
const isValueAwaitedInElements = (name, elements) => {
|
|
6093
6066
|
for (const element of elements) {
|
|
6094
|
-
if (element?.type ===
|
|
6095
|
-
if (element?.type ===
|
|
6067
|
+
if (element?.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression && isIdentifier(element.argument, name)) return true;
|
|
6068
|
+
if (element?.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrayExpression && isValueAwaitedInElements(name, element.elements)) return true;
|
|
6096
6069
|
}
|
|
6097
6070
|
return false;
|
|
6098
6071
|
};
|
|
@@ -6103,11 +6076,11 @@ const isValueAwaitedInElements = (name, elements) => {
|
|
|
6103
6076
|
const isValueAwaitedInArguments = (name, call) => {
|
|
6104
6077
|
let node = call;
|
|
6105
6078
|
while (node) {
|
|
6106
|
-
if (node.type ===
|
|
6079
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) {
|
|
6107
6080
|
if (isValueAwaitedInElements(name, node.arguments)) return true;
|
|
6108
6081
|
node = node.callee;
|
|
6109
6082
|
}
|
|
6110
|
-
if (node.type !==
|
|
6083
|
+
if (node.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) break;
|
|
6111
6084
|
node = node.object;
|
|
6112
6085
|
}
|
|
6113
6086
|
return false;
|
|
@@ -6116,11 +6089,11 @@ const getLeftMostCallExpression = (call) => {
|
|
|
6116
6089
|
let leftMostCallExpression = call;
|
|
6117
6090
|
let node = call;
|
|
6118
6091
|
while (node) {
|
|
6119
|
-
if (node.type ===
|
|
6092
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) {
|
|
6120
6093
|
leftMostCallExpression = node;
|
|
6121
6094
|
node = node.callee;
|
|
6122
6095
|
}
|
|
6123
|
-
if (node.type !==
|
|
6096
|
+
if (node.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) break;
|
|
6124
6097
|
node = node.object;
|
|
6125
6098
|
}
|
|
6126
6099
|
return leftMostCallExpression;
|
|
@@ -6133,9 +6106,9 @@ const isValueAwaitedOrReturned = (identifier, body, context) => {
|
|
|
6133
6106
|
const { name } = identifier;
|
|
6134
6107
|
for (const node of body) {
|
|
6135
6108
|
if (node.range[0] <= identifier.range[0]) continue;
|
|
6136
|
-
if (node.type ===
|
|
6137
|
-
if (node.type ===
|
|
6138
|
-
if (node.expression.type ===
|
|
6109
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement) return isPromiseMethodThatUsesValue(node, identifier);
|
|
6110
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement) {
|
|
6111
|
+
if (node.expression.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) {
|
|
6139
6112
|
if (isValueAwaitedInArguments(name, node.expression)) return true;
|
|
6140
6113
|
const leftMostCall = getLeftMostCallExpression(node.expression);
|
|
6141
6114
|
const vitestFnCall = parseVitestFnCall(node.expression, context);
|
|
@@ -6146,20 +6119,20 @@ const isValueAwaitedOrReturned = (identifier, body, context) => {
|
|
|
6146
6119
|
})) return true;
|
|
6147
6120
|
}
|
|
6148
6121
|
}
|
|
6149
|
-
if (node.expression.type ===
|
|
6150
|
-
if (node.expression.type ===
|
|
6122
|
+
if (node.expression.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression && isPromiseMethodThatUsesValue(node.expression, identifier)) return true;
|
|
6123
|
+
if (node.expression.type === _typescript_eslint_utils.AST_NODE_TYPES.AssignmentExpression) {
|
|
6151
6124
|
if (isIdentifier(node.expression.left, name) && getNodeName(node.expression.right)?.startsWith(`${name}.`) && isPromiseChainCall(node.expression.right)) continue;
|
|
6152
6125
|
break;
|
|
6153
6126
|
}
|
|
6154
6127
|
}
|
|
6155
|
-
if (node.type ===
|
|
6128
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement && isValueAwaitedOrReturned(identifier, node.body, context)) return true;
|
|
6156
6129
|
}
|
|
6157
6130
|
return false;
|
|
6158
6131
|
};
|
|
6159
6132
|
const findFirstBlockBodyUp = (node) => {
|
|
6160
6133
|
let parent = node;
|
|
6161
6134
|
while (parent) {
|
|
6162
|
-
if (parent.type ===
|
|
6135
|
+
if (parent.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) return parent.body;
|
|
6163
6136
|
parent = parent.parent;
|
|
6164
6137
|
}
|
|
6165
6138
|
/* istanbul ignore next */
|
|
@@ -6170,7 +6143,7 @@ const isDirectlyWithinTestCaseCall = (node, context) => {
|
|
|
6170
6143
|
while (parent) {
|
|
6171
6144
|
if (isFunction(parent)) {
|
|
6172
6145
|
parent = parent.parent;
|
|
6173
|
-
return parent?.type ===
|
|
6146
|
+
return parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && isTypeOfVitestFnCall(parent, context, ["test"]);
|
|
6174
6147
|
}
|
|
6175
6148
|
parent = parent.parent;
|
|
6176
6149
|
}
|
|
@@ -6214,15 +6187,15 @@ var valid_expect_in_promise_default = createEslintRule({
|
|
|
6214
6187
|
const { parent } = findTopMostCallExpression(node);
|
|
6215
6188
|
if (!parent || !isDirectlyWithinTestCaseCall(parent, context)) return;
|
|
6216
6189
|
switch (parent.type) {
|
|
6217
|
-
case
|
|
6190
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator:
|
|
6218
6191
|
if (isVariableAwaitedOrReturned(parent, context)) return;
|
|
6219
6192
|
break;
|
|
6220
|
-
case
|
|
6221
|
-
if (parent.left.type ===
|
|
6193
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.AssignmentExpression:
|
|
6194
|
+
if (parent.left.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && isValueAwaitedOrReturned(parent.left, findFirstBlockBodyUp(parent), context)) return;
|
|
6222
6195
|
break;
|
|
6223
|
-
case
|
|
6224
|
-
case
|
|
6225
|
-
case
|
|
6196
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement: break;
|
|
6197
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement:
|
|
6198
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression:
|
|
6226
6199
|
default: return;
|
|
6227
6200
|
}
|
|
6228
6201
|
context.report({
|
|
@@ -6246,29 +6219,29 @@ const defaultAsyncMatchers = ["toReject", "toResolve"];
|
|
|
6246
6219
|
* @Returns CallExpressionNode
|
|
6247
6220
|
*/
|
|
6248
6221
|
const getPromiseCallExpressionNode = (node) => {
|
|
6249
|
-
if (node.type ===
|
|
6250
|
-
if (node.type ===
|
|
6222
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrayExpression && node.parent && node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) node = node.parent;
|
|
6223
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.object, "Promise") && node.parent) return node;
|
|
6251
6224
|
return null;
|
|
6252
6225
|
};
|
|
6253
6226
|
const promiseArrayExceptionKey = ({ start, end }) => `${start.line}:${start.column}-${end.line}:${end.column}`;
|
|
6254
6227
|
const getNormalizeFunctionExpression = (functionExpression) => {
|
|
6255
|
-
if (functionExpression.parent.type ===
|
|
6228
|
+
if (functionExpression.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.Property && functionExpression.type === _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression) return functionExpression.parent;
|
|
6256
6229
|
return functionExpression;
|
|
6257
6230
|
};
|
|
6258
6231
|
function getParentIfThenified(node) {
|
|
6259
6232
|
const grandParentNode = node.parent?.parent;
|
|
6260
|
-
if (grandParentNode && grandParentNode.type ===
|
|
6233
|
+
if (grandParentNode && grandParentNode.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && grandParentNode.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(grandParentNode.callee.property) && ["then", "catch"].includes(getAccessorValue(grandParentNode.callee.property)) && grandParentNode.parent) return getParentIfThenified(grandParentNode);
|
|
6261
6234
|
return node;
|
|
6262
6235
|
}
|
|
6263
|
-
const findPromiseCallExpressionNode = (node) => node.parent?.parent && [
|
|
6236
|
+
const findPromiseCallExpressionNode = (node) => node.parent?.parent && [_typescript_eslint_utils.AST_NODE_TYPES.CallExpression, _typescript_eslint_utils.AST_NODE_TYPES.ArrayExpression].includes(node.parent.type) ? getPromiseCallExpressionNode(node.parent) : null;
|
|
6264
6237
|
const findFirstFunctionExpression = ({ parent }) => {
|
|
6265
6238
|
if (!parent) return null;
|
|
6266
6239
|
return isFunction(parent) ? parent : findFirstFunctionExpression(parent);
|
|
6267
6240
|
};
|
|
6268
6241
|
const isAcceptableReturnNode = (node, allowReturn) => {
|
|
6269
|
-
if (allowReturn && node.type ===
|
|
6270
|
-
if (node.type ===
|
|
6271
|
-
return [
|
|
6242
|
+
if (allowReturn && node.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement) return true;
|
|
6243
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.ConditionalExpression && node.parent) return isAcceptableReturnNode(node.parent, allowReturn);
|
|
6244
|
+
return [_typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression, _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression].includes(node.type);
|
|
6272
6245
|
};
|
|
6273
6246
|
var valid_expect_default = createEslintRule({
|
|
6274
6247
|
name: RULE_NAME$4,
|
|
@@ -6330,7 +6303,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6330
6303
|
let topMostMemberExpression = node;
|
|
6331
6304
|
let { parent } = node;
|
|
6332
6305
|
while (parent) {
|
|
6333
|
-
if (parent.type !==
|
|
6306
|
+
if (parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) break;
|
|
6334
6307
|
topMostMemberExpression = parent;
|
|
6335
6308
|
parent = parent.parent;
|
|
6336
6309
|
}
|
|
@@ -6341,7 +6314,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6341
6314
|
const vitestFnCall = parseVitestFnCallWithReason(node, context);
|
|
6342
6315
|
const settings = parsePluginSettings(context.settings);
|
|
6343
6316
|
if (typeof vitestFnCall === "string") {
|
|
6344
|
-
const reportingNode = node.parent?.type ===
|
|
6317
|
+
const reportingNode = node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression ? findTopMostMemberExpression(node.parent).property : node;
|
|
6345
6318
|
if (vitestFnCall === "matcher-not-found") {
|
|
6346
6319
|
context.report({
|
|
6347
6320
|
messageId: "matcherNotFound",
|
|
@@ -6363,9 +6336,9 @@ var valid_expect_default = createEslintRule({
|
|
|
6363
6336
|
return;
|
|
6364
6337
|
} else if (vitestFnCall?.type === "expectTypeOf" && settings.typecheck) return;
|
|
6365
6338
|
else if (vitestFnCall?.type !== "expect") return;
|
|
6366
|
-
else if (vitestFnCall.modifiers.some((mod) => mod.type ===
|
|
6339
|
+
else if (vitestFnCall.modifiers.some((mod) => mod.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && mod.name == "to")) return;
|
|
6367
6340
|
const { parent: expect } = vitestFnCall.head.node;
|
|
6368
|
-
if (expect?.type !==
|
|
6341
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
6369
6342
|
if (expect.arguments.length < minArgs) {
|
|
6370
6343
|
const expectLength = getAccessorValue(vitestFnCall.head.node).length;
|
|
6371
6344
|
const loc = {
|
|
@@ -6390,8 +6363,8 @@ var valid_expect_default = createEslintRule({
|
|
|
6390
6363
|
}
|
|
6391
6364
|
if (expect.arguments.length > maxArgs) {
|
|
6392
6365
|
if (expect.arguments.length === 2) {
|
|
6393
|
-
const isSecondArgString = expect.arguments[1].type ===
|
|
6394
|
-
const isSecondArgTemplateLiteral = expect.arguments[1].type ===
|
|
6366
|
+
const isSecondArgString = expect.arguments[1].type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof expect.arguments[1].value === "string";
|
|
6367
|
+
const isSecondArgTemplateLiteral = expect.arguments[1].type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral;
|
|
6395
6368
|
if (isSecondArgString || isSecondArgTemplateLiteral) return;
|
|
6396
6369
|
}
|
|
6397
6370
|
const { start } = expect.arguments[maxArgs].loc;
|
|
@@ -6417,7 +6390,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6417
6390
|
const parentNode = matcher.parent.parent;
|
|
6418
6391
|
const shouldBeAwaited = vitestFnCall.modifiers.some((nod) => getAccessorValue(nod) !== "not") || asyncMatchers.includes(getAccessorValue(matcher));
|
|
6419
6392
|
if (!parentNode?.parent || !shouldBeAwaited) return;
|
|
6420
|
-
const isParentArrayExpression = parentNode.parent.type ===
|
|
6393
|
+
const isParentArrayExpression = parentNode.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrayExpression;
|
|
6421
6394
|
const targetNode = getParentIfThenified(parentNode);
|
|
6422
6395
|
const finalNode = findPromiseCallExpressionNode(targetNode) || targetNode;
|
|
6423
6396
|
if (finalNode.parent && !isAcceptableReturnNode(finalNode.parent, !alwaysAwait) && !promiseArrayExceptionExists(finalNode.loc)) {
|
|
@@ -6445,7 +6418,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6445
6418
|
const targetFunction = getNormalizeFunctionExpression(functionExpression);
|
|
6446
6419
|
fixes.push(fixer.insertTextBefore(targetFunction, "async "));
|
|
6447
6420
|
}
|
|
6448
|
-
const returnStatement = node.parent?.type ===
|
|
6421
|
+
const returnStatement = node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement ? node.parent : null;
|
|
6449
6422
|
if (alwaysAwait && returnStatement) {
|
|
6450
6423
|
const replacedText = context.sourceCode.getText(returnStatement).replace("return", "await");
|
|
6451
6424
|
fixes.push(fixer.replaceText(returnStatement, replacedText));
|
|
@@ -6463,7 +6436,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6463
6436
|
//#region src/rules/valid-title.ts
|
|
6464
6437
|
const RULE_NAME$3 = "valid-title";
|
|
6465
6438
|
const trimFXPrefix = (word) => ["f", "x"].includes(word.charAt(0)) ? word.substring(1) : word;
|
|
6466
|
-
const quoteStringValue = (node) => node.type ===
|
|
6439
|
+
const quoteStringValue = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral ? `\`${node.quasis[0].value.raw}\`` : node.raw;
|
|
6467
6440
|
const MatcherAndMessageSchema = {
|
|
6468
6441
|
type: "array",
|
|
6469
6442
|
items: { type: "string" },
|
|
@@ -6496,7 +6469,7 @@ const compileMatcherPatterns = (matchers) => {
|
|
|
6496
6469
|
};
|
|
6497
6470
|
const doesBinaryExpressionContainStringNode = (binaryExp) => {
|
|
6498
6471
|
if (isStringNode(binaryExp.right)) return true;
|
|
6499
|
-
if (binaryExp.left.type ===
|
|
6472
|
+
if (binaryExp.left.type === _typescript_eslint_utils.AST_NODE_TYPES.BinaryExpression) return doesBinaryExpressionContainStringNode(binaryExp.left);
|
|
6500
6473
|
return isStringNode(binaryExp.left);
|
|
6501
6474
|
};
|
|
6502
6475
|
var valid_title_default = createEslintRule({
|
|
@@ -6562,24 +6535,24 @@ var valid_title_default = createEslintRule({
|
|
|
6562
6535
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
6563
6536
|
if (vitestFnCall?.type !== "describe" && vitestFnCall?.type !== "test" && vitestFnCall?.type !== "it") return;
|
|
6564
6537
|
if (vitestFnCall.members.some((member) => ["extend", "scoped"].includes(getAccessorValue(member)))) return;
|
|
6565
|
-
const reportEmptyTitle = (node
|
|
6538
|
+
const reportEmptyTitle = (node) => {
|
|
6566
6539
|
context.report({
|
|
6567
6540
|
messageId: "emptyTitle",
|
|
6568
6541
|
data: { functionName: vitestFnCall.type === "describe" ? DescribeAlias.describe : TestCaseName.test },
|
|
6569
|
-
node
|
|
6542
|
+
node
|
|
6570
6543
|
});
|
|
6571
6544
|
};
|
|
6572
6545
|
const [argument] = node.arguments;
|
|
6573
6546
|
const getArgumentType = () => {
|
|
6574
6547
|
if (!settings.typecheck) return null;
|
|
6575
|
-
return
|
|
6548
|
+
return _typescript_eslint_utils.ESLintUtils.getParserServices(context).getTypeAtLocation(argument);
|
|
6576
6549
|
};
|
|
6577
6550
|
const type = getArgumentType();
|
|
6578
6551
|
if (type && isClassOrFunctionType(type)) return;
|
|
6579
|
-
if (!argument || allowArguments && argument.type ===
|
|
6552
|
+
if (!argument || allowArguments && argument.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
|
|
6580
6553
|
if (!isStringNode(argument)) {
|
|
6581
|
-
if (argument.type ===
|
|
6582
|
-
if (argument.type !==
|
|
6554
|
+
if (argument.type === _typescript_eslint_utils.AST_NODE_TYPES.BinaryExpression && doesBinaryExpressionContainStringNode(argument) || type && isStringLikeType(type)) return;
|
|
6555
|
+
if (argument.type !== _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral && !(ignoreTypeOfDescribeName && vitestFnCall.type === "describe")) context.report({
|
|
6583
6556
|
messageId: "titleMustBeString",
|
|
6584
6557
|
loc: argument.loc
|
|
6585
6558
|
});
|
|
@@ -6678,10 +6651,10 @@ var warn_todo_default = createEslintRule({
|
|
|
6678
6651
|
const RULE_NAME$1 = "no-unneeded-async-expect-function";
|
|
6679
6652
|
const getAwaitedCallExpression = (expression) => {
|
|
6680
6653
|
if (!expression.async) return null;
|
|
6681
|
-
if (expression.type ===
|
|
6682
|
-
if (expression.body.type !==
|
|
6654
|
+
if (expression.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression && expression.body.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression && expression.body.argument.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return expression.body.argument;
|
|
6655
|
+
if (expression.body.type !== _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement || expression.body.body.length !== 1) return null;
|
|
6683
6656
|
const [callback] = expression.body.body;
|
|
6684
|
-
if (callback.type ===
|
|
6657
|
+
if (callback.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement && callback.expression.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression && callback.expression.argument.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return callback.expression.argument;
|
|
6685
6658
|
return null;
|
|
6686
6659
|
};
|
|
6687
6660
|
var no_unneeded_async_expect_function_default = createEslintRule({
|
|
@@ -6698,7 +6671,7 @@ var no_unneeded_async_expect_function_default = createEslintRule({
|
|
|
6698
6671
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
6699
6672
|
if (vitestFnCall?.type !== "expect") return;
|
|
6700
6673
|
const { parent } = vitestFnCall.head.node;
|
|
6701
|
-
if (parent?.type !==
|
|
6674
|
+
if (parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
6702
6675
|
const [awaitNode] = parent.arguments;
|
|
6703
6676
|
if (!awaitNode || !isFunction(awaitNode)) return;
|
|
6704
6677
|
const innerAsyncFuncCall = getAwaitedCallExpression(awaitNode);
|
|
@@ -6732,13 +6705,13 @@ var prefer_to_have_been_called_times_default = createEslintRule({
|
|
|
6732
6705
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
6733
6706
|
if (vitestFnCall?.type !== "expect") return;
|
|
6734
6707
|
const { parent: expect } = vitestFnCall.head.node;
|
|
6735
|
-
if (expect?.type !==
|
|
6708
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
6736
6709
|
const { matcher } = vitestFnCall;
|
|
6737
6710
|
if (!isSupportedAccessor(matcher, "toHaveLength")) return;
|
|
6738
6711
|
const [argument] = expect.arguments;
|
|
6739
|
-
if (argument?.type !==
|
|
6712
|
+
if (argument?.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || !isSupportedAccessor(argument.property, "calls")) return;
|
|
6740
6713
|
const { object } = argument;
|
|
6741
|
-
if (object.type !==
|
|
6714
|
+
if (object.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || !isSupportedAccessor(object.property, "mock")) return;
|
|
6742
6715
|
context.report({
|
|
6743
6716
|
messageId: "preferMatcher",
|
|
6744
6717
|
node: matcher,
|
|
@@ -6838,18 +6811,18 @@ const rules = {
|
|
|
6838
6811
|
|
|
6839
6812
|
//#endregion
|
|
6840
6813
|
//#region src/index.ts
|
|
6841
|
-
const createConfig = (rules
|
|
6814
|
+
const createConfig = (rules) => Object.keys(rules).reduce((acc, ruleName) => {
|
|
6842
6815
|
return {
|
|
6843
6816
|
...acc,
|
|
6844
|
-
[`vitest/${ruleName}`]: rules
|
|
6817
|
+
[`vitest/${ruleName}`]: rules[ruleName]
|
|
6845
6818
|
};
|
|
6846
6819
|
}, {});
|
|
6847
|
-
const createConfigLegacy = (rules
|
|
6820
|
+
const createConfigLegacy = (rules) => ({
|
|
6848
6821
|
plugins: ["@vitest"],
|
|
6849
|
-
rules: Object.keys(rules
|
|
6822
|
+
rules: Object.keys(rules).reduce((acc, ruleName) => {
|
|
6850
6823
|
return {
|
|
6851
6824
|
...acc,
|
|
6852
|
-
[`@vitest/${ruleName}`]: rules
|
|
6825
|
+
[`@vitest/${ruleName}`]: rules[ruleName]
|
|
6853
6826
|
};
|
|
6854
6827
|
}, {})
|
|
6855
6828
|
});
|
|
@@ -7018,7 +6991,6 @@ const plugin = {
|
|
|
7018
6991
|
}
|
|
7019
6992
|
}
|
|
7020
6993
|
};
|
|
7021
|
-
var src_default = plugin;
|
|
7022
6994
|
|
|
7023
6995
|
//#endregion
|
|
7024
|
-
module.exports =
|
|
6996
|
+
module.exports = plugin;
|