@vitest/eslint-plugin 1.6.6 → 1.6.8
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 +416 -536
- package/dist/{index.js → index.mjs} +169 -262
- package/package.json +17 -17
- /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.8";
|
|
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
|
|
@@ -1853,7 +1826,6 @@ var consistent_each_for_default = createEslintRule({
|
|
|
1853
1826
|
}],
|
|
1854
1827
|
defaultOptions: [{}]
|
|
1855
1828
|
},
|
|
1856
|
-
defaultOptions: [{}],
|
|
1857
1829
|
create(context, [options]) {
|
|
1858
1830
|
return { CallExpression(node) {
|
|
1859
1831
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -1900,21 +1872,19 @@ var consistent_test_filename_default = createEslintRule({
|
|
|
1900
1872
|
properties: {
|
|
1901
1873
|
pattern: {
|
|
1902
1874
|
type: "string",
|
|
1903
|
-
format: "regex"
|
|
1904
|
-
default: defaultPattern.source
|
|
1875
|
+
format: "regex"
|
|
1905
1876
|
},
|
|
1906
1877
|
allTestPattern: {
|
|
1907
1878
|
type: "string",
|
|
1908
|
-
format: "regex"
|
|
1909
|
-
default: defaultTestsPattern.source
|
|
1879
|
+
format: "regex"
|
|
1910
1880
|
}
|
|
1911
1881
|
}
|
|
1882
|
+
}],
|
|
1883
|
+
defaultOptions: [{
|
|
1884
|
+
pattern: defaultPattern.source,
|
|
1885
|
+
allTestPattern: defaultTestsPattern.source
|
|
1912
1886
|
}]
|
|
1913
1887
|
},
|
|
1914
|
-
defaultOptions: [{
|
|
1915
|
-
pattern: defaultPattern.source,
|
|
1916
|
-
allTestPattern: defaultTestsPattern.source
|
|
1917
|
-
}],
|
|
1918
1888
|
create: (context, options) => {
|
|
1919
1889
|
const { pattern: patternRaw, allTestPattern: allTestPatternRaw } = options[0];
|
|
1920
1890
|
const pattern = new RegExp(patternRaw);
|
|
@@ -1934,7 +1904,7 @@ var consistent_test_filename_default = createEslintRule({
|
|
|
1934
1904
|
//#endregion
|
|
1935
1905
|
//#region src/rules/consistent-test-it.ts
|
|
1936
1906
|
const RULE_NAME$78 = "consistent-test-it";
|
|
1937
|
-
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))];
|
|
1938
1908
|
function getPreferredNodeName(nodeName, preferredTestKeyword) {
|
|
1939
1909
|
if (nodeName === TestCaseName.fit) return "test.only";
|
|
1940
1910
|
return nodeName.startsWith("f") || nodeName.startsWith("x") ? nodeName.charAt(0) + preferredTestKeyword : preferredTestKeyword;
|
|
@@ -1969,9 +1939,9 @@ var consistent_test_it_default = createEslintRule({
|
|
|
1969
1939
|
}
|
|
1970
1940
|
},
|
|
1971
1941
|
additionalProperties: false
|
|
1972
|
-
}]
|
|
1942
|
+
}],
|
|
1943
|
+
defaultOptions: [{}]
|
|
1973
1944
|
},
|
|
1974
|
-
defaultOptions: [{}],
|
|
1975
1945
|
create(context, options) {
|
|
1976
1946
|
const { fn, withinDescribe } = options[0];
|
|
1977
1947
|
const testFnKeyWork = fn || TestCaseName.test;
|
|
@@ -1998,7 +1968,7 @@ var consistent_test_it_default = createEslintRule({
|
|
|
1998
1968
|
fix: (fixer) => {
|
|
1999
1969
|
const remainingSpecifiers = node.specifiers.filter((spec) => spec !== specifier);
|
|
2000
1970
|
if (remainingSpecifiers.length > 0) {
|
|
2001
|
-
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);
|
|
2002
1972
|
const importNames = remainingSpecifiers.map((spec) => sourceCode.getText(spec));
|
|
2003
1973
|
if (!hasPreferredSpecifier) importNames.push(testFnDisabled);
|
|
2004
1974
|
const importText = importNames.join(", ");
|
|
@@ -2012,14 +1982,14 @@ var consistent_test_it_default = createEslintRule({
|
|
|
2012
1982
|
}
|
|
2013
1983
|
},
|
|
2014
1984
|
CallExpression(node) {
|
|
2015
|
-
if (node.callee.type ===
|
|
1985
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && node.callee.name === "bench") return;
|
|
2016
1986
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
2017
1987
|
if (!vitestFnCall) return;
|
|
2018
1988
|
if (vitestFnCall.type === "describe") {
|
|
2019
1989
|
describeNestingLevel++;
|
|
2020
1990
|
return;
|
|
2021
1991
|
}
|
|
2022
|
-
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;
|
|
2023
1993
|
if (vitestFnCall.type === "test" && describeNestingLevel === 0 && !vitestFnCall.name.endsWith(testFnKeyWork)) {
|
|
2024
1994
|
const oppositeTestKeyword = getOppositeTestKeyword(testFnKeyWork);
|
|
2025
1995
|
context.report({
|
|
@@ -2069,22 +2039,21 @@ var consistent_vitest_vi_default = createEslintRule({
|
|
|
2069
2039
|
type: "object",
|
|
2070
2040
|
properties: { fn: {
|
|
2071
2041
|
type: "string",
|
|
2072
|
-
enum: [UtilName.vi, UtilName.vitest]
|
|
2073
|
-
default: UtilName.vi
|
|
2042
|
+
enum: [UtilName.vi, UtilName.vitest]
|
|
2074
2043
|
} },
|
|
2075
2044
|
additionalProperties: false
|
|
2076
|
-
}]
|
|
2045
|
+
}],
|
|
2046
|
+
defaultOptions: [{ fn: UtilName.vi }]
|
|
2077
2047
|
},
|
|
2078
|
-
defaultOptions: [{ fn: UtilName.vi }],
|
|
2079
2048
|
create(context, options) {
|
|
2080
2049
|
const utilKeyword = options[0].fn;
|
|
2081
2050
|
const oppositeUtilKeyword = getOppositeVitestUtilKeyword(utilKeyword);
|
|
2082
2051
|
return {
|
|
2083
2052
|
ImportDeclaration(node) {
|
|
2084
|
-
if (node.source.type !==
|
|
2053
|
+
if (node.source.type !== _typescript_eslint_utils.AST_NODE_TYPES.Literal || node.source.value !== "vitest") return;
|
|
2085
2054
|
for (const specifier of node.specifiers) {
|
|
2086
|
-
if (specifier.type !==
|
|
2087
|
-
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;
|
|
2088
2057
|
if (specifier.local.name !== specifier.imported.name) continue;
|
|
2089
2058
|
if (specifier.imported.name === oppositeUtilKeyword) context.report({
|
|
2090
2059
|
node: specifier,
|
|
@@ -2110,7 +2079,7 @@ var consistent_vitest_vi_default = createEslintRule({
|
|
|
2110
2079
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
2111
2080
|
if (vitestFnCall?.type !== "vi") return;
|
|
2112
2081
|
if (!isSupportedAccessor(vitestFnCall.head.node, oppositeUtilKeyword)) return;
|
|
2113
|
-
const replaceNode = node.callee.type ===
|
|
2082
|
+
const replaceNode = node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression ? node.callee.object : node.callee;
|
|
2114
2083
|
context.report({
|
|
2115
2084
|
node: replaceNode,
|
|
2116
2085
|
data: {
|
|
@@ -2167,18 +2136,14 @@ var expect_expect_default = createEslintRule({
|
|
|
2167
2136
|
}],
|
|
2168
2137
|
messages: { noAssertions: "Test has no assertions" }
|
|
2169
2138
|
},
|
|
2170
|
-
defaultOptions: [{
|
|
2171
|
-
assertFunctionNames: ["expect", "assert"],
|
|
2172
|
-
additionalTestBlockFunctions: []
|
|
2173
|
-
}],
|
|
2174
2139
|
create(context, [{ assertFunctionNames = ["expect"], additionalTestBlockFunctions = [] }]) {
|
|
2175
2140
|
const unchecked = [];
|
|
2176
2141
|
if (parsePluginSettings(context.settings).typecheck) assertFunctionNames.push("expectTypeOf", "assertType");
|
|
2177
2142
|
const assertFunctionRegexps = assertFunctionNames.map(buildPatternRegexp);
|
|
2178
2143
|
function checkCallExpression(nodes) {
|
|
2179
2144
|
for (const node of nodes) {
|
|
2180
|
-
const index = node.type ===
|
|
2181
|
-
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));
|
|
2182
2147
|
if (index !== -1) {
|
|
2183
2148
|
unchecked.splice(index, 1);
|
|
2184
2149
|
break;
|
|
@@ -2187,15 +2152,15 @@ var expect_expect_default = createEslintRule({
|
|
|
2187
2152
|
}
|
|
2188
2153
|
return {
|
|
2189
2154
|
CallExpression(node) {
|
|
2190
|
-
if (node.callee.type ===
|
|
2191
|
-
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 && [
|
|
2192
2157
|
"skip",
|
|
2193
2158
|
"extend",
|
|
2194
2159
|
"scoped"
|
|
2195
2160
|
].includes(node.callee.property.name)) return;
|
|
2196
2161
|
const name = getNodeName(node) ?? "";
|
|
2197
2162
|
if (isTypeOfVitestFnCall(node, context, ["test"]) || additionalTestBlockFunctions.includes(name)) {
|
|
2198
|
-
if (node.callee.type ===
|
|
2163
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, "todo")) return;
|
|
2199
2164
|
unchecked.push(node);
|
|
2200
2165
|
} else if (assertFunctionRegexps.some((p) => p.test(name))) checkCallExpression(context.sourceCode.getAncestors(node));
|
|
2201
2166
|
},
|
|
@@ -2239,27 +2204,26 @@ var hoisted_apis_on_top_default = createEslintRule({
|
|
|
2239
2204
|
},
|
|
2240
2205
|
schema: []
|
|
2241
2206
|
},
|
|
2242
|
-
defaultOptions: [],
|
|
2243
2207
|
create(context) {
|
|
2244
2208
|
let lastImportEnd = null;
|
|
2245
2209
|
const nodesToReport = [];
|
|
2246
2210
|
return {
|
|
2247
2211
|
ImportDeclaration(node) {
|
|
2248
|
-
if (node.parent.type !==
|
|
2212
|
+
if (node.parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.Program) return;
|
|
2249
2213
|
lastImportEnd = node.range[1];
|
|
2250
2214
|
},
|
|
2251
2215
|
CallExpression(node) {
|
|
2252
|
-
if (node.callee.type !==
|
|
2216
|
+
if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return;
|
|
2253
2217
|
const { object, property } = node.callee;
|
|
2254
|
-
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;
|
|
2255
2219
|
const apiName = property.name;
|
|
2256
2220
|
if (!hoistedAPIs.includes(apiName)) return;
|
|
2257
2221
|
if (apiName === "hoisted") {
|
|
2258
2222
|
let parent = node.parent;
|
|
2259
|
-
if (parent?.type ===
|
|
2260
|
-
if (parent?.type ===
|
|
2261
|
-
if ((parent?.type ===
|
|
2262
|
-
} 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;
|
|
2263
2227
|
nodesToReport.push(node);
|
|
2264
2228
|
},
|
|
2265
2229
|
"Program:exit"() {
|
|
@@ -2268,7 +2232,7 @@ var hoisted_apis_on_top_default = createEslintRule({
|
|
|
2268
2232
|
suggestions.push({
|
|
2269
2233
|
messageId: "suggestMoveHoistedApiToTop",
|
|
2270
2234
|
*fix(fixer) {
|
|
2271
|
-
if (node.parent.type ===
|
|
2235
|
+
if (node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.ExpressionStatement) yield fixer.remove(node);
|
|
2272
2236
|
else yield fixer.replaceText(node, "undefined");
|
|
2273
2237
|
if (lastImportEnd != null) yield fixer.insertTextAfterRange([lastImportEnd, lastImportEnd], "\n" + context.sourceCode.getText(node) + ";");
|
|
2274
2238
|
else yield fixer.insertTextAfterRange([0, 0], context.sourceCode.getText(node) + ";\n");
|
|
@@ -2309,13 +2273,13 @@ var max_expects_default = createEslintRule({
|
|
|
2309
2273
|
type: "object",
|
|
2310
2274
|
properties: { max: { type: "number" } },
|
|
2311
2275
|
additionalProperties: false
|
|
2312
|
-
}]
|
|
2276
|
+
}],
|
|
2277
|
+
defaultOptions: [{ max: 5 }]
|
|
2313
2278
|
},
|
|
2314
|
-
defaultOptions: [{ max: 5 }],
|
|
2315
2279
|
create(context, [{ max }]) {
|
|
2316
2280
|
let assertsCount = 0;
|
|
2317
2281
|
const resetAssertCount = (node) => {
|
|
2318
|
-
if (node.parent?.type !==
|
|
2282
|
+
if (node.parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression || isTypeOfVitestFnCall(node.parent, context, ["test"])) assertsCount = 0;
|
|
2319
2283
|
};
|
|
2320
2284
|
return {
|
|
2321
2285
|
FunctionExpression: resetAssertCount,
|
|
@@ -2324,7 +2288,7 @@ var max_expects_default = createEslintRule({
|
|
|
2324
2288
|
"ArrowFunctionExpression:exit": resetAssertCount,
|
|
2325
2289
|
CallExpression(node) {
|
|
2326
2290
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
2327
|
-
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;
|
|
2328
2292
|
assertsCount += 1;
|
|
2329
2293
|
if (assertsCount > max) context.report({
|
|
2330
2294
|
node,
|
|
@@ -2355,9 +2319,9 @@ var max_nested_describe_default = createEslintRule({
|
|
|
2355
2319
|
properties: { max: { type: "number" } },
|
|
2356
2320
|
additionalProperties: false
|
|
2357
2321
|
}],
|
|
2358
|
-
messages: { maxNestedDescribe: "Nested describe block should be less than set max value" }
|
|
2322
|
+
messages: { maxNestedDescribe: "Nested describe block should be less than set max value" },
|
|
2323
|
+
defaultOptions: [{ max: 5 }]
|
|
2359
2324
|
},
|
|
2360
|
-
defaultOptions: [{ max: 5 }],
|
|
2361
2325
|
create(context, [{ max }]) {
|
|
2362
2326
|
const stack = [];
|
|
2363
2327
|
function pushStack(node) {
|
|
@@ -2399,7 +2363,6 @@ var no_alias_methods_default = createEslintRule({
|
|
|
2399
2363
|
fixable: "code",
|
|
2400
2364
|
schema: []
|
|
2401
2365
|
},
|
|
2402
|
-
defaultOptions: [],
|
|
2403
2366
|
create(context) {
|
|
2404
2367
|
const methodNames = {
|
|
2405
2368
|
toBeCalled: "toHaveBeenCalled",
|
|
@@ -2453,7 +2416,6 @@ var no_commented_out_tests_default = createEslintRule({
|
|
|
2453
2416
|
schema: [],
|
|
2454
2417
|
type: "suggestion"
|
|
2455
2418
|
},
|
|
2456
|
-
defaultOptions: [],
|
|
2457
2419
|
create(context) {
|
|
2458
2420
|
const { sourceCode } = context;
|
|
2459
2421
|
function checkNodeForCommentedOutTests(node) {
|
|
@@ -2472,7 +2434,7 @@ var no_commented_out_tests_default = createEslintRule({
|
|
|
2472
2434
|
//#endregion
|
|
2473
2435
|
//#region src/rules/no-conditional-expect.ts
|
|
2474
2436
|
const RULE_NAME$70 = "no-conditional-expect";
|
|
2475
|
-
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");
|
|
2476
2438
|
var no_conditional_expect_default = createEslintRule({
|
|
2477
2439
|
name: RULE_NAME$70,
|
|
2478
2440
|
meta: {
|
|
@@ -2490,9 +2452,9 @@ var no_conditional_expect_default = createEslintRule({
|
|
|
2490
2452
|
description: "Enable/disable whether expect.assertions() is taken into account",
|
|
2491
2453
|
type: "boolean"
|
|
2492
2454
|
} }
|
|
2493
|
-
}]
|
|
2455
|
+
}],
|
|
2456
|
+
defaultOptions: [{ expectAssertions: false }]
|
|
2494
2457
|
},
|
|
2495
|
-
defaultOptions: [{ expectAssertions: false }],
|
|
2496
2458
|
create(context, [options]) {
|
|
2497
2459
|
let conditionalDepth = 0;
|
|
2498
2460
|
let inTestCase = false;
|
|
@@ -2565,7 +2527,6 @@ var no_conditional_in_test_default = createEslintRule({
|
|
|
2565
2527
|
schema: [],
|
|
2566
2528
|
type: "problem"
|
|
2567
2529
|
},
|
|
2568
|
-
defaultOptions: [],
|
|
2569
2530
|
create(context) {
|
|
2570
2531
|
return { IfStatement(node) {
|
|
2571
2532
|
if (node.parent?.parent?.parent?.type === "CallExpression" && isTypeOfVitestFnCall(node.parent?.parent?.parent, context, ["test", "it"])) context.report({
|
|
@@ -2590,7 +2551,6 @@ var no_conditional_tests_default = createEslintRule({
|
|
|
2590
2551
|
schema: [],
|
|
2591
2552
|
messages: { noConditionalTests: "Avoid using if conditions in a test" }
|
|
2592
2553
|
},
|
|
2593
|
-
defaultOptions: [],
|
|
2594
2554
|
create(context) {
|
|
2595
2555
|
return { Identifier: function(node) {
|
|
2596
2556
|
if ([
|
|
@@ -2628,7 +2588,6 @@ var no_disabled_tests_default = createEslintRule({
|
|
|
2628
2588
|
},
|
|
2629
2589
|
schema: []
|
|
2630
2590
|
},
|
|
2631
|
-
defaultOptions: [],
|
|
2632
2591
|
create(context) {
|
|
2633
2592
|
let suiteDepth = 0;
|
|
2634
2593
|
let testDepth = 0;
|
|
@@ -2702,21 +2661,20 @@ var no_done_callback_default = createEslintRule({
|
|
|
2702
2661
|
},
|
|
2703
2662
|
hasSuggestions: true
|
|
2704
2663
|
},
|
|
2705
|
-
defaultOptions: [],
|
|
2706
2664
|
create(context) {
|
|
2707
2665
|
return { CallExpression(node) {
|
|
2708
2666
|
const isVitestEach = /\.each$|\.for$|\.concurrent$/.test(getNodeName(node.callee) ?? "");
|
|
2709
|
-
if (isVitestEach && node.callee.type !==
|
|
2667
|
+
if (isVitestEach && node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression) return;
|
|
2710
2668
|
if (context.sourceCode.getAncestors(node).some((ancestor) => {
|
|
2711
|
-
if (ancestor.type !==
|
|
2669
|
+
if (ancestor.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return false;
|
|
2712
2670
|
if (!isTypeOfVitestFnCall(ancestor, context, ["describe", "test"])) return false;
|
|
2713
|
-
return ancestor.callee.type ===
|
|
2671
|
+
return ancestor.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(ancestor.callee.property, "concurrent");
|
|
2714
2672
|
})) return;
|
|
2715
2673
|
const callback = findCallbackArg(node, isVitestEach, context);
|
|
2716
2674
|
const callbackArgIndex = Number(isVitestEach);
|
|
2717
2675
|
if (!callback || !isFunction(callback) || callback.params.length !== 1 + callbackArgIndex) return;
|
|
2718
2676
|
const argument = callback.params[callbackArgIndex];
|
|
2719
|
-
if (argument.type !==
|
|
2677
|
+
if (argument.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) {
|
|
2720
2678
|
context.report({
|
|
2721
2679
|
node: argument,
|
|
2722
2680
|
messageId: "noDoneCallback"
|
|
@@ -2752,7 +2710,7 @@ var no_done_callback_default = createEslintRule({
|
|
|
2752
2710
|
let beforeReplacement = `new Promise(${argument.name} => `;
|
|
2753
2711
|
let afterReplacement = ")";
|
|
2754
2712
|
let replaceBefore = true;
|
|
2755
|
-
if (body.type ===
|
|
2713
|
+
if (body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) {
|
|
2756
2714
|
beforeReplacement = `return ${beforeReplacement}{`;
|
|
2757
2715
|
afterReplacement += "}";
|
|
2758
2716
|
replaceBefore = false;
|
|
@@ -2784,7 +2742,6 @@ var no_duplicate_hooks_default = createEslintRule({
|
|
|
2784
2742
|
schema: [],
|
|
2785
2743
|
type: "suggestion"
|
|
2786
2744
|
},
|
|
2787
|
-
defaultOptions: [],
|
|
2788
2745
|
create(context) {
|
|
2789
2746
|
const hooksContexts = [{}];
|
|
2790
2747
|
return {
|
|
@@ -2832,15 +2789,12 @@ var no_focused_tests_default = createEslintRule({
|
|
|
2832
2789
|
fixable: "code",
|
|
2833
2790
|
schema: [{
|
|
2834
2791
|
type: "object",
|
|
2835
|
-
properties: { fixable: {
|
|
2836
|
-
type: "boolean",
|
|
2837
|
-
default: true
|
|
2838
|
-
} },
|
|
2792
|
+
properties: { fixable: { type: "boolean" } },
|
|
2839
2793
|
additionalProperties: false
|
|
2840
2794
|
}],
|
|
2841
|
-
messages: { noFocusedTests: "Focused tests are not allowed" }
|
|
2795
|
+
messages: { noFocusedTests: "Focused tests are not allowed" },
|
|
2796
|
+
defaultOptions: [{ fixable: true }]
|
|
2842
2797
|
},
|
|
2843
|
-
defaultOptions: [{ fixable: true }],
|
|
2844
2798
|
create: (context, options) => {
|
|
2845
2799
|
const fixable = options[0].fixable;
|
|
2846
2800
|
return {
|
|
@@ -2910,9 +2864,9 @@ var no_hooks_default = createEslintRule({
|
|
|
2910
2864
|
} },
|
|
2911
2865
|
additionalProperties: false
|
|
2912
2866
|
}],
|
|
2913
|
-
messages: { unexpectedHook: "Unexpected '{{ hookName }}' hook" }
|
|
2867
|
+
messages: { unexpectedHook: "Unexpected '{{ hookName }}' hook" },
|
|
2868
|
+
defaultOptions: [{ allow: [] }]
|
|
2914
2869
|
},
|
|
2915
|
-
defaultOptions: [{ allow: [] }],
|
|
2916
2870
|
create(context, [{ allow = [] }]) {
|
|
2917
2871
|
return { CallExpression(node) {
|
|
2918
2872
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -2947,7 +2901,6 @@ var no_identical_title_default = createEslintRule({
|
|
|
2947
2901
|
multipleDescribeTitle: "Describe is used multiple times in the same describe(suite) block"
|
|
2948
2902
|
}
|
|
2949
2903
|
},
|
|
2950
|
-
defaultOptions: [],
|
|
2951
2904
|
create(context) {
|
|
2952
2905
|
const stack = [newDescribeContext()];
|
|
2953
2906
|
return {
|
|
@@ -2996,7 +2949,6 @@ var no_import_node_test_default = createEslintRule({
|
|
|
2996
2949
|
fixable: "code",
|
|
2997
2950
|
schema: []
|
|
2998
2951
|
},
|
|
2999
|
-
defaultOptions: [],
|
|
3000
2952
|
create(context) {
|
|
3001
2953
|
return { ImportDeclaration(node) {
|
|
3002
2954
|
if (node.source.value === "node:test") context.report({
|
|
@@ -3036,21 +2988,21 @@ const isVitestImport = (node) => {
|
|
|
3036
2988
|
return node.source.value === "vitest";
|
|
3037
2989
|
};
|
|
3038
2990
|
const isVitestGlobalsImportSpecifier = (specifier) => {
|
|
3039
|
-
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);
|
|
3040
2992
|
};
|
|
3041
2993
|
const isVitestGlobalsProperty = (prop) => {
|
|
3042
|
-
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);
|
|
3043
2995
|
};
|
|
3044
2996
|
const isVitestGlobalsFunction = (node) => {
|
|
3045
|
-
return node.callee.type ===
|
|
2997
|
+
return node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && VITEST_GLOBALS.has(node.callee.name);
|
|
3046
2998
|
};
|
|
3047
2999
|
const isRequireVitestCall = (node) => {
|
|
3048
|
-
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;
|
|
3049
3001
|
const args = node.arguments;
|
|
3050
|
-
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";
|
|
3051
3003
|
};
|
|
3052
3004
|
const isObjectPattern = (node) => {
|
|
3053
|
-
return node.type ===
|
|
3005
|
+
return node.type === _typescript_eslint_utils.AST_NODE_TYPES.ObjectPattern;
|
|
3054
3006
|
};
|
|
3055
3007
|
|
|
3056
3008
|
//#endregion
|
|
@@ -3098,7 +3050,6 @@ var no_importing_vitest_globals_default = createEslintRule({
|
|
|
3098
3050
|
fixable: "code",
|
|
3099
3051
|
schema: []
|
|
3100
3052
|
},
|
|
3101
|
-
defaultOptions: [],
|
|
3102
3053
|
create(context) {
|
|
3103
3054
|
return {
|
|
3104
3055
|
ImportDeclaration(node) {
|
|
@@ -3153,13 +3104,12 @@ var no_interpolation_in_snapshots_default = createEslintRule({
|
|
|
3153
3104
|
schema: [],
|
|
3154
3105
|
messages: { noInterpolationInSnapshots: "Do not use string interpolation in snapshots" }
|
|
3155
3106
|
},
|
|
3156
|
-
defaultOptions: [],
|
|
3157
3107
|
create(context) {
|
|
3158
3108
|
return { CallExpression(node) {
|
|
3159
3109
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
3160
3110
|
if (vitestFnCall?.type !== "expect") return;
|
|
3161
3111
|
if (["toMatchInlineSnapshot", "toThrowErrorMatchingInlineSnapshot"].includes(getAccessorValue(vitestFnCall.matcher))) vitestFnCall.args.forEach((argument) => {
|
|
3162
|
-
if (argument.type ===
|
|
3112
|
+
if (argument.type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral && argument.expressions.length > 0) context.report({
|
|
3163
3113
|
messageId: "noInterpolationInSnapshots",
|
|
3164
3114
|
node: argument
|
|
3165
3115
|
});
|
|
@@ -3176,7 +3126,7 @@ const reportOnViolation = (context, node, { maxSize: lineLimit = 50, allowedSnap
|
|
|
3176
3126
|
const lineCount = node.loc.end.line - startLine;
|
|
3177
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`");
|
|
3178
3128
|
let isAllowed = false;
|
|
3179
|
-
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)) {
|
|
3180
3130
|
const allowedSnapshotsInFile = allowedSnapshots[context.filename];
|
|
3181
3131
|
if (allowedSnapshotsInFile) {
|
|
3182
3132
|
const snapshotName = getAccessorValue(node.expression.left.property);
|
|
@@ -3218,9 +3168,9 @@ var no_large_snapshots_default = createEslintRule({
|
|
|
3218
3168
|
}
|
|
3219
3169
|
},
|
|
3220
3170
|
additionalProperties: false
|
|
3221
|
-
}]
|
|
3171
|
+
}],
|
|
3172
|
+
defaultOptions: [{}]
|
|
3222
3173
|
},
|
|
3223
|
-
defaultOptions: [{}],
|
|
3224
3174
|
create(context, [options]) {
|
|
3225
3175
|
if (context.filename.endsWith(".snap")) return { ExpressionStatement(node) {
|
|
3226
3176
|
reportOnViolation(context, node, options);
|
|
@@ -3253,7 +3203,6 @@ var no_mocks_import_default = createEslintRule({
|
|
|
3253
3203
|
messages: { noMocksImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`vi.mock\` and import from the original module path` },
|
|
3254
3204
|
schema: []
|
|
3255
3205
|
},
|
|
3256
|
-
defaultOptions: [],
|
|
3257
3206
|
create(context) {
|
|
3258
3207
|
return {
|
|
3259
3208
|
ImportDeclaration(node) {
|
|
@@ -3292,18 +3241,17 @@ var no_restricted_matchers_default = createEslintRule({
|
|
|
3292
3241
|
type: "object",
|
|
3293
3242
|
additionalProperties: { type: ["string", "null"] }
|
|
3294
3243
|
}],
|
|
3295
|
-
defaultOptions: [],
|
|
3244
|
+
defaultOptions: [{}],
|
|
3296
3245
|
messages: {
|
|
3297
3246
|
restrictedChain: "use of {{ restriction }} is disallowed",
|
|
3298
3247
|
restrictedChainWithMessage: "{{ message }}"
|
|
3299
3248
|
}
|
|
3300
3249
|
},
|
|
3301
|
-
defaultOptions: [{}],
|
|
3302
3250
|
create(context, [restrictedChains]) {
|
|
3303
3251
|
return { CallExpression(node) {
|
|
3304
3252
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
3305
3253
|
if (vitestFnCall?.type !== "expect") return;
|
|
3306
|
-
const chain = vitestFnCall.members.map((node
|
|
3254
|
+
const chain = vitestFnCall.members.map((node) => getAccessorValue(node)).join(".");
|
|
3307
3255
|
for (const [restriction, message] of Object.entries(restrictedChains)) if (isChainRestricted(chain, restriction)) {
|
|
3308
3256
|
context.report({
|
|
3309
3257
|
messageId: message ? "restrictedChainWithMessage" : "restrictedChain",
|
|
@@ -3340,9 +3288,9 @@ var no_restricted_vi_methods_default = createEslintRule({
|
|
|
3340
3288
|
messages: {
|
|
3341
3289
|
restrictedViMethod: "Use of `{{ restriction }}` is disallowed",
|
|
3342
3290
|
restrictedViMethodWithMessage: "{{ message }}"
|
|
3343
|
-
}
|
|
3291
|
+
},
|
|
3292
|
+
defaultOptions: [{}]
|
|
3344
3293
|
},
|
|
3345
|
-
defaultOptions: [{}],
|
|
3346
3294
|
create(context, [restrictedMethods]) {
|
|
3347
3295
|
return { CallExpression(node) {
|
|
3348
3296
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -3372,11 +3320,11 @@ const RULE_NAME$54 = "no-standalone-expect";
|
|
|
3372
3320
|
const getBlockType = (statement, context) => {
|
|
3373
3321
|
const func = statement.parent;
|
|
3374
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");
|
|
3375
|
-
if (func.type ===
|
|
3323
|
+
if (func.type === _typescript_eslint_utils.AST_NODE_TYPES.FunctionDeclaration) return "function";
|
|
3376
3324
|
if (isFunction(func) && func.parent) {
|
|
3377
3325
|
const expr = func.parent;
|
|
3378
|
-
if (expr.type ===
|
|
3379
|
-
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";
|
|
3380
3328
|
}
|
|
3381
3329
|
return null;
|
|
3382
3330
|
};
|
|
@@ -3397,9 +3345,8 @@ var no_standalone_expect_default = createEslintRule({
|
|
|
3397
3345
|
} },
|
|
3398
3346
|
additionalProperties: false
|
|
3399
3347
|
}],
|
|
3400
|
-
defaultOptions: []
|
|
3348
|
+
defaultOptions: [{ additionalTestBlockFunctions: [] }]
|
|
3401
3349
|
},
|
|
3402
|
-
defaultOptions: [{ additionalTestBlockFunctions: [] }],
|
|
3403
3350
|
create(context, [{ additionalTestBlockFunctions = [] }]) {
|
|
3404
3351
|
const callStack = [];
|
|
3405
3352
|
const isCustomTestBlockFunction = (node) => additionalTestBlockFunctions.includes(getNodeName(node) || "");
|
|
@@ -3407,7 +3354,7 @@ var no_standalone_expect_default = createEslintRule({
|
|
|
3407
3354
|
CallExpression(node) {
|
|
3408
3355
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
3409
3356
|
if (vitestFnCall?.type === "expect") {
|
|
3410
|
-
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;
|
|
3411
3358
|
const parent = callStack[callStack.length - 1];
|
|
3412
3359
|
if (!parent || parent === DescribeAlias.describe) context.report({
|
|
3413
3360
|
node,
|
|
@@ -3416,11 +3363,11 @@ var no_standalone_expect_default = createEslintRule({
|
|
|
3416
3363
|
return;
|
|
3417
3364
|
}
|
|
3418
3365
|
if (vitestFnCall?.type === "test" || isCustomTestBlockFunction(node)) callStack.push("test");
|
|
3419
|
-
if (node.callee.type ===
|
|
3366
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression) callStack.push("template");
|
|
3420
3367
|
},
|
|
3421
3368
|
"CallExpression:exit"(node) {
|
|
3422
3369
|
const top = callStack[callStack.length - 1];
|
|
3423
|
-
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();
|
|
3424
3371
|
},
|
|
3425
3372
|
BlockStatement(statement) {
|
|
3426
3373
|
const blockType = getBlockType(statement, context);
|
|
@@ -3430,7 +3377,7 @@ var no_standalone_expect_default = createEslintRule({
|
|
|
3430
3377
|
if (getBlockType(statement, context)) callStack.pop();
|
|
3431
3378
|
},
|
|
3432
3379
|
ArrowFunctionExpression(node) {
|
|
3433
|
-
if (node.parent?.type !==
|
|
3380
|
+
if (node.parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) callStack.push("arrow");
|
|
3434
3381
|
},
|
|
3435
3382
|
"ArrowFunctionExpression:exit"() {
|
|
3436
3383
|
if (callStack[callStack.length - 1] === "arrow") callStack.pop();
|
|
@@ -3454,7 +3401,6 @@ var no_test_prefixes_default = createEslintRule({
|
|
|
3454
3401
|
fixable: "code",
|
|
3455
3402
|
schema: []
|
|
3456
3403
|
},
|
|
3457
|
-
defaultOptions: [],
|
|
3458
3404
|
create(context) {
|
|
3459
3405
|
return { CallExpression(node) {
|
|
3460
3406
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -3465,7 +3411,7 @@ var no_test_prefixes_default = createEslintRule({
|
|
|
3465
3411
|
vitestFnCall.name[0] === "f" ? "only" : "skip",
|
|
3466
3412
|
...vitestFnCall.members.map((m) => getAccessorValue(m))
|
|
3467
3413
|
].join(".");
|
|
3468
|
-
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;
|
|
3469
3415
|
context.report({
|
|
3470
3416
|
messageId: "usePreferredName",
|
|
3471
3417
|
node: node.callee,
|
|
@@ -3481,7 +3427,7 @@ var no_test_prefixes_default = createEslintRule({
|
|
|
3481
3427
|
const RULE_NAME$52 = "no-test-return-statement";
|
|
3482
3428
|
const getBody = (args) => {
|
|
3483
3429
|
const [, secondArg] = args;
|
|
3484
|
-
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;
|
|
3485
3431
|
return [];
|
|
3486
3432
|
};
|
|
3487
3433
|
var no_test_return_statement_default = createEslintRule({
|
|
@@ -3495,12 +3441,11 @@ var no_test_return_statement_default = createEslintRule({
|
|
|
3495
3441
|
schema: [],
|
|
3496
3442
|
messages: { noTestReturnStatement: "Return statements are not allowed in tests" }
|
|
3497
3443
|
},
|
|
3498
|
-
defaultOptions: [],
|
|
3499
3444
|
create(context) {
|
|
3500
3445
|
return {
|
|
3501
3446
|
CallExpression(node) {
|
|
3502
3447
|
if (!isTypeOfVitestFnCall(node, context, ["test"])) return;
|
|
3503
|
-
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);
|
|
3504
3449
|
if (!returnStmt) return;
|
|
3505
3450
|
context.report({
|
|
3506
3451
|
messageId: "noTestReturnStatement",
|
|
@@ -3509,7 +3454,7 @@ var no_test_return_statement_default = createEslintRule({
|
|
|
3509
3454
|
},
|
|
3510
3455
|
FunctionDeclaration(node) {
|
|
3511
3456
|
if (getTestCallExpressionsFromDeclaredVariables(context.sourceCode.getDeclaredVariables(node), context).length === 0) return;
|
|
3512
|
-
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);
|
|
3513
3458
|
if (!returnStmt) return;
|
|
3514
3459
|
context.report({
|
|
3515
3460
|
messageId: "noTestReturnStatement",
|
|
@@ -3525,15 +3470,15 @@ var no_test_return_statement_default = createEslintRule({
|
|
|
3525
3470
|
const eslintRequire = (0, node_module.createRequire)((0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve("eslint"));
|
|
3526
3471
|
const espreeParser = eslintRequire.resolve("espree");
|
|
3527
3472
|
const STATEMENT_LIST_PARENTS = new Set([
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
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
|
|
3532
3477
|
]);
|
|
3533
3478
|
const isValidParent = (parentType) => {
|
|
3534
3479
|
return STATEMENT_LIST_PARENTS.has(parentType);
|
|
3535
3480
|
};
|
|
3536
|
-
const isTokenASemicolon = (token) => token.value === ";" && token.type ===
|
|
3481
|
+
const isTokenASemicolon = (token) => token.value === ";" && token.type === _typescript_eslint_utils.AST_TOKEN_TYPES.Punctuator;
|
|
3537
3482
|
/**
|
|
3538
3483
|
* Gets the actual last token.
|
|
3539
3484
|
*
|
|
@@ -3561,33 +3506,33 @@ const getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
|
|
|
3561
3506
|
return pairs;
|
|
3562
3507
|
};
|
|
3563
3508
|
const areTokensOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
|
|
3564
|
-
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;
|
|
3565
3510
|
const followTypeAssertionChain = (expression) => isTypeCastExpression(expression) ? followTypeAssertionChain(expression.expression) : expression;
|
|
3566
3511
|
|
|
3567
3512
|
//#endregion
|
|
3568
3513
|
//#region src/utils/padding.ts
|
|
3569
|
-
let PaddingType = /* @__PURE__ */ function(PaddingType
|
|
3570
|
-
PaddingType
|
|
3571
|
-
PaddingType
|
|
3572
|
-
return PaddingType
|
|
3514
|
+
let PaddingType = /* @__PURE__ */ function(PaddingType) {
|
|
3515
|
+
PaddingType[PaddingType["Any"] = 0] = "Any";
|
|
3516
|
+
PaddingType[PaddingType["Always"] = 1] = "Always";
|
|
3517
|
+
return PaddingType;
|
|
3573
3518
|
}({});
|
|
3574
|
-
let StatementType = /* @__PURE__ */ function(StatementType
|
|
3575
|
-
StatementType
|
|
3576
|
-
StatementType
|
|
3577
|
-
StatementType
|
|
3578
|
-
StatementType
|
|
3579
|
-
StatementType
|
|
3580
|
-
StatementType
|
|
3581
|
-
StatementType
|
|
3582
|
-
StatementType
|
|
3583
|
-
StatementType
|
|
3584
|
-
StatementType
|
|
3585
|
-
StatementType
|
|
3586
|
-
StatementType
|
|
3587
|
-
StatementType
|
|
3588
|
-
StatementType
|
|
3589
|
-
StatementType
|
|
3590
|
-
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;
|
|
3591
3536
|
}({});
|
|
3592
3537
|
const paddingAlwaysTester = (prevNode, nextNode, paddingContext) => {
|
|
3593
3538
|
const { sourceCode, ruleContext } = paddingContext;
|
|
@@ -3639,10 +3584,10 @@ const createScopeInfo = () => {
|
|
|
3639
3584
|
const createTokenTester = (tokenName) => {
|
|
3640
3585
|
return (node, sourceCode) => {
|
|
3641
3586
|
let activeNode = node;
|
|
3642
|
-
if (activeNode.type ===
|
|
3643
|
-
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;
|
|
3644
3589
|
const token = sourceCode.getFirstToken(activeNode);
|
|
3645
|
-
return token?.type ===
|
|
3590
|
+
return token?.type === _typescript_eslint_utils.AST_TOKEN_TYPES.Identifier && token.value === tokenName;
|
|
3646
3591
|
}
|
|
3647
3592
|
return false;
|
|
3648
3593
|
};
|
|
@@ -3670,7 +3615,7 @@ const statementTesters = {
|
|
|
3670
3615
|
const nodeMatchesType = (node, statementType, paddingContext) => {
|
|
3671
3616
|
let innerStatementNode = node;
|
|
3672
3617
|
const { sourceCode } = paddingContext;
|
|
3673
|
-
while (innerStatementNode.type ===
|
|
3618
|
+
while (innerStatementNode.type === _typescript_eslint_utils.AST_NODE_TYPES.LabeledStatement) innerStatementNode = innerStatementNode.body;
|
|
3674
3619
|
if (Array.isArray(statementType)) return statementType.some((type) => nodeMatchesType(innerStatementNode, type, paddingContext));
|
|
3675
3620
|
return statementTesters[statementType](innerStatementNode, sourceCode);
|
|
3676
3621
|
};
|
|
@@ -3725,9 +3670,9 @@ const createPaddingRule = (name, description, configs, deprecated = false) => {
|
|
|
3725
3670
|
deprecated,
|
|
3726
3671
|
messages: { missingPadding: "expect blank line before this statement" },
|
|
3727
3672
|
schema: [],
|
|
3728
|
-
type: "suggestion"
|
|
3673
|
+
type: "suggestion",
|
|
3674
|
+
defaultOptions: []
|
|
3729
3675
|
},
|
|
3730
|
-
defaultOptions: [],
|
|
3731
3676
|
create(context) {
|
|
3732
3677
|
const paddingContext = {
|
|
3733
3678
|
ruleContext: context,
|
|
@@ -3757,7 +3702,7 @@ const createPaddingRule = (name, description, configs, deprecated = false) => {
|
|
|
3757
3702
|
//#endregion
|
|
3758
3703
|
//#region src/rules/padding-around-after-all-blocks.ts
|
|
3759
3704
|
const RULE_NAME$51 = "padding-around-after-all-blocks";
|
|
3760
|
-
const config = [{
|
|
3705
|
+
const config$6 = [{
|
|
3761
3706
|
paddingType: PaddingType.Always,
|
|
3762
3707
|
prevStatementType: StatementType.Any,
|
|
3763
3708
|
nextStatementType: StatementType.AfterAllToken
|
|
@@ -3766,12 +3711,12 @@ const config = [{
|
|
|
3766
3711
|
prevStatementType: StatementType.AfterAllToken,
|
|
3767
3712
|
nextStatementType: StatementType.Any
|
|
3768
3713
|
}];
|
|
3769
|
-
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);
|
|
3770
3715
|
|
|
3771
3716
|
//#endregion
|
|
3772
3717
|
//#region src/rules/padding-around-after-each-blocks.ts
|
|
3773
3718
|
const RULE_NAME$50 = "padding-around-after-each-blocks";
|
|
3774
|
-
const config$
|
|
3719
|
+
const config$5 = [{
|
|
3775
3720
|
paddingType: PaddingType.Always,
|
|
3776
3721
|
prevStatementType: StatementType.Any,
|
|
3777
3722
|
nextStatementType: StatementType.AfterEachToken
|
|
@@ -3780,12 +3725,12 @@ const config$1 = [{
|
|
|
3780
3725
|
prevStatementType: StatementType.AfterEachToken,
|
|
3781
3726
|
nextStatementType: StatementType.Any
|
|
3782
3727
|
}];
|
|
3783
|
-
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);
|
|
3784
3729
|
|
|
3785
3730
|
//#endregion
|
|
3786
3731
|
//#region src/rules/padding-around-before-all-blocks.ts
|
|
3787
3732
|
const RULE_NAME$49 = "padding-around-before-all-blocks";
|
|
3788
|
-
const config$
|
|
3733
|
+
const config$4 = [{
|
|
3789
3734
|
paddingType: PaddingType.Always,
|
|
3790
3735
|
prevStatementType: StatementType.Any,
|
|
3791
3736
|
nextStatementType: StatementType.BeforeAllToken
|
|
@@ -3794,7 +3739,7 @@ const config$2 = [{
|
|
|
3794
3739
|
prevStatementType: StatementType.BeforeAllToken,
|
|
3795
3740
|
nextStatementType: StatementType.Any
|
|
3796
3741
|
}];
|
|
3797
|
-
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);
|
|
3798
3743
|
|
|
3799
3744
|
//#endregion
|
|
3800
3745
|
//#region src/rules/padding-around-before-each-blocks.ts
|
|
@@ -3813,7 +3758,7 @@ var padding_around_before_each_blocks_default = createPaddingRule(RULE_NAME$48,
|
|
|
3813
3758
|
//#endregion
|
|
3814
3759
|
//#region src/rules/padding-around-describe-blocks.ts
|
|
3815
3760
|
const RULE_NAME$47 = "padding-around-describe-blocks";
|
|
3816
|
-
const config$
|
|
3761
|
+
const config$2 = [{
|
|
3817
3762
|
paddingType: PaddingType.Always,
|
|
3818
3763
|
prevStatementType: StatementType.Any,
|
|
3819
3764
|
nextStatementType: [
|
|
@@ -3830,12 +3775,12 @@ const config$4 = [{
|
|
|
3830
3775
|
],
|
|
3831
3776
|
nextStatementType: StatementType.Any
|
|
3832
3777
|
}];
|
|
3833
|
-
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);
|
|
3834
3779
|
|
|
3835
3780
|
//#endregion
|
|
3836
3781
|
//#region src/rules/padding-around-expect-groups.ts
|
|
3837
3782
|
const RULE_NAME$46 = "padding-around-expect-groups";
|
|
3838
|
-
const config$
|
|
3783
|
+
const config$1 = [
|
|
3839
3784
|
{
|
|
3840
3785
|
paddingType: PaddingType.Always,
|
|
3841
3786
|
prevStatementType: StatementType.Any,
|
|
@@ -3867,12 +3812,12 @@ const config$5 = [
|
|
|
3867
3812
|
nextStatementType: StatementType.ExpectTypeOfToken
|
|
3868
3813
|
}
|
|
3869
3814
|
];
|
|
3870
|
-
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);
|
|
3871
3816
|
|
|
3872
3817
|
//#endregion
|
|
3873
3818
|
//#region src/rules/padding-around-test-blocks.ts
|
|
3874
3819
|
const RULE_NAME$45 = "padding-around-test-blocks";
|
|
3875
|
-
const config
|
|
3820
|
+
const config = [{
|
|
3876
3821
|
paddingType: PaddingType.Always,
|
|
3877
3822
|
prevStatementType: StatementType.Any,
|
|
3878
3823
|
nextStatementType: [
|
|
@@ -3893,19 +3838,19 @@ const config$6 = [{
|
|
|
3893
3838
|
],
|
|
3894
3839
|
nextStatementType: StatementType.Any
|
|
3895
3840
|
}];
|
|
3896
|
-
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);
|
|
3897
3842
|
|
|
3898
3843
|
//#endregion
|
|
3899
3844
|
//#region src/rules/padding-around-all.ts
|
|
3900
3845
|
const RULE_NAME$44 = "padding-around-all";
|
|
3901
3846
|
var padding_around_all_default = createPaddingRule(RULE_NAME$44, "Enforce padding around vitest functions", [
|
|
3902
|
-
...config,
|
|
3903
|
-
...config$1,
|
|
3904
|
-
...config$2,
|
|
3905
|
-
...config$3,
|
|
3906
|
-
...config$4,
|
|
3847
|
+
...config$6,
|
|
3907
3848
|
...config$5,
|
|
3908
|
-
...config$
|
|
3849
|
+
...config$4,
|
|
3850
|
+
...config$3,
|
|
3851
|
+
...config$2,
|
|
3852
|
+
...config$1,
|
|
3853
|
+
...config
|
|
3909
3854
|
]);
|
|
3910
3855
|
|
|
3911
3856
|
//#endregion
|
|
@@ -3919,7 +3864,7 @@ const MOCK_CALL_RESET_METHODS = [
|
|
|
3919
3864
|
];
|
|
3920
3865
|
const hasMatchersToCombine = (target) => MATCHERS_TO_COMBINE.some((matcher) => matcher === target);
|
|
3921
3866
|
const getExpectText = (callee, source) => {
|
|
3922
|
-
if (callee.type !==
|
|
3867
|
+
if (callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
|
|
3923
3868
|
return source.getText(callee.object);
|
|
3924
3869
|
};
|
|
3925
3870
|
const getArgumentsText = (callExpression, source) => callExpression.arguments.map((arg) => source.getText(arg)).join(", ");
|
|
@@ -3933,11 +3878,11 @@ const getMatcherName = (vitestFnCall) => {
|
|
|
3933
3878
|
return validExpectCall ? getAccessorValue(validExpectCall.matcher) : null;
|
|
3934
3879
|
};
|
|
3935
3880
|
const getExpectArgText = ({ callee }) => {
|
|
3936
|
-
if (callee.type !==
|
|
3881
|
+
if (callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return null;
|
|
3937
3882
|
const { object } = callee;
|
|
3938
|
-
if (object.type !==
|
|
3883
|
+
if (object.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return null;
|
|
3939
3884
|
const [firstArgument] = object.arguments;
|
|
3940
|
-
if (firstArgument.type !==
|
|
3885
|
+
if (firstArgument.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return null;
|
|
3941
3886
|
return firstArgument.name;
|
|
3942
3887
|
};
|
|
3943
3888
|
const getSharedExpectArgText = (firstCallExpression, secondCallExpression) => {
|
|
@@ -3947,16 +3892,16 @@ const getSharedExpectArgText = (firstCallExpression, secondCallExpression) => {
|
|
|
3947
3892
|
return firstArgText;
|
|
3948
3893
|
};
|
|
3949
3894
|
const isTargetMockResetCall = (statement, expectArgText, minLine, maxLine) => {
|
|
3950
|
-
if (statement.type !==
|
|
3951
|
-
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;
|
|
3952
3897
|
const statementLine = statement.loc.start.line;
|
|
3953
3898
|
if (statementLine <= minLine || statementLine >= maxLine) return false;
|
|
3954
3899
|
const { callee } = statement.expression;
|
|
3955
|
-
if (callee.type !==
|
|
3900
|
+
if (callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return false;
|
|
3956
3901
|
const { object, property } = callee;
|
|
3957
|
-
if (object.type !==
|
|
3902
|
+
if (object.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return false;
|
|
3958
3903
|
if (object.name !== expectArgText) return false;
|
|
3959
|
-
if (property.type !==
|
|
3904
|
+
if (property.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return false;
|
|
3960
3905
|
return MOCK_CALL_RESET_METHODS.some((method) => method === property.name);
|
|
3961
3906
|
};
|
|
3962
3907
|
const hasMockResetBetween = (body, firstCallExpression, secondCallExpression) => {
|
|
@@ -3967,7 +3912,7 @@ const hasMockResetBetween = (body, firstCallExpression, secondCallExpression) =>
|
|
|
3967
3912
|
if (!expectArgText) return false;
|
|
3968
3913
|
return body.some((statement) => isTargetMockResetCall(statement, expectArgText, minLine, maxLine));
|
|
3969
3914
|
};
|
|
3970
|
-
const getMemberProperty = (expression) => expression.callee.type ===
|
|
3915
|
+
const getMemberProperty = (expression) => expression.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression ? expression.callee.property : null;
|
|
3971
3916
|
var prefer_called_exactly_once_with_default = createEslintRule({
|
|
3972
3917
|
name: RULE_NAME$43,
|
|
3973
3918
|
meta: {
|
|
@@ -3977,10 +3922,9 @@ var prefer_called_exactly_once_with_default = createEslintRule({
|
|
|
3977
3922
|
fixable: "code",
|
|
3978
3923
|
schema: []
|
|
3979
3924
|
},
|
|
3980
|
-
defaultOptions: [],
|
|
3981
3925
|
create(context) {
|
|
3982
3926
|
const { sourceCode } = context;
|
|
3983
|
-
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 : []);
|
|
3984
3928
|
const checkBlockBody = (body) => {
|
|
3985
3929
|
const callExpressions = getCallExpressions(body);
|
|
3986
3930
|
const expectMatcherMap = /* @__PURE__ */ new Map();
|
|
@@ -4038,7 +3982,7 @@ var prefer_called_exactly_once_with_default = createEslintRule({
|
|
|
4038
3982
|
//#endregion
|
|
4039
3983
|
//#region src/rules/prefer-called-once.ts
|
|
4040
3984
|
const RULE_NAME$42 = "prefer-called-once";
|
|
4041
|
-
const isOneLiteral = (node) => node.type ===
|
|
3985
|
+
const isOneLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === 1;
|
|
4042
3986
|
var prefer_called_once_default = createEslintRule({
|
|
4043
3987
|
name: RULE_NAME$42,
|
|
4044
3988
|
meta: {
|
|
@@ -4051,7 +3995,6 @@ var prefer_called_once_default = createEslintRule({
|
|
|
4051
3995
|
fixable: "code",
|
|
4052
3996
|
schema: []
|
|
4053
3997
|
},
|
|
4054
|
-
defaultOptions: [],
|
|
4055
3998
|
create(context) {
|
|
4056
3999
|
return { CallExpression(node) {
|
|
4057
4000
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -4086,7 +4029,6 @@ var prefer_called_times_default = createEslintRule({
|
|
|
4086
4029
|
fixable: "code",
|
|
4087
4030
|
schema: []
|
|
4088
4031
|
},
|
|
4089
|
-
defaultOptions: [],
|
|
4090
4032
|
create(context) {
|
|
4091
4033
|
return { CallExpression(node) {
|
|
4092
4034
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -4121,12 +4063,11 @@ var prefer_called_with_default = createEslintRule({
|
|
|
4121
4063
|
fixable: "code",
|
|
4122
4064
|
schema: []
|
|
4123
4065
|
},
|
|
4124
|
-
defaultOptions: [],
|
|
4125
4066
|
create(context) {
|
|
4126
4067
|
return { CallExpression(node) {
|
|
4127
4068
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4128
4069
|
if (vitestFnCall?.type !== "expect") return;
|
|
4129
|
-
if (vitestFnCall.modifiers.some((node
|
|
4070
|
+
if (vitestFnCall.modifiers.some((node) => getAccessorValue(node) === "not")) return;
|
|
4130
4071
|
const { matcher } = vitestFnCall;
|
|
4131
4072
|
const matcherName = getAccessorValue(matcher);
|
|
4132
4073
|
if (["toBeCalled", "toHaveBeenCalled"].includes(matcherName)) context.report({
|
|
@@ -4141,7 +4082,7 @@ var prefer_called_with_default = createEslintRule({
|
|
|
4141
4082
|
|
|
4142
4083
|
//#endregion
|
|
4143
4084
|
//#region src/utils/msc.ts
|
|
4144
|
-
const isBooleanLiteral = (node) => node.type ===
|
|
4085
|
+
const isBooleanLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof node.value === "boolean";
|
|
4145
4086
|
/**
|
|
4146
4087
|
* Checks if the given `ParsedExpectMatcher` is either a call to one of the equality matchers,
|
|
4147
4088
|
* with a boolean` literal as the sole argument, *or* is a call to `toBeTruthy` or `toBeFalsy`.
|
|
@@ -4153,14 +4094,14 @@ const isBooleanEqualityMatcher = (expectFnCall) => {
|
|
|
4153
4094
|
const arg = getFirstMatcherArg(expectFnCall);
|
|
4154
4095
|
return Object.prototype.hasOwnProperty.call(EqualityMatcher, matcherName) && isBooleanLiteral(arg);
|
|
4155
4096
|
};
|
|
4156
|
-
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);
|
|
4157
4098
|
const hasOnlyOneArgument = (call) => call.arguments.length === 1;
|
|
4158
4099
|
|
|
4159
4100
|
//#endregion
|
|
4160
4101
|
//#region src/rules/prefer-comparison-matcher.ts
|
|
4161
4102
|
const RULE_NAME$39 = "prefer-comparison-matcher";
|
|
4162
4103
|
const isString = (node) => {
|
|
4163
|
-
return isStringNode(node) || node?.type ===
|
|
4104
|
+
return isStringNode(node) || node?.type === _typescript_eslint_utils.AST_NODE_TYPES.TemplateLiteral;
|
|
4164
4105
|
};
|
|
4165
4106
|
const isComparingToString = (expression) => {
|
|
4166
4107
|
return isString(expression.left) || isString(expression.right);
|
|
@@ -4195,17 +4136,16 @@ var prefer_comparison_matcher_default = createEslintRule({
|
|
|
4195
4136
|
fixable: "code",
|
|
4196
4137
|
messages: { useToBeComparison: "Prefer using `{{ preferredMatcher }}` instead" }
|
|
4197
4138
|
},
|
|
4198
|
-
defaultOptions: [],
|
|
4199
4139
|
create(context) {
|
|
4200
4140
|
return { CallExpression(node) {
|
|
4201
4141
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4202
4142
|
if (vitestFnCall?.type !== "expect" || vitestFnCall.args.length === 0) return;
|
|
4203
4143
|
const { parent: expect } = vitestFnCall.head.node;
|
|
4204
|
-
if (expect?.type !==
|
|
4144
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4205
4145
|
const { arguments: [comparison], range: [, expectCallEnd] } = expect;
|
|
4206
4146
|
const { matcher } = vitestFnCall;
|
|
4207
4147
|
const matcherArg = getFirstMatcherArg(vitestFnCall);
|
|
4208
|
-
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;
|
|
4209
4149
|
const [modifier] = vitestFnCall.modifiers;
|
|
4210
4150
|
const hasNot = vitestFnCall.modifiers.some((nod) => getAccessorValue(nod) === "not");
|
|
4211
4151
|
const preferredMatcher = determineMatcher(comparison.operator, matcherArg.value === hasNot);
|
|
@@ -4243,15 +4183,14 @@ var prefer_describe_function_title_default = createEslintRule({
|
|
|
4243
4183
|
schema: [],
|
|
4244
4184
|
messages: { preferFunction: "Enforce using a function over an equivalent string" }
|
|
4245
4185
|
},
|
|
4246
|
-
defaultOptions: [],
|
|
4247
4186
|
create(context) {
|
|
4248
4187
|
return { CallExpression(node) {
|
|
4249
4188
|
if (node.arguments.length < 2) return;
|
|
4250
4189
|
const scope = getModuleScope(context, node);
|
|
4251
4190
|
const [argument] = node.arguments;
|
|
4252
|
-
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) {
|
|
4253
4192
|
const identifierName = argument.object.name;
|
|
4254
|
-
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;
|
|
4255
4194
|
context.report({
|
|
4256
4195
|
node: argument,
|
|
4257
4196
|
messageId: "preferFunction",
|
|
@@ -4261,13 +4200,13 @@ var prefer_describe_function_title_default = createEslintRule({
|
|
|
4261
4200
|
});
|
|
4262
4201
|
return;
|
|
4263
4202
|
}
|
|
4264
|
-
if (argument.type !==
|
|
4203
|
+
if (argument.type !== _typescript_eslint_utils.AST_NODE_TYPES.Literal || typeof argument.value !== "string") return;
|
|
4265
4204
|
const describedTitle = argument.value;
|
|
4266
4205
|
if (parseVitestFnCall(node, context)?.type !== "describe") return;
|
|
4267
4206
|
const scopedFunction = scope?.set.get(describedTitle)?.defs[0];
|
|
4268
|
-
if (scopedFunction?.type !==
|
|
4207
|
+
if (scopedFunction?.type !== _typescript_eslint_scope_manager.DefinitionType.ImportBinding) return;
|
|
4269
4208
|
if (parsePluginSettings(context.settings).typecheck) {
|
|
4270
|
-
if (!isClassOrFunctionType(
|
|
4209
|
+
if (!isClassOrFunctionType(_typescript_eslint_utils.ESLintUtils.getParserServices(context).getTypeAtLocation(scopedFunction.node))) return;
|
|
4271
4210
|
}
|
|
4272
4211
|
context.report({
|
|
4273
4212
|
node: argument,
|
|
@@ -4294,7 +4233,6 @@ var prefer_each_default = createEslintRule({
|
|
|
4294
4233
|
schema: [],
|
|
4295
4234
|
messages: { preferEach: "Prefer using `{{ fn }}.each` rather than a manual loop" }
|
|
4296
4235
|
},
|
|
4297
|
-
defaultOptions: [],
|
|
4298
4236
|
create(context) {
|
|
4299
4237
|
const vitestFnCalls = [];
|
|
4300
4238
|
let inTestCaseCall = false;
|
|
@@ -4353,22 +4291,21 @@ var prefer_equality_matcher_default = createEslintRule({
|
|
|
4353
4291
|
hasSuggestions: true,
|
|
4354
4292
|
schema: []
|
|
4355
4293
|
},
|
|
4356
|
-
defaultOptions: [],
|
|
4357
4294
|
create(context) {
|
|
4358
4295
|
return { CallExpression(node) {
|
|
4359
4296
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4360
4297
|
if (vitestFnCall?.type !== "expect" || vitestFnCall.args.length === 0) return;
|
|
4361
4298
|
const { parent: expect } = vitestFnCall.head.node;
|
|
4362
|
-
if (expect?.type !==
|
|
4299
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4363
4300
|
const { arguments: [comparison], range: [, expectCallEnd] } = expect;
|
|
4364
4301
|
const { matcher } = vitestFnCall;
|
|
4365
4302
|
const matcherArg = getFirstMatcherArg(vitestFnCall);
|
|
4366
|
-
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;
|
|
4367
4304
|
const matcherValue = matcherArg.value;
|
|
4368
4305
|
const [modifier] = vitestFnCall.modifiers;
|
|
4369
4306
|
const hasNot = vitestFnCall.modifiers.some((nod) => getAccessorValue(nod) === "not");
|
|
4370
4307
|
const addNotModifier = (comparison.operator === "!==" ? !matcherValue : matcherValue) === hasNot;
|
|
4371
|
-
const buildFixer
|
|
4308
|
+
const buildFixer = (equalityMatcher) => (fixer) => {
|
|
4372
4309
|
const { sourceCode } = context;
|
|
4373
4310
|
let modifierText = modifier && getAccessorValue(modifier) !== "not" ? `.${getAccessorValue(modifier)}` : "";
|
|
4374
4311
|
if (addNotModifier) modifierText += `.${ModifierName.not}`;
|
|
@@ -4387,7 +4324,7 @@ var prefer_equality_matcher_default = createEslintRule({
|
|
|
4387
4324
|
].map((equalityMatcher) => ({
|
|
4388
4325
|
messageId: "suggestEqualityMatcher",
|
|
4389
4326
|
data: { equalityMatcher },
|
|
4390
|
-
fix: buildFixer
|
|
4327
|
+
fix: buildFixer(equalityMatcher)
|
|
4391
4328
|
})),
|
|
4392
4329
|
node: matcher
|
|
4393
4330
|
});
|
|
@@ -4401,8 +4338,8 @@ const RULE_NAME$35 = "prefer-expect-assertions";
|
|
|
4401
4338
|
const isFirstStatement = (node) => {
|
|
4402
4339
|
let parent = node;
|
|
4403
4340
|
while (parent) {
|
|
4404
|
-
if (parent.parent?.type ===
|
|
4405
|
-
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;
|
|
4406
4343
|
parent = parent.parent;
|
|
4407
4344
|
}
|
|
4408
4345
|
throw new Error("Could not find parent block statement");
|
|
@@ -4438,13 +4375,12 @@ var prefer_expect_assertions_default = createEslintRule({
|
|
|
4438
4375
|
},
|
|
4439
4376
|
additionalProperties: false
|
|
4440
4377
|
}],
|
|
4441
|
-
defaultOptions: [
|
|
4378
|
+
defaultOptions: [{
|
|
4379
|
+
onlyFunctionsWithAsyncKeyword: false,
|
|
4380
|
+
onlyFunctionsWithExpectInCallback: false,
|
|
4381
|
+
onlyFunctionsWithExpectInLoop: false
|
|
4382
|
+
}]
|
|
4442
4383
|
},
|
|
4443
|
-
defaultOptions: [{
|
|
4444
|
-
onlyFunctionsWithAsyncKeyword: false,
|
|
4445
|
-
onlyFunctionsWithExpectInCallback: false,
|
|
4446
|
-
onlyFunctionsWithExpectInLoop: false
|
|
4447
|
-
}],
|
|
4448
4384
|
create(context, [options]) {
|
|
4449
4385
|
let expressionDepth = 0;
|
|
4450
4386
|
let hasExpectInCallBack = false;
|
|
@@ -4490,7 +4426,7 @@ var prefer_expect_assertions_default = createEslintRule({
|
|
|
4490
4426
|
return;
|
|
4491
4427
|
}
|
|
4492
4428
|
const [arg] = expectFnCall.args;
|
|
4493
|
-
if (arg.type ===
|
|
4429
|
+
if (arg.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof arg.value === "number" && Number.isInteger(arg.value)) return;
|
|
4494
4430
|
context.report({
|
|
4495
4431
|
messageId: "assertionsRequiresNumberArgument",
|
|
4496
4432
|
node: arg
|
|
@@ -4517,9 +4453,9 @@ var prefer_expect_assertions_default = createEslintRule({
|
|
|
4517
4453
|
inTestCaseCall = true;
|
|
4518
4454
|
return;
|
|
4519
4455
|
}
|
|
4520
|
-
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}`;
|
|
4521
4457
|
if (vitestFnCall?.type === "expect" && inTestCaseCall) {
|
|
4522
|
-
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]))) {
|
|
4523
4459
|
checkExpectHasAssertions(vitestFnCall, node);
|
|
4524
4460
|
hasExpectAssertAsFirstStatement = true;
|
|
4525
4461
|
}
|
|
@@ -4540,7 +4476,7 @@ var prefer_expect_assertions_default = createEslintRule({
|
|
|
4540
4476
|
return;
|
|
4541
4477
|
}
|
|
4542
4478
|
const suggestions = [];
|
|
4543
|
-
if (secondArg.body.type ===
|
|
4479
|
+
if (secondArg.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) {
|
|
4544
4480
|
const prefix = testContextName ? `${testContextName}.` : "";
|
|
4545
4481
|
suggestions.push(["suggestAddingHasAssertions", `${prefix}expect.hasAssertions();`], ["suggestAddingAssertions", `${prefix}expect.assertions();`]);
|
|
4546
4482
|
}
|
|
@@ -4572,14 +4508,13 @@ var prefer_expect_resolves_default = createEslintRule({
|
|
|
4572
4508
|
messages: { expectResolves: "Use `expect().resolves` instead" },
|
|
4573
4509
|
schema: []
|
|
4574
4510
|
},
|
|
4575
|
-
defaultOptions: [],
|
|
4576
4511
|
create: (context) => ({ CallExpression(node) {
|
|
4577
4512
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4578
4513
|
if (vitestFnCall?.type !== "expect") return;
|
|
4579
4514
|
const { parent } = vitestFnCall.head.node;
|
|
4580
|
-
if (parent?.type !==
|
|
4515
|
+
if (parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4581
4516
|
const [awaitNode] = parent.arguments;
|
|
4582
|
-
if (awaitNode?.type ===
|
|
4517
|
+
if (awaitNode?.type === _typescript_eslint_utils.AST_NODE_TYPES.AwaitExpression) context.report({
|
|
4583
4518
|
node: awaitNode,
|
|
4584
4519
|
messageId: "expectResolves",
|
|
4585
4520
|
fix(fixer) {
|
|
@@ -4618,19 +4553,18 @@ var prefer_expect_type_of_default = createEslintRule({
|
|
|
4618
4553
|
fixable: "code",
|
|
4619
4554
|
messages: { preferExpectTypeOf: "Use `expectTypeOf({{ value }}).{{ matcher }}()` instead of `expect(typeof {{ value }}).toBe(\"{{ type }}\")`" }
|
|
4620
4555
|
},
|
|
4621
|
-
defaultOptions: [],
|
|
4622
4556
|
create(context) {
|
|
4623
4557
|
return { CallExpression(node) {
|
|
4624
4558
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
4625
4559
|
if (vitestFnCall?.type !== "expect") return;
|
|
4626
|
-
if (vitestFnCall.head.node.parent?.type !==
|
|
4560
|
+
if (vitestFnCall.head.node.parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4627
4561
|
const [firstArg] = vitestFnCall.head.node.parent.arguments;
|
|
4628
|
-
if (!firstArg || firstArg.type !==
|
|
4562
|
+
if (!firstArg || firstArg.type !== _typescript_eslint_utils.AST_NODE_TYPES.UnaryExpression) return;
|
|
4629
4563
|
if (firstArg.operator !== "typeof") return;
|
|
4630
4564
|
const matcherName = getAccessorValue(vitestFnCall.matcher);
|
|
4631
4565
|
if (matcherName !== "toBe" && matcherName !== "toEqual") return;
|
|
4632
4566
|
const [matcherArg] = vitestFnCall.args;
|
|
4633
|
-
if (!matcherArg || matcherArg.type !==
|
|
4567
|
+
if (!matcherArg || matcherArg.type !== _typescript_eslint_utils.AST_NODE_TYPES.Literal) return;
|
|
4634
4568
|
if (typeof matcherArg.value !== "string") return;
|
|
4635
4569
|
const typeString = matcherArg.value;
|
|
4636
4570
|
const expectTypeOfMatcher = typeMatchers[typeString];
|
|
@@ -4674,7 +4608,6 @@ var prefer_hooks_in_order_default = createEslintRule({
|
|
|
4674
4608
|
messages: { reorderHooks: "`{{ currentHook }}` hooks should be before any `{{ previousHook }}` hooks" },
|
|
4675
4609
|
schema: []
|
|
4676
4610
|
},
|
|
4677
|
-
defaultOptions: [],
|
|
4678
4611
|
create(context) {
|
|
4679
4612
|
let previousHookIndex = -1;
|
|
4680
4613
|
let inHook = false;
|
|
@@ -4729,7 +4662,6 @@ var prefer_hooks_on_top_default = createEslintRule({
|
|
|
4729
4662
|
messages: { noHookOnTop: "Hooks should come before test cases" },
|
|
4730
4663
|
schema: []
|
|
4731
4664
|
},
|
|
4732
|
-
defaultOptions: [],
|
|
4733
4665
|
create(context) {
|
|
4734
4666
|
const hooksContext = [false];
|
|
4735
4667
|
return {
|
|
@@ -4762,23 +4694,20 @@ var prefer_import_in_mock_default = createEslintRule({
|
|
|
4762
4694
|
messages: { preferImport: "Replace '{{path}}' with import('{{path}}')" },
|
|
4763
4695
|
schema: [{
|
|
4764
4696
|
type: "object",
|
|
4765
|
-
properties: { fixable: {
|
|
4766
|
-
type: "boolean",
|
|
4767
|
-
default: true
|
|
4768
|
-
} },
|
|
4697
|
+
properties: { fixable: { type: "boolean" } },
|
|
4769
4698
|
additionalProperties: false
|
|
4770
|
-
}]
|
|
4699
|
+
}],
|
|
4700
|
+
defaultOptions: [{ fixable: true }]
|
|
4771
4701
|
},
|
|
4772
|
-
defaultOptions: [{ fixable: true }],
|
|
4773
4702
|
create(context, options) {
|
|
4774
4703
|
const fixable = options[0].fixable;
|
|
4775
4704
|
return { CallExpression(node) {
|
|
4776
|
-
if (node.callee.type !==
|
|
4705
|
+
if (node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return;
|
|
4777
4706
|
if (parseVitestFnCall(node, context)?.type !== "vi") return false;
|
|
4778
4707
|
const { property } = node.callee;
|
|
4779
|
-
if (property.type !=
|
|
4708
|
+
if (property.type != _typescript_eslint_utils.AST_NODE_TYPES.Identifier || property.name != "mock") return;
|
|
4780
4709
|
const pathArg = node.arguments[0];
|
|
4781
|
-
if (pathArg && pathArg.type ===
|
|
4710
|
+
if (pathArg && pathArg.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal) context.report({
|
|
4782
4711
|
messageId: "preferImport",
|
|
4783
4712
|
data: { path: pathArg.value },
|
|
4784
4713
|
node,
|
|
@@ -4806,7 +4735,6 @@ var prefer_importing_vitest_globals_default = createEslintRule({
|
|
|
4806
4735
|
schema: [],
|
|
4807
4736
|
fixable: "code"
|
|
4808
4737
|
},
|
|
4809
|
-
defaultOptions: [],
|
|
4810
4738
|
create(context) {
|
|
4811
4739
|
const importedNames = /* @__PURE__ */ new Set();
|
|
4812
4740
|
let vitestImportSpecifiers;
|
|
@@ -4909,24 +4837,18 @@ var prefer_lowercase_title_default = createEslintRule({
|
|
|
4909
4837
|
items: { type: "string" },
|
|
4910
4838
|
additionalItems: false
|
|
4911
4839
|
},
|
|
4912
|
-
ignoreTopLevelDescribe: {
|
|
4913
|
-
|
|
4914
|
-
default: false
|
|
4915
|
-
},
|
|
4916
|
-
lowercaseFirstCharacterOnly: {
|
|
4917
|
-
type: "boolean",
|
|
4918
|
-
default: true
|
|
4919
|
-
}
|
|
4840
|
+
ignoreTopLevelDescribe: { type: "boolean" },
|
|
4841
|
+
lowercaseFirstCharacterOnly: { type: "boolean" }
|
|
4920
4842
|
},
|
|
4921
4843
|
additionalProperties: false
|
|
4844
|
+
}],
|
|
4845
|
+
defaultOptions: [{
|
|
4846
|
+
ignore: [],
|
|
4847
|
+
allowedPrefixes: [],
|
|
4848
|
+
ignoreTopLevelDescribe: false,
|
|
4849
|
+
lowercaseFirstCharacterOnly: true
|
|
4922
4850
|
}]
|
|
4923
4851
|
},
|
|
4924
|
-
defaultOptions: [{
|
|
4925
|
-
ignore: [],
|
|
4926
|
-
allowedPrefixes: [],
|
|
4927
|
-
ignoreTopLevelDescribe: false,
|
|
4928
|
-
lowercaseFirstCharacterOnly: true
|
|
4929
|
-
}],
|
|
4930
4852
|
create: (context, [{ ignore = [], allowedPrefixes = [], ignoreTopLevelDescribe = false, lowercaseFirstCharacterOnly = false }]) => {
|
|
4931
4853
|
const ignores = populateIgnores(ignore);
|
|
4932
4854
|
let numberOfDescribeBlocks = 0;
|
|
@@ -4949,9 +4871,9 @@ var prefer_lowercase_title_default = createEslintRule({
|
|
|
4949
4871
|
node: node.arguments[0],
|
|
4950
4872
|
data: { method: vitestFnCall.name },
|
|
4951
4873
|
fix: (fixer) => {
|
|
4952
|
-
const description
|
|
4874
|
+
const description = getStringValue(firstArgument);
|
|
4953
4875
|
const rangeIgnoreQuotes = [firstArgument.range[0] + 1, firstArgument.range[1] - 1];
|
|
4954
|
-
const newDescription = lowercaseFirstCharacterOnly ? description
|
|
4876
|
+
const newDescription = lowercaseFirstCharacterOnly ? description.substring(0, 1).toLowerCase() + description.substring(1) : description.toLowerCase();
|
|
4955
4877
|
return [fixer.replaceTextRange(rangeIgnoreQuotes, newDescription)];
|
|
4956
4878
|
}
|
|
4957
4879
|
});
|
|
@@ -4970,8 +4892,8 @@ const withOnce$1 = (name, addOnce) => {
|
|
|
4970
4892
|
return `${name}${addOnce ? "Once" : ""}`;
|
|
4971
4893
|
};
|
|
4972
4894
|
const findSingleReturnArgumentNode$1 = (fnNode) => {
|
|
4973
|
-
if (fnNode.body.type !==
|
|
4974
|
-
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;
|
|
4975
4897
|
return null;
|
|
4976
4898
|
};
|
|
4977
4899
|
var prefer_mock_promise_shorthand_default = createEslintRule({
|
|
@@ -4986,10 +4908,9 @@ var prefer_mock_promise_shorthand_default = createEslintRule({
|
|
|
4986
4908
|
schema: [],
|
|
4987
4909
|
fixable: "code"
|
|
4988
4910
|
},
|
|
4989
|
-
defaultOptions: [],
|
|
4990
4911
|
create(context) {
|
|
4991
4912
|
const report = (property, isOnce, outerArgNode, innerArgNode = outerArgNode) => {
|
|
4992
|
-
if (innerArgNode?.type !==
|
|
4913
|
+
if (innerArgNode?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
4993
4914
|
const argName = getNodeName(innerArgNode);
|
|
4994
4915
|
if (argName !== "Promise.resolve" && argName !== "Promise.reject") return;
|
|
4995
4916
|
const replacement = withOnce$1(argName.endsWith("reject") ? "mockRejectedValue" : "mockResolvedValue", isOnce);
|
|
@@ -5005,7 +4926,7 @@ var prefer_mock_promise_shorthand_default = createEslintRule({
|
|
|
5005
4926
|
});
|
|
5006
4927
|
};
|
|
5007
4928
|
return { CallExpression(node) {
|
|
5008
|
-
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;
|
|
5009
4930
|
const mockFnName = getAccessorValue(node.callee.property);
|
|
5010
4931
|
const isOnce = mockFnName.endsWith("Once");
|
|
5011
4932
|
if (mockFnName === withOnce$1("mockReturnValue", isOnce)) report(node.callee.property, isOnce, node.arguments[0]);
|
|
@@ -5025,8 +4946,8 @@ const withOnce = (name, addOnce) => {
|
|
|
5025
4946
|
return `${name}${addOnce ? "Once" : ""}`;
|
|
5026
4947
|
};
|
|
5027
4948
|
const findSingleReturnArgumentNode = (fnNode) => {
|
|
5028
|
-
if (fnNode.body.type !==
|
|
5029
|
-
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;
|
|
5030
4951
|
return null;
|
|
5031
4952
|
};
|
|
5032
4953
|
var prefer_mock_return_shorthand_default = createEslintRule({
|
|
@@ -5041,10 +4962,9 @@ var prefer_mock_return_shorthand_default = createEslintRule({
|
|
|
5041
4962
|
type: "suggestion",
|
|
5042
4963
|
fixable: "code"
|
|
5043
4964
|
},
|
|
5044
|
-
defaultOptions: [],
|
|
5045
4965
|
create(context) {
|
|
5046
4966
|
return { CallExpression(node) {
|
|
5047
|
-
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;
|
|
5048
4968
|
const { property } = node.callee;
|
|
5049
4969
|
const mockFnName = getAccessorValue(property);
|
|
5050
4970
|
const isOnce = mockFnName.endsWith("Once");
|
|
@@ -5053,8 +4973,8 @@ var prefer_mock_return_shorthand_default = createEslintRule({
|
|
|
5053
4973
|
if (!isFunction(arg) || arg.params.length !== 0 || arg.async) return;
|
|
5054
4974
|
const replacement = withOnce("mockReturnValue", isOnce);
|
|
5055
4975
|
const returnNode = findSingleReturnArgumentNode(arg);
|
|
5056
|
-
if (!returnNode || returnNode.type ===
|
|
5057
|
-
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) {
|
|
5058
4978
|
if (context.sourceCode.getScope(returnNode).through.some((v) => v.resolved?.defs.some((n) => n.type === "Variable" && n.parent.kind !== "const"))) return;
|
|
5059
4979
|
}
|
|
5060
4980
|
context.report({
|
|
@@ -5093,9 +5013,8 @@ var prefer_snapshot_hint_default = createEslintRule({
|
|
|
5093
5013
|
type: "string",
|
|
5094
5014
|
enum: ["always", "multi"]
|
|
5095
5015
|
}],
|
|
5096
|
-
defaultOptions: []
|
|
5016
|
+
defaultOptions: ["multi"]
|
|
5097
5017
|
},
|
|
5098
|
-
defaultOptions: ["multi"],
|
|
5099
5018
|
create(context, [mode]) {
|
|
5100
5019
|
const snapshotMatchers = [];
|
|
5101
5020
|
let expressionDepth = 0;
|
|
@@ -5154,18 +5073,18 @@ var prefer_snapshot_hint_default = createEslintRule({
|
|
|
5154
5073
|
const RULE_NAME$24 = "prefer-spy-on";
|
|
5155
5074
|
const findNodeObject = (node) => {
|
|
5156
5075
|
if ("object" in node) return node.object;
|
|
5157
|
-
if (node.callee.type ===
|
|
5076
|
+
if (node.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return node.callee.object;
|
|
5158
5077
|
return null;
|
|
5159
5078
|
};
|
|
5160
5079
|
const getVitestFnCall = (node) => {
|
|
5161
|
-
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;
|
|
5162
5081
|
const obj = findNodeObject(node);
|
|
5163
5082
|
if (!obj) return null;
|
|
5164
|
-
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;
|
|
5165
5084
|
return getVitestFnCall(obj);
|
|
5166
5085
|
};
|
|
5167
5086
|
const getAutoFixMockImplementation = (vitestFnCall, context) => {
|
|
5168
|
-
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 "";
|
|
5169
5088
|
const [arg] = vitestFnCall.arguments;
|
|
5170
5089
|
const argSource = arg && context.sourceCode.getText(arg);
|
|
5171
5090
|
return argSource ? `.mockImplementation(${argSource})` : ".mockImplementation()";
|
|
@@ -5182,18 +5101,17 @@ var prefer_spy_on_default = createEslintRule({
|
|
|
5182
5101
|
fixable: "code",
|
|
5183
5102
|
schema: []
|
|
5184
5103
|
},
|
|
5185
|
-
defaultOptions: [],
|
|
5186
5104
|
create(context) {
|
|
5187
5105
|
return { AssignmentExpression(node) {
|
|
5188
5106
|
const { left, right } = node;
|
|
5189
|
-
if (left.type !==
|
|
5107
|
+
if (left.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) return;
|
|
5190
5108
|
const vitestFnCall = getVitestFnCall(right);
|
|
5191
5109
|
if (!vitestFnCall) return;
|
|
5192
5110
|
context.report({
|
|
5193
5111
|
node,
|
|
5194
5112
|
messageId: "useViSpayOn",
|
|
5195
5113
|
fix(fixer) {
|
|
5196
|
-
const lefPropQuote = left.property.type ===
|
|
5114
|
+
const lefPropQuote = left.property.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && !left.computed ? "'" : "";
|
|
5197
5115
|
const mockImplementation = getAutoFixMockImplementation(vitestFnCall, context);
|
|
5198
5116
|
return [
|
|
5199
5117
|
fixer.insertTextBefore(left, "vi.spyOn("),
|
|
@@ -5224,7 +5142,6 @@ var prefer_strict_boolean_matchers_default = createEslintRule({
|
|
|
5224
5142
|
fixable: "code",
|
|
5225
5143
|
schema: []
|
|
5226
5144
|
},
|
|
5227
|
-
defaultOptions: [],
|
|
5228
5145
|
create(context) {
|
|
5229
5146
|
return { CallExpression(node) {
|
|
5230
5147
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -5262,7 +5179,6 @@ var prefer_strict_equal_default = createEslintRule({
|
|
|
5262
5179
|
schema: [],
|
|
5263
5180
|
hasSuggestions: true
|
|
5264
5181
|
},
|
|
5265
|
-
defaultOptions: [],
|
|
5266
5182
|
create(context) {
|
|
5267
5183
|
return { CallExpression(node) {
|
|
5268
5184
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -5283,7 +5199,7 @@ var prefer_strict_equal_default = createEslintRule({
|
|
|
5283
5199
|
//#endregion
|
|
5284
5200
|
//#region src/rules/prefer-to-be-falsy.ts
|
|
5285
5201
|
const RULE_NAME$21 = "prefer-to-be-falsy";
|
|
5286
|
-
const isFalseLiteral = (node) => node.type ===
|
|
5202
|
+
const isFalseLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === false;
|
|
5287
5203
|
var prefer_to_be_falsy_default = createEslintRule({
|
|
5288
5204
|
name: RULE_NAME$21,
|
|
5289
5205
|
meta: {
|
|
@@ -5296,7 +5212,6 @@ var prefer_to_be_falsy_default = createEslintRule({
|
|
|
5296
5212
|
schema: [],
|
|
5297
5213
|
messages: { preferToBeFalsy: "Prefer using toBeFalsy()" }
|
|
5298
5214
|
},
|
|
5299
|
-
defaultOptions: [],
|
|
5300
5215
|
create(context) {
|
|
5301
5216
|
return { CallExpression(node) {
|
|
5302
5217
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -5325,7 +5240,6 @@ var prefer_to_be_object_default = createEslintRule({
|
|
|
5325
5240
|
messages: { preferToBeObject: "Prefer toBeObject() to test if a value is an object" },
|
|
5326
5241
|
schema: []
|
|
5327
5242
|
},
|
|
5328
|
-
defaultOptions: [],
|
|
5329
5243
|
create(context) {
|
|
5330
5244
|
return { CallExpression(node) {
|
|
5331
5245
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -5339,7 +5253,7 @@ var prefer_to_be_object_default = createEslintRule({
|
|
|
5339
5253
|
return;
|
|
5340
5254
|
}
|
|
5341
5255
|
const { parent: expectTypeOf } = vitestFnCall.head.node;
|
|
5342
|
-
if (expectTypeOf?.type !==
|
|
5256
|
+
if (expectTypeOf?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
5343
5257
|
const [expectTypeOfArgs] = expectTypeOf.arguments;
|
|
5344
5258
|
if (!expectTypeOfArgs || !isBooleanEqualityMatcher(vitestFnCall) || !isInstanceOfBinaryExpression(expectTypeOfArgs, "Object")) return;
|
|
5345
5259
|
context.report({
|
|
@@ -5351,10 +5265,10 @@ var prefer_to_be_object_default = createEslintRule({
|
|
|
5351
5265
|
if (vitestFnCall.args.length) {
|
|
5352
5266
|
const [matcherArg] = vitestFnCall.args;
|
|
5353
5267
|
fixes.push(fixer.remove(matcherArg));
|
|
5354
|
-
invertCondition = matcherArg.type ===
|
|
5268
|
+
invertCondition = matcherArg.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && followTypeAssertionChain$1(matcherArg).value === false;
|
|
5355
5269
|
}
|
|
5356
5270
|
if (invertCondition) {
|
|
5357
|
-
const notModifier = vitestFnCall.modifiers.find((node
|
|
5271
|
+
const notModifier = vitestFnCall.modifiers.find((node) => getAccessorValue(node) === "not");
|
|
5358
5272
|
fixes.push(notModifier ? fixer.removeRange([notModifier.range[0] - 1, notModifier.range[1]]) : fixer.insertTextBefore(vitestFnCall.matcher, "not."));
|
|
5359
5273
|
}
|
|
5360
5274
|
return fixes;
|
|
@@ -5367,7 +5281,7 @@ var prefer_to_be_object_default = createEslintRule({
|
|
|
5367
5281
|
//#endregion
|
|
5368
5282
|
//#region src/rules/prefer-to-be-truthy.ts
|
|
5369
5283
|
const RULE_NAME$19 = "prefer-to-be-truthy";
|
|
5370
|
-
const isTrueLiteral = (node) => node.type ===
|
|
5284
|
+
const isTrueLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === true;
|
|
5371
5285
|
var prefer_to_be_truthy_default = createEslintRule({
|
|
5372
5286
|
name: RULE_NAME$19,
|
|
5373
5287
|
meta: {
|
|
@@ -5380,7 +5294,6 @@ var prefer_to_be_truthy_default = createEslintRule({
|
|
|
5380
5294
|
fixable: "code",
|
|
5381
5295
|
schema: []
|
|
5382
5296
|
},
|
|
5383
|
-
defaultOptions: [],
|
|
5384
5297
|
create(context) {
|
|
5385
5298
|
return { CallExpression(node) {
|
|
5386
5299
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -5397,16 +5310,16 @@ var prefer_to_be_truthy_default = createEslintRule({
|
|
|
5397
5310
|
//#endregion
|
|
5398
5311
|
//#region src/rules/prefer-to-be.ts
|
|
5399
5312
|
const RULE_NAME$18 = "prefer-to-be";
|
|
5400
|
-
const isNullLiteral = (node) => node.type ===
|
|
5313
|
+
const isNullLiteral = (node) => node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === null;
|
|
5401
5314
|
const isNullEqualityMatcher = (expectFnCall) => isNullLiteral(getFirstMatcherArg(expectFnCall));
|
|
5402
5315
|
const isFirstArgumentIdentifier = (expectFnCall, name) => isIdentifier(getFirstMatcherArg(expectFnCall), name);
|
|
5403
5316
|
const isFloat = (v) => Math.floor(v) !== Math.ceil(v);
|
|
5404
5317
|
const shouldUseToBe = (expectFnCall) => {
|
|
5405
5318
|
let firstArg = getFirstMatcherArg(expectFnCall);
|
|
5406
|
-
if (firstArg.type ===
|
|
5407
|
-
if (firstArg.type ===
|
|
5408
|
-
if (firstArg.type ===
|
|
5409
|
-
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;
|
|
5410
5323
|
};
|
|
5411
5324
|
const reportPreferToBe = (context, whatToBe, expectFnCall, func, modifierNode) => {
|
|
5412
5325
|
context.report({
|
|
@@ -5438,13 +5351,12 @@ var prefer_to_be_default = createEslintRule({
|
|
|
5438
5351
|
useToBeNaN: "Use `toBeNaN()` instead"
|
|
5439
5352
|
}
|
|
5440
5353
|
},
|
|
5441
|
-
defaultOptions: [],
|
|
5442
5354
|
create(context) {
|
|
5443
5355
|
return { CallExpression(node) {
|
|
5444
5356
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
5445
5357
|
if (vitestFnCall?.type !== "expect") return;
|
|
5446
5358
|
const matcherName = getAccessorValue(vitestFnCall.matcher);
|
|
5447
|
-
const notModifier = vitestFnCall.modifiers.find((node
|
|
5359
|
+
const notModifier = vitestFnCall.modifiers.find((node) => getAccessorValue(node) === "not");
|
|
5448
5360
|
if (notModifier && ["toBeUndefined", "toBeDefined"].includes(matcherName)) {
|
|
5449
5361
|
reportPreferToBe(context, matcherName === "toBeDefined" ? "Undefined" : "Defined", vitestFnCall, node, notModifier);
|
|
5450
5362
|
return;
|
|
@@ -5470,7 +5382,7 @@ var prefer_to_be_default = createEslintRule({
|
|
|
5470
5382
|
//#endregion
|
|
5471
5383
|
//#region src/rules/prefer-to-contain.ts
|
|
5472
5384
|
const RULE_NAME$17 = "prefer-to-contain";
|
|
5473
|
-
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;
|
|
5474
5386
|
var prefer_to_contain_default = createEslintRule({
|
|
5475
5387
|
name: RULE_NAME$17,
|
|
5476
5388
|
meta: {
|
|
@@ -5483,17 +5395,16 @@ var prefer_to_contain_default = createEslintRule({
|
|
|
5483
5395
|
type: "suggestion",
|
|
5484
5396
|
schema: []
|
|
5485
5397
|
},
|
|
5486
|
-
defaultOptions: [],
|
|
5487
5398
|
create(context) {
|
|
5488
5399
|
return { CallExpression(node) {
|
|
5489
5400
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
5490
5401
|
if (vitestFnCall?.type !== "expect" || vitestFnCall.args.length === 0) return;
|
|
5491
5402
|
const { parent: expect } = vitestFnCall.head.node;
|
|
5492
|
-
if (expect?.type !==
|
|
5403
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
5493
5404
|
const { arguments: [includesCall], range: [, expectCallEnd] } = expect;
|
|
5494
5405
|
const { matcher } = vitestFnCall;
|
|
5495
5406
|
const matcherArg = getFirstMatcherArg(vitestFnCall);
|
|
5496
|
-
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;
|
|
5497
5408
|
const hasNot = vitestFnCall.modifiers.some((nod) => getAccessorValue(nod) === "not");
|
|
5498
5409
|
context.report({
|
|
5499
5410
|
fix(fixer) {
|
|
@@ -5527,16 +5438,15 @@ var prefer_to_have_length_default = createEslintRule({
|
|
|
5527
5438
|
messages: { preferToHaveLength: "Prefer toHaveLength()" },
|
|
5528
5439
|
schema: []
|
|
5529
5440
|
},
|
|
5530
|
-
defaultOptions: [],
|
|
5531
5441
|
create(context) {
|
|
5532
5442
|
return { CallExpression(node) {
|
|
5533
5443
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
5534
5444
|
if (vitestFnCall?.type !== "expect") return;
|
|
5535
5445
|
const { parent: expect } = vitestFnCall.head.node;
|
|
5536
|
-
if (expect?.type !==
|
|
5446
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
5537
5447
|
const [argument] = expect.arguments;
|
|
5538
5448
|
const { matcher } = vitestFnCall;
|
|
5539
|
-
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;
|
|
5540
5450
|
context.report({
|
|
5541
5451
|
node: matcher,
|
|
5542
5452
|
messageId: "preferToHaveLength",
|
|
@@ -5558,7 +5468,7 @@ const isTargetedTestCase = (vitestFnCall) => {
|
|
|
5558
5468
|
};
|
|
5559
5469
|
function isEmptyFunction(node) {
|
|
5560
5470
|
if (!isFunction(node)) return false;
|
|
5561
|
-
return node.body.type ===
|
|
5471
|
+
return node.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement && !node.body.body.length;
|
|
5562
5472
|
}
|
|
5563
5473
|
function createTodoFixer(vitestFnCall, fixer) {
|
|
5564
5474
|
if (vitestFnCall.members.length) return replaceAccessorFixer(fixer, vitestFnCall.members[0], "todo");
|
|
@@ -5579,7 +5489,6 @@ var prefer_todo_default = createEslintRule({
|
|
|
5579
5489
|
fixable: "code",
|
|
5580
5490
|
schema: []
|
|
5581
5491
|
},
|
|
5582
|
-
defaultOptions: [],
|
|
5583
5492
|
create(context) {
|
|
5584
5493
|
return { CallExpression(node) {
|
|
5585
5494
|
const [title, callback] = node.arguments;
|
|
@@ -5621,13 +5530,12 @@ var prefer_vi_mocked_default = createEslintRule({
|
|
|
5621
5530
|
messages: { useViMocked: "Prefer `vi.mocked()`" },
|
|
5622
5531
|
schema: []
|
|
5623
5532
|
},
|
|
5624
|
-
defaultOptions: [],
|
|
5625
5533
|
create(context) {
|
|
5626
5534
|
function check(node) {
|
|
5627
5535
|
const { typeAnnotation } = node;
|
|
5628
|
-
if (typeAnnotation.type !==
|
|
5536
|
+
if (typeAnnotation.type !== _typescript_eslint_utils.AST_NODE_TYPES.TSTypeReference) return;
|
|
5629
5537
|
const { typeName } = typeAnnotation;
|
|
5630
|
-
if (typeName.type !==
|
|
5538
|
+
if (typeName.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
|
|
5631
5539
|
if (!mockTypes.includes(typeName.name)) return;
|
|
5632
5540
|
const fnName = context.sourceCode.text.slice(...followTypeAssertionChain(node.expression).range);
|
|
5633
5541
|
context.report({
|
|
@@ -5640,7 +5548,7 @@ var prefer_vi_mocked_default = createEslintRule({
|
|
|
5640
5548
|
}
|
|
5641
5549
|
return {
|
|
5642
5550
|
TSAsExpression(node) {
|
|
5643
|
-
if (node.parent.type ===
|
|
5551
|
+
if (node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.TSAsExpression) return;
|
|
5644
5552
|
check(node);
|
|
5645
5553
|
},
|
|
5646
5554
|
TSTypeAssertion(node) {
|
|
@@ -5665,7 +5573,6 @@ var require_awaited_expect_poll_default = createEslintRule({
|
|
|
5665
5573
|
type: "problem",
|
|
5666
5574
|
schema: []
|
|
5667
5575
|
},
|
|
5668
|
-
defaultOptions: [],
|
|
5669
5576
|
create(context) {
|
|
5670
5577
|
const reported = /* @__PURE__ */ new Set();
|
|
5671
5578
|
return { CallExpression(node) {
|
|
@@ -5674,7 +5581,7 @@ var require_awaited_expect_poll_default = createEslintRule({
|
|
|
5674
5581
|
const nodeToReport = vitestFnCall.members[0].parent;
|
|
5675
5582
|
if (reported.has(nodeToReport)) return;
|
|
5676
5583
|
const topMostNode = skipSequenceExpressions(skipMatchersAndModifiers(vitestFnCall.head.node));
|
|
5677
|
-
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;
|
|
5678
5585
|
context.report({
|
|
5679
5586
|
node: nodeToReport,
|
|
5680
5587
|
messageId: "notAwaited",
|
|
@@ -5690,12 +5597,12 @@ function memberRequiresAwait(member) {
|
|
|
5690
5597
|
}
|
|
5691
5598
|
function skipMatchersAndModifiers(node) {
|
|
5692
5599
|
let currentNode = node;
|
|
5693
|
-
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;
|
|
5694
5601
|
return currentNode;
|
|
5695
5602
|
}
|
|
5696
5603
|
function skipSequenceExpressions(node) {
|
|
5697
5604
|
let currentNode = node;
|
|
5698
|
-
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;
|
|
5699
5606
|
return currentNode;
|
|
5700
5607
|
}
|
|
5701
5608
|
|
|
@@ -5707,13 +5614,13 @@ const isVitestFnCall = (node, context) => {
|
|
|
5707
5614
|
return !!getNodeName(node)?.startsWith("vi");
|
|
5708
5615
|
};
|
|
5709
5616
|
const isNullOrUndefined = (node) => {
|
|
5710
|
-
return node.type ===
|
|
5617
|
+
return node.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && node.value === null || isIdentifier(node, "undefined");
|
|
5711
5618
|
};
|
|
5712
5619
|
const shouldBeInHook = (node, context, allowedFunctionCalls = []) => {
|
|
5713
5620
|
switch (node.type) {
|
|
5714
|
-
case
|
|
5715
|
-
case
|
|
5716
|
-
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:
|
|
5717
5624
|
if (node.kind === "const") return false;
|
|
5718
5625
|
return node.declarations.some(({ init }) => init !== null && !isNullOrUndefined(init));
|
|
5719
5626
|
default: return false;
|
|
@@ -5735,9 +5642,9 @@ var require_hook_default = createEslintRule({
|
|
|
5735
5642
|
items: { type: "string" }
|
|
5736
5643
|
} },
|
|
5737
5644
|
additionalProperties: false
|
|
5738
|
-
}]
|
|
5645
|
+
}],
|
|
5646
|
+
defaultOptions: [{ allowedFunctionCalls: [] }]
|
|
5739
5647
|
},
|
|
5740
|
-
defaultOptions: [{ allowedFunctionCalls: [] }],
|
|
5741
5648
|
create(context, options) {
|
|
5742
5649
|
const checkBlockBody = (body) => {
|
|
5743
5650
|
for (const statement of body) if (shouldBeInHook(statement, context, options[0].allowedFunctionCalls)) context.report({
|
|
@@ -5752,7 +5659,7 @@ var require_hook_default = createEslintRule({
|
|
|
5752
5659
|
CallExpression(node) {
|
|
5753
5660
|
if (!isTypeOfVitestFnCall(node, context, ["describe"]) || node.arguments.length < 2) return;
|
|
5754
5661
|
const [, testFn] = node.arguments;
|
|
5755
|
-
if (!isFunction(testFn) || testFn.body.type !==
|
|
5662
|
+
if (!isFunction(testFn) || testFn.body.type !== _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) return;
|
|
5756
5663
|
checkBlockBody(testFn.body.body);
|
|
5757
5664
|
}
|
|
5758
5665
|
};
|
|
@@ -5773,7 +5680,6 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5773
5680
|
messages: { missingTimeout: "Test is missing a timeout. Add an explicit timeout." },
|
|
5774
5681
|
schema: []
|
|
5775
5682
|
},
|
|
5776
|
-
defaultOptions: [],
|
|
5777
5683
|
create(context) {
|
|
5778
5684
|
/**
|
|
5779
5685
|
* Track positions (character offsets) of vi.setConfig({ testTimeout })
|
|
@@ -5788,10 +5694,10 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5788
5694
|
const firstMember = vitestFnCall.members[0];
|
|
5789
5695
|
if (firstMember && getAccessorValue(firstMember) === "setConfig") {
|
|
5790
5696
|
const arg = node.arguments[0];
|
|
5791
|
-
if (arg && arg.type ===
|
|
5792
|
-
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) {
|
|
5793
5699
|
const key = prop.key;
|
|
5794
|
-
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) {
|
|
5795
5701
|
const endOffset = node.range ? node.range[1] : 0;
|
|
5796
5702
|
setConfigPositions.push(endOffset);
|
|
5797
5703
|
break;
|
|
@@ -5807,7 +5713,7 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5807
5713
|
return v === "todo" || v === "skip";
|
|
5808
5714
|
}) || vitestFnCall.name.startsWith("x")) return;
|
|
5809
5715
|
const args = node.arguments;
|
|
5810
|
-
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;
|
|
5811
5717
|
/**
|
|
5812
5718
|
* If there is a setConfig call *before* this test that sets testTimeout,
|
|
5813
5719
|
* exempt this test. Note: we compare source positions (character offsets)
|
|
@@ -5818,7 +5724,7 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5818
5724
|
let foundNumericTimeout = false;
|
|
5819
5725
|
let foundObjectTimeout = false;
|
|
5820
5726
|
for (const a of args) {
|
|
5821
|
-
if (a.type ===
|
|
5727
|
+
if (a.type === _typescript_eslint_utils.AST_NODE_TYPES.Literal && typeof a.value === "number") if (a.value >= 0) foundNumericTimeout = true;
|
|
5822
5728
|
else {
|
|
5823
5729
|
context.report({
|
|
5824
5730
|
node,
|
|
@@ -5826,10 +5732,10 @@ var require_test_timeout_default = createEslintRule({
|
|
|
5826
5732
|
});
|
|
5827
5733
|
return;
|
|
5828
5734
|
}
|
|
5829
|
-
if (a.type ===
|
|
5830
|
-
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;
|
|
5831
5737
|
const key = prop.key;
|
|
5832
|
-
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;
|
|
5833
5739
|
else {
|
|
5834
5740
|
context.report({
|
|
5835
5741
|
node,
|
|
@@ -5862,15 +5768,14 @@ var require_local_test_context_for_concurrent_snapshots_default = createEslintRu
|
|
|
5862
5768
|
type: "problem",
|
|
5863
5769
|
schema: []
|
|
5864
5770
|
},
|
|
5865
|
-
defaultOptions: [],
|
|
5866
5771
|
create(context) {
|
|
5867
5772
|
return { CallExpression(node) {
|
|
5868
5773
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
5869
5774
|
if (vitestFnCall === null) return;
|
|
5870
5775
|
if (vitestFnCall.type !== "expect") return;
|
|
5871
5776
|
if (vitestFnCall.type === "expect" && vitestFnCall.head.type === "testContext") return;
|
|
5872
|
-
if (node.callee.type !==
|
|
5873
|
-
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;
|
|
5874
5779
|
if (![
|
|
5875
5780
|
"toMatchSnapshot",
|
|
5876
5781
|
"toMatchInlineSnapshot",
|
|
@@ -5879,9 +5784,9 @@ var require_local_test_context_for_concurrent_snapshots_default = createEslintRu
|
|
|
5879
5784
|
"toThrowErrorMatchingInlineSnapshot"
|
|
5880
5785
|
].includes(node.callee.property.name)) return;
|
|
5881
5786
|
if (!context.sourceCode.getAncestors(node).some((ancestor) => {
|
|
5882
|
-
if (ancestor.type !==
|
|
5787
|
+
if (ancestor.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return false;
|
|
5883
5788
|
if (!isTypeOfVitestFnCall(ancestor, context, ["describe", "test"])) return false;
|
|
5884
|
-
return ancestor.callee.type ===
|
|
5789
|
+
return ancestor.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(ancestor.callee.property, "concurrent");
|
|
5885
5790
|
})) return;
|
|
5886
5791
|
context.report({
|
|
5887
5792
|
node,
|
|
@@ -5909,9 +5814,8 @@ var require_mock_type_parameters_default = createEslintRule({
|
|
|
5909
5814
|
properties: { checkImportFunctions: { type: "boolean" } },
|
|
5910
5815
|
additionalProperties: false
|
|
5911
5816
|
}],
|
|
5912
|
-
defaultOptions: []
|
|
5817
|
+
defaultOptions: [{ checkImportFunctions: false }]
|
|
5913
5818
|
},
|
|
5914
|
-
defaultOptions: [{ checkImportFunctions: false }],
|
|
5915
5819
|
create(context, [options]) {
|
|
5916
5820
|
return { CallExpression(node) {
|
|
5917
5821
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -5945,7 +5849,6 @@ var require_to_throw_message_default = createEslintRule({
|
|
|
5945
5849
|
schema: [],
|
|
5946
5850
|
messages: { addErrorMessage: "Add an error message to {{ matcherName }}()" }
|
|
5947
5851
|
},
|
|
5948
|
-
defaultOptions: [],
|
|
5949
5852
|
create(context) {
|
|
5950
5853
|
return { CallExpression(node) {
|
|
5951
5854
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -5981,13 +5884,12 @@ var require_top_level_describe_default = createEslintRule({
|
|
|
5981
5884
|
type: "object",
|
|
5982
5885
|
properties: { maxNumberOfTopLevelDescribes: {
|
|
5983
5886
|
type: "number",
|
|
5984
|
-
minimum: 1
|
|
5985
|
-
default: Infinity
|
|
5887
|
+
minimum: 1
|
|
5986
5888
|
} },
|
|
5987
5889
|
additionalProperties: false
|
|
5988
|
-
}]
|
|
5890
|
+
}],
|
|
5891
|
+
defaultOptions: [{ maxNumberOfTopLevelDescribes: Infinity }]
|
|
5989
5892
|
},
|
|
5990
|
-
defaultOptions: [{ maxNumberOfTopLevelDescribes: Infinity }],
|
|
5991
5893
|
create(context, options) {
|
|
5992
5894
|
const maxNumberOfTopLevelDescribes = options[0].maxNumberOfTopLevelDescribes;
|
|
5993
5895
|
let numberOfTopLevelDescribeBlocks = 0;
|
|
@@ -6048,7 +5950,7 @@ const hasNonEachMembersAndParams = (vitestFnCall, functionExpression) => {
|
|
|
6048
5950
|
};
|
|
6049
5951
|
const reportUnexpectedReturnInDescribe = (blockStatement, context) => {
|
|
6050
5952
|
blockStatement.body.forEach((node) => {
|
|
6051
|
-
if (node.type !==
|
|
5953
|
+
if (node.type !== _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement) return;
|
|
6052
5954
|
context.report({
|
|
6053
5955
|
messageId: "unexpectedReturnInDescribe",
|
|
6054
5956
|
node
|
|
@@ -6071,12 +5973,11 @@ var valid_describe_callback_default = createEslintRule({
|
|
|
6071
5973
|
},
|
|
6072
5974
|
schema: []
|
|
6073
5975
|
},
|
|
6074
|
-
defaultOptions: [],
|
|
6075
5976
|
create(context) {
|
|
6076
5977
|
return { CallExpression(node) {
|
|
6077
5978
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
6078
5979
|
if (vitestFnCall?.type !== "describe") return;
|
|
6079
|
-
if (vitestFnCall?.members[0]?.type ===
|
|
5980
|
+
if (vitestFnCall?.members[0]?.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && vitestFnCall.members[0].name === "todo") return;
|
|
6080
5981
|
if (node.arguments.length < 1) return context.report({
|
|
6081
5982
|
messageId: "nameAndCallback",
|
|
6082
5983
|
loc: node.loc
|
|
@@ -6095,11 +5996,11 @@ var valid_describe_callback_default = createEslintRule({
|
|
|
6095
5996
|
messageId: "unexpectedDescribeArgument",
|
|
6096
5997
|
node: arg3
|
|
6097
5998
|
});
|
|
6098
|
-
if (arg3.body.type ===
|
|
5999
|
+
if (arg3.body.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) context.report({
|
|
6099
6000
|
messageId: "unexpectedReturnInDescribe",
|
|
6100
6001
|
node: arg3
|
|
6101
6002
|
});
|
|
6102
|
-
if (arg3.body.type ===
|
|
6003
|
+
if (arg3.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) reportUnexpectedReturnInDescribe(arg3.body, context);
|
|
6103
6004
|
return;
|
|
6104
6005
|
}
|
|
6105
6006
|
context.report({
|
|
@@ -6112,11 +6013,11 @@ var valid_describe_callback_default = createEslintRule({
|
|
|
6112
6013
|
messageId: "unexpectedDescribeArgument",
|
|
6113
6014
|
node: arg2
|
|
6114
6015
|
});
|
|
6115
|
-
if (arg2.body.type ===
|
|
6016
|
+
if (arg2.body.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) context.report({
|
|
6116
6017
|
messageId: "unexpectedReturnInDescribe",
|
|
6117
6018
|
node: arg2
|
|
6118
6019
|
});
|
|
6119
|
-
if (arg2.body.type ===
|
|
6020
|
+
if (arg2.body.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) reportUnexpectedReturnInDescribe(arg2.body, context);
|
|
6120
6021
|
} };
|
|
6121
6022
|
}
|
|
6122
6023
|
});
|
|
@@ -6124,9 +6025,8 @@ var valid_describe_callback_default = createEslintRule({
|
|
|
6124
6025
|
//#endregion
|
|
6125
6026
|
//#region src/rules/valid-expect-in-promise.ts
|
|
6126
6027
|
const RULE_NAME$5 = "valid-expect-in-promise";
|
|
6127
|
-
const defaultAsyncMatchers$1 = ["toRejectWith", "toResolveWith"];
|
|
6128
6028
|
const isPromiseChainCall = (node) => {
|
|
6129
|
-
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)) {
|
|
6130
6030
|
if (node.arguments.length === 0) return false;
|
|
6131
6031
|
switch (getAccessorValue(node.callee.property)) {
|
|
6132
6032
|
case "then": return node.arguments.length < 3;
|
|
@@ -6140,7 +6040,7 @@ const isTestCaseCallWithCallbackArg = (node, context) => {
|
|
|
6140
6040
|
const vitestCallFn = parseVitestFnCall(node, context);
|
|
6141
6041
|
if (vitestCallFn?.type !== "test") return false;
|
|
6142
6042
|
const isVitestEach = vitestCallFn.members.some((s) => getAccessorValue(s) === "each");
|
|
6143
|
-
if (isVitestEach && node.callee.type !==
|
|
6043
|
+
if (isVitestEach && node.callee.type !== _typescript_eslint_utils.AST_NODE_TYPES.TaggedTemplateExpression) return true;
|
|
6144
6044
|
const [, callback] = node.arguments;
|
|
6145
6045
|
const callbackArgIndex = Number(isVitestEach);
|
|
6146
6046
|
return callback && isFunction(callback) && callback.params.length === 1 + callbackArgIndex;
|
|
@@ -6148,11 +6048,11 @@ const isTestCaseCallWithCallbackArg = (node, context) => {
|
|
|
6148
6048
|
const isPromiseMethodThatUsesValue = (node, identifier) => {
|
|
6149
6049
|
const { name } = identifier;
|
|
6150
6050
|
if (node.argument === null) return false;
|
|
6151
|
-
if (node.argument.type ===
|
|
6051
|
+
if (node.argument.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && node.argument.arguments.length > 0) {
|
|
6152
6052
|
const nodeName = getNodeName(node.argument);
|
|
6153
6053
|
if (["Promise.all", "Promise.allSettled"].includes(nodeName)) {
|
|
6154
6054
|
const [firstArg] = node.argument.arguments;
|
|
6155
|
-
if (firstArg.type ===
|
|
6055
|
+
if (firstArg.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrayExpression && firstArg.elements.some((nod) => nod && isIdentifier(nod, name))) return true;
|
|
6156
6056
|
}
|
|
6157
6057
|
if (["Promise.resolve", "Promise.reject"].includes(nodeName) && node.argument.arguments.length === 1) return isIdentifier(node.argument.arguments[0], name);
|
|
6158
6058
|
}
|
|
@@ -6164,8 +6064,8 @@ const isPromiseMethodThatUsesValue = (node, identifier) => {
|
|
|
6164
6064
|
*/
|
|
6165
6065
|
const isValueAwaitedInElements = (name, elements) => {
|
|
6166
6066
|
for (const element of elements) {
|
|
6167
|
-
if (element?.type ===
|
|
6168
|
-
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;
|
|
6169
6069
|
}
|
|
6170
6070
|
return false;
|
|
6171
6071
|
};
|
|
@@ -6176,11 +6076,11 @@ const isValueAwaitedInElements = (name, elements) => {
|
|
|
6176
6076
|
const isValueAwaitedInArguments = (name, call) => {
|
|
6177
6077
|
let node = call;
|
|
6178
6078
|
while (node) {
|
|
6179
|
-
if (node.type ===
|
|
6079
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) {
|
|
6180
6080
|
if (isValueAwaitedInElements(name, node.arguments)) return true;
|
|
6181
6081
|
node = node.callee;
|
|
6182
6082
|
}
|
|
6183
|
-
if (node.type !==
|
|
6083
|
+
if (node.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) break;
|
|
6184
6084
|
node = node.object;
|
|
6185
6085
|
}
|
|
6186
6086
|
return false;
|
|
@@ -6189,11 +6089,11 @@ const getLeftMostCallExpression = (call) => {
|
|
|
6189
6089
|
let leftMostCallExpression = call;
|
|
6190
6090
|
let node = call;
|
|
6191
6091
|
while (node) {
|
|
6192
|
-
if (node.type ===
|
|
6092
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) {
|
|
6193
6093
|
leftMostCallExpression = node;
|
|
6194
6094
|
node = node.callee;
|
|
6195
6095
|
}
|
|
6196
|
-
if (node.type !==
|
|
6096
|
+
if (node.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) break;
|
|
6197
6097
|
node = node.object;
|
|
6198
6098
|
}
|
|
6199
6099
|
return leftMostCallExpression;
|
|
@@ -6206,9 +6106,9 @@ const isValueAwaitedOrReturned = (identifier, body, context) => {
|
|
|
6206
6106
|
const { name } = identifier;
|
|
6207
6107
|
for (const node of body) {
|
|
6208
6108
|
if (node.range[0] <= identifier.range[0]) continue;
|
|
6209
|
-
if (node.type ===
|
|
6210
|
-
if (node.type ===
|
|
6211
|
-
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) {
|
|
6212
6112
|
if (isValueAwaitedInArguments(name, node.expression)) return true;
|
|
6213
6113
|
const leftMostCall = getLeftMostCallExpression(node.expression);
|
|
6214
6114
|
const vitestFnCall = parseVitestFnCall(node.expression, context);
|
|
@@ -6219,20 +6119,20 @@ const isValueAwaitedOrReturned = (identifier, body, context) => {
|
|
|
6219
6119
|
})) return true;
|
|
6220
6120
|
}
|
|
6221
6121
|
}
|
|
6222
|
-
if (node.expression.type ===
|
|
6223
|
-
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) {
|
|
6224
6124
|
if (isIdentifier(node.expression.left, name) && getNodeName(node.expression.right)?.startsWith(`${name}.`) && isPromiseChainCall(node.expression.right)) continue;
|
|
6225
6125
|
break;
|
|
6226
6126
|
}
|
|
6227
6127
|
}
|
|
6228
|
-
if (node.type ===
|
|
6128
|
+
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement && isValueAwaitedOrReturned(identifier, node.body, context)) return true;
|
|
6229
6129
|
}
|
|
6230
6130
|
return false;
|
|
6231
6131
|
};
|
|
6232
6132
|
const findFirstBlockBodyUp = (node) => {
|
|
6233
6133
|
let parent = node;
|
|
6234
6134
|
while (parent) {
|
|
6235
|
-
if (parent.type ===
|
|
6135
|
+
if (parent.type === _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement) return parent.body;
|
|
6236
6136
|
parent = parent.parent;
|
|
6237
6137
|
}
|
|
6238
6138
|
/* istanbul ignore next */
|
|
@@ -6243,7 +6143,7 @@ const isDirectlyWithinTestCaseCall = (node, context) => {
|
|
|
6243
6143
|
while (parent) {
|
|
6244
6144
|
if (isFunction(parent)) {
|
|
6245
6145
|
parent = parent.parent;
|
|
6246
|
-
return parent?.type ===
|
|
6146
|
+
return parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression && isTypeOfVitestFnCall(parent, context, ["test"]);
|
|
6247
6147
|
}
|
|
6248
6148
|
parent = parent.parent;
|
|
6249
6149
|
}
|
|
@@ -6262,12 +6162,6 @@ var valid_expect_in_promise_default = createEslintRule({
|
|
|
6262
6162
|
type: "suggestion",
|
|
6263
6163
|
schema: []
|
|
6264
6164
|
},
|
|
6265
|
-
defaultOptions: [{
|
|
6266
|
-
alwaysAwait: false,
|
|
6267
|
-
asyncMatchers: defaultAsyncMatchers$1,
|
|
6268
|
-
minArgs: 1,
|
|
6269
|
-
maxArgs: 1
|
|
6270
|
-
}],
|
|
6271
6165
|
create(context) {
|
|
6272
6166
|
let inTestCaseWithDoneCallback = false;
|
|
6273
6167
|
const chains = [];
|
|
@@ -6293,15 +6187,15 @@ var valid_expect_in_promise_default = createEslintRule({
|
|
|
6293
6187
|
const { parent } = findTopMostCallExpression(node);
|
|
6294
6188
|
if (!parent || !isDirectlyWithinTestCaseCall(parent, context)) return;
|
|
6295
6189
|
switch (parent.type) {
|
|
6296
|
-
case
|
|
6190
|
+
case _typescript_eslint_utils.AST_NODE_TYPES.VariableDeclarator:
|
|
6297
6191
|
if (isVariableAwaitedOrReturned(parent, context)) return;
|
|
6298
6192
|
break;
|
|
6299
|
-
case
|
|
6300
|
-
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;
|
|
6301
6195
|
break;
|
|
6302
|
-
case
|
|
6303
|
-
case
|
|
6304
|
-
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:
|
|
6305
6199
|
default: return;
|
|
6306
6200
|
}
|
|
6307
6201
|
context.report({
|
|
@@ -6325,29 +6219,29 @@ const defaultAsyncMatchers = ["toReject", "toResolve"];
|
|
|
6325
6219
|
* @Returns CallExpressionNode
|
|
6326
6220
|
*/
|
|
6327
6221
|
const getPromiseCallExpressionNode = (node) => {
|
|
6328
|
-
if (node.type ===
|
|
6329
|
-
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;
|
|
6330
6224
|
return null;
|
|
6331
6225
|
};
|
|
6332
6226
|
const promiseArrayExceptionKey = ({ start, end }) => `${start.line}:${start.column}-${end.line}:${end.column}`;
|
|
6333
6227
|
const getNormalizeFunctionExpression = (functionExpression) => {
|
|
6334
|
-
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;
|
|
6335
6229
|
return functionExpression;
|
|
6336
6230
|
};
|
|
6337
6231
|
function getParentIfThenified(node) {
|
|
6338
6232
|
const grandParentNode = node.parent?.parent;
|
|
6339
|
-
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);
|
|
6340
6234
|
return node;
|
|
6341
6235
|
}
|
|
6342
|
-
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;
|
|
6343
6237
|
const findFirstFunctionExpression = ({ parent }) => {
|
|
6344
6238
|
if (!parent) return null;
|
|
6345
6239
|
return isFunction(parent) ? parent : findFirstFunctionExpression(parent);
|
|
6346
6240
|
};
|
|
6347
6241
|
const isAcceptableReturnNode = (node, allowReturn) => {
|
|
6348
|
-
if (allowReturn && node.type ===
|
|
6349
|
-
if (node.type ===
|
|
6350
|
-
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);
|
|
6351
6245
|
};
|
|
6352
6246
|
var valid_expect_default = createEslintRule({
|
|
6353
6247
|
name: RULE_NAME$4,
|
|
@@ -6370,10 +6264,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6370
6264
|
schema: [{
|
|
6371
6265
|
type: "object",
|
|
6372
6266
|
properties: {
|
|
6373
|
-
alwaysAwait: {
|
|
6374
|
-
type: "boolean",
|
|
6375
|
-
default: false
|
|
6376
|
-
},
|
|
6267
|
+
alwaysAwait: { type: "boolean" },
|
|
6377
6268
|
asyncMatchers: {
|
|
6378
6269
|
type: "array",
|
|
6379
6270
|
items: { type: "string" }
|
|
@@ -6388,14 +6279,14 @@ var valid_expect_default = createEslintRule({
|
|
|
6388
6279
|
}
|
|
6389
6280
|
},
|
|
6390
6281
|
additionalProperties: false
|
|
6282
|
+
}],
|
|
6283
|
+
defaultOptions: [{
|
|
6284
|
+
alwaysAwait: false,
|
|
6285
|
+
asyncMatchers: defaultAsyncMatchers,
|
|
6286
|
+
minArgs: 1,
|
|
6287
|
+
maxArgs: 1
|
|
6391
6288
|
}]
|
|
6392
6289
|
},
|
|
6393
|
-
defaultOptions: [{
|
|
6394
|
-
alwaysAwait: false,
|
|
6395
|
-
asyncMatchers: defaultAsyncMatchers,
|
|
6396
|
-
minArgs: 1,
|
|
6397
|
-
maxArgs: 1
|
|
6398
|
-
}],
|
|
6399
6290
|
create: (context, [{ alwaysAwait, asyncMatchers = defaultAsyncMatchers, minArgs = 1, maxArgs = 1 }]) => {
|
|
6400
6291
|
const arrayExceptions = /* @__PURE__ */ new Set();
|
|
6401
6292
|
const descriptors = [];
|
|
@@ -6412,7 +6303,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6412
6303
|
let topMostMemberExpression = node;
|
|
6413
6304
|
let { parent } = node;
|
|
6414
6305
|
while (parent) {
|
|
6415
|
-
if (parent.type !==
|
|
6306
|
+
if (parent.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) break;
|
|
6416
6307
|
topMostMemberExpression = parent;
|
|
6417
6308
|
parent = parent.parent;
|
|
6418
6309
|
}
|
|
@@ -6423,7 +6314,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6423
6314
|
const vitestFnCall = parseVitestFnCallWithReason(node, context);
|
|
6424
6315
|
const settings = parsePluginSettings(context.settings);
|
|
6425
6316
|
if (typeof vitestFnCall === "string") {
|
|
6426
|
-
const reportingNode = node.parent?.type ===
|
|
6317
|
+
const reportingNode = node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression ? findTopMostMemberExpression(node.parent).property : node;
|
|
6427
6318
|
if (vitestFnCall === "matcher-not-found") {
|
|
6428
6319
|
context.report({
|
|
6429
6320
|
messageId: "matcherNotFound",
|
|
@@ -6445,9 +6336,9 @@ var valid_expect_default = createEslintRule({
|
|
|
6445
6336
|
return;
|
|
6446
6337
|
} else if (vitestFnCall?.type === "expectTypeOf" && settings.typecheck) return;
|
|
6447
6338
|
else if (vitestFnCall?.type !== "expect") return;
|
|
6448
|
-
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;
|
|
6449
6340
|
const { parent: expect } = vitestFnCall.head.node;
|
|
6450
|
-
if (expect?.type !==
|
|
6341
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
6451
6342
|
if (expect.arguments.length < minArgs) {
|
|
6452
6343
|
const expectLength = getAccessorValue(vitestFnCall.head.node).length;
|
|
6453
6344
|
const loc = {
|
|
@@ -6472,8 +6363,8 @@ var valid_expect_default = createEslintRule({
|
|
|
6472
6363
|
}
|
|
6473
6364
|
if (expect.arguments.length > maxArgs) {
|
|
6474
6365
|
if (expect.arguments.length === 2) {
|
|
6475
|
-
const isSecondArgString = expect.arguments[1].type ===
|
|
6476
|
-
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;
|
|
6477
6368
|
if (isSecondArgString || isSecondArgTemplateLiteral) return;
|
|
6478
6369
|
}
|
|
6479
6370
|
const { start } = expect.arguments[maxArgs].loc;
|
|
@@ -6499,7 +6390,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6499
6390
|
const parentNode = matcher.parent.parent;
|
|
6500
6391
|
const shouldBeAwaited = vitestFnCall.modifiers.some((nod) => getAccessorValue(nod) !== "not") || asyncMatchers.includes(getAccessorValue(matcher));
|
|
6501
6392
|
if (!parentNode?.parent || !shouldBeAwaited) return;
|
|
6502
|
-
const isParentArrayExpression = parentNode.parent.type ===
|
|
6393
|
+
const isParentArrayExpression = parentNode.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrayExpression;
|
|
6503
6394
|
const targetNode = getParentIfThenified(parentNode);
|
|
6504
6395
|
const finalNode = findPromiseCallExpressionNode(targetNode) || targetNode;
|
|
6505
6396
|
if (finalNode.parent && !isAcceptableReturnNode(finalNode.parent, !alwaysAwait) && !promiseArrayExceptionExists(finalNode.loc)) {
|
|
@@ -6527,7 +6418,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6527
6418
|
const targetFunction = getNormalizeFunctionExpression(functionExpression);
|
|
6528
6419
|
fixes.push(fixer.insertTextBefore(targetFunction, "async "));
|
|
6529
6420
|
}
|
|
6530
|
-
const returnStatement = node.parent?.type ===
|
|
6421
|
+
const returnStatement = node.parent?.type === _typescript_eslint_utils.AST_NODE_TYPES.ReturnStatement ? node.parent : null;
|
|
6531
6422
|
if (alwaysAwait && returnStatement) {
|
|
6532
6423
|
const replacedText = context.sourceCode.getText(returnStatement).replace("return", "await");
|
|
6533
6424
|
fixes.push(fixer.replaceText(returnStatement, replacedText));
|
|
@@ -6545,7 +6436,7 @@ var valid_expect_default = createEslintRule({
|
|
|
6545
6436
|
//#region src/rules/valid-title.ts
|
|
6546
6437
|
const RULE_NAME$3 = "valid-title";
|
|
6547
6438
|
const trimFXPrefix = (word) => ["f", "x"].includes(word.charAt(0)) ? word.substring(1) : word;
|
|
6548
|
-
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;
|
|
6549
6440
|
const MatcherAndMessageSchema = {
|
|
6550
6441
|
type: "array",
|
|
6551
6442
|
items: { type: "string" },
|
|
@@ -6578,7 +6469,7 @@ const compileMatcherPatterns = (matchers) => {
|
|
|
6578
6469
|
};
|
|
6579
6470
|
const doesBinaryExpressionContainStringNode = (binaryExp) => {
|
|
6580
6471
|
if (isStringNode(binaryExp.right)) return true;
|
|
6581
|
-
if (binaryExp.left.type ===
|
|
6472
|
+
if (binaryExp.left.type === _typescript_eslint_utils.AST_NODE_TYPES.BinaryExpression) return doesBinaryExpressionContainStringNode(binaryExp.left);
|
|
6582
6473
|
return isStringNode(binaryExp.left);
|
|
6583
6474
|
};
|
|
6584
6475
|
var valid_title_default = createEslintRule({
|
|
@@ -6603,14 +6494,8 @@ var valid_title_default = createEslintRule({
|
|
|
6603
6494
|
schema: [{
|
|
6604
6495
|
type: "object",
|
|
6605
6496
|
properties: {
|
|
6606
|
-
ignoreTypeOfDescribeName: {
|
|
6607
|
-
|
|
6608
|
-
default: false
|
|
6609
|
-
},
|
|
6610
|
-
allowArguments: {
|
|
6611
|
-
type: "boolean",
|
|
6612
|
-
default: false
|
|
6613
|
-
},
|
|
6497
|
+
ignoreTypeOfDescribeName: { type: "boolean" },
|
|
6498
|
+
allowArguments: { type: "boolean" },
|
|
6614
6499
|
disallowedWords: {
|
|
6615
6500
|
type: "array",
|
|
6616
6501
|
items: { type: "string" }
|
|
@@ -6634,14 +6519,13 @@ var valid_title_default = createEslintRule({
|
|
|
6634
6519
|
] } },
|
|
6635
6520
|
additionalProperties: false
|
|
6636
6521
|
}],
|
|
6637
|
-
defaultOptions: [
|
|
6522
|
+
defaultOptions: [{
|
|
6523
|
+
ignoreTypeOfDescribeName: false,
|
|
6524
|
+
allowArguments: false,
|
|
6525
|
+
disallowedWords: []
|
|
6526
|
+
}],
|
|
6638
6527
|
fixable: "code"
|
|
6639
6528
|
},
|
|
6640
|
-
defaultOptions: [{
|
|
6641
|
-
ignoreTypeOfDescribeName: false,
|
|
6642
|
-
allowArguments: false,
|
|
6643
|
-
disallowedWords: []
|
|
6644
|
-
}],
|
|
6645
6529
|
create(context, [{ ignoreTypeOfDescribeName, allowArguments, disallowedWords = [], mustNotMatch, mustMatch }]) {
|
|
6646
6530
|
const disallowedWordsRegexp = new RegExp(`\\b(${disallowedWords.join("|")})\\b`, "iu");
|
|
6647
6531
|
const mustNotMatchPatterns = compileMatcherPatterns(mustNotMatch ?? {});
|
|
@@ -6651,24 +6535,24 @@ var valid_title_default = createEslintRule({
|
|
|
6651
6535
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
6652
6536
|
if (vitestFnCall?.type !== "describe" && vitestFnCall?.type !== "test" && vitestFnCall?.type !== "it") return;
|
|
6653
6537
|
if (vitestFnCall.members.some((member) => ["extend", "scoped"].includes(getAccessorValue(member)))) return;
|
|
6654
|
-
const reportEmptyTitle = (node
|
|
6538
|
+
const reportEmptyTitle = (node) => {
|
|
6655
6539
|
context.report({
|
|
6656
6540
|
messageId: "emptyTitle",
|
|
6657
6541
|
data: { functionName: vitestFnCall.type === "describe" ? DescribeAlias.describe : TestCaseName.test },
|
|
6658
|
-
node
|
|
6542
|
+
node
|
|
6659
6543
|
});
|
|
6660
6544
|
};
|
|
6661
6545
|
const [argument] = node.arguments;
|
|
6662
6546
|
const getArgumentType = () => {
|
|
6663
6547
|
if (!settings.typecheck) return null;
|
|
6664
|
-
return
|
|
6548
|
+
return _typescript_eslint_utils.ESLintUtils.getParserServices(context).getTypeAtLocation(argument);
|
|
6665
6549
|
};
|
|
6666
6550
|
const type = getArgumentType();
|
|
6667
6551
|
if (type && isClassOrFunctionType(type)) return;
|
|
6668
|
-
if (!argument || allowArguments && argument.type ===
|
|
6552
|
+
if (!argument || allowArguments && argument.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
|
|
6669
6553
|
if (!isStringNode(argument)) {
|
|
6670
|
-
if (argument.type ===
|
|
6671
|
-
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({
|
|
6672
6556
|
messageId: "titleMustBeString",
|
|
6673
6557
|
loc: argument.loc
|
|
6674
6558
|
});
|
|
@@ -6748,7 +6632,6 @@ var warn_todo_default = createEslintRule({
|
|
|
6748
6632
|
type: "suggestion",
|
|
6749
6633
|
schema: []
|
|
6750
6634
|
},
|
|
6751
|
-
defaultOptions: [],
|
|
6752
6635
|
create(context) {
|
|
6753
6636
|
return { CallExpression(node) {
|
|
6754
6637
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
@@ -6768,10 +6651,10 @@ var warn_todo_default = createEslintRule({
|
|
|
6768
6651
|
const RULE_NAME$1 = "no-unneeded-async-expect-function";
|
|
6769
6652
|
const getAwaitedCallExpression = (expression) => {
|
|
6770
6653
|
if (!expression.async) return null;
|
|
6771
|
-
if (expression.type ===
|
|
6772
|
-
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;
|
|
6773
6656
|
const [callback] = expression.body.body;
|
|
6774
|
-
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;
|
|
6775
6658
|
return null;
|
|
6776
6659
|
};
|
|
6777
6660
|
var no_unneeded_async_expect_function_default = createEslintRule({
|
|
@@ -6783,13 +6666,12 @@ var no_unneeded_async_expect_function_default = createEslintRule({
|
|
|
6783
6666
|
schema: [],
|
|
6784
6667
|
type: "suggestion"
|
|
6785
6668
|
},
|
|
6786
|
-
defaultOptions: [],
|
|
6787
6669
|
create(context) {
|
|
6788
6670
|
return { CallExpression(node) {
|
|
6789
6671
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
6790
6672
|
if (vitestFnCall?.type !== "expect") return;
|
|
6791
6673
|
const { parent } = vitestFnCall.head.node;
|
|
6792
|
-
if (parent?.type !==
|
|
6674
|
+
if (parent?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
6793
6675
|
const [awaitNode] = parent.arguments;
|
|
6794
6676
|
if (!awaitNode || !isFunction(awaitNode)) return;
|
|
6795
6677
|
const innerAsyncFuncCall = getAwaitedCallExpression(awaitNode);
|
|
@@ -6818,19 +6700,18 @@ var prefer_to_have_been_called_times_default = createEslintRule({
|
|
|
6818
6700
|
type: "suggestion",
|
|
6819
6701
|
schema: []
|
|
6820
6702
|
},
|
|
6821
|
-
defaultOptions: [],
|
|
6822
6703
|
create(context) {
|
|
6823
6704
|
return { CallExpression(node) {
|
|
6824
6705
|
const vitestFnCall = parseVitestFnCall(node, context);
|
|
6825
6706
|
if (vitestFnCall?.type !== "expect") return;
|
|
6826
6707
|
const { parent: expect } = vitestFnCall.head.node;
|
|
6827
|
-
if (expect?.type !==
|
|
6708
|
+
if (expect?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return;
|
|
6828
6709
|
const { matcher } = vitestFnCall;
|
|
6829
6710
|
if (!isSupportedAccessor(matcher, "toHaveLength")) return;
|
|
6830
6711
|
const [argument] = expect.arguments;
|
|
6831
|
-
if (argument?.type !==
|
|
6712
|
+
if (argument?.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || !isSupportedAccessor(argument.property, "calls")) return;
|
|
6832
6713
|
const { object } = argument;
|
|
6833
|
-
if (object.type !==
|
|
6714
|
+
if (object.type !== _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression || !isSupportedAccessor(object.property, "mock")) return;
|
|
6834
6715
|
context.report({
|
|
6835
6716
|
messageId: "preferMatcher",
|
|
6836
6717
|
node: matcher,
|
|
@@ -6930,18 +6811,18 @@ const rules = {
|
|
|
6930
6811
|
|
|
6931
6812
|
//#endregion
|
|
6932
6813
|
//#region src/index.ts
|
|
6933
|
-
const createConfig = (rules
|
|
6814
|
+
const createConfig = (rules) => Object.keys(rules).reduce((acc, ruleName) => {
|
|
6934
6815
|
return {
|
|
6935
6816
|
...acc,
|
|
6936
|
-
[`vitest/${ruleName}`]: rules
|
|
6817
|
+
[`vitest/${ruleName}`]: rules[ruleName]
|
|
6937
6818
|
};
|
|
6938
6819
|
}, {});
|
|
6939
|
-
const createConfigLegacy = (rules
|
|
6820
|
+
const createConfigLegacy = (rules) => ({
|
|
6940
6821
|
plugins: ["@vitest"],
|
|
6941
|
-
rules: Object.keys(rules
|
|
6822
|
+
rules: Object.keys(rules).reduce((acc, ruleName) => {
|
|
6942
6823
|
return {
|
|
6943
6824
|
...acc,
|
|
6944
|
-
[`@vitest/${ruleName}`]: rules
|
|
6825
|
+
[`@vitest/${ruleName}`]: rules[ruleName]
|
|
6945
6826
|
};
|
|
6946
6827
|
}, {})
|
|
6947
6828
|
});
|
|
@@ -7110,7 +6991,6 @@ const plugin = {
|
|
|
7110
6991
|
}
|
|
7111
6992
|
}
|
|
7112
6993
|
};
|
|
7113
|
-
var src_default = plugin;
|
|
7114
6994
|
|
|
7115
6995
|
//#endregion
|
|
7116
|
-
module.exports =
|
|
6996
|
+
module.exports = plugin;
|