@vitest/eslint-plugin 1.1.18 → 1.1.19
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 +18 -14
- package/dist/index.mjs +18 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ function _interopNamespaceCompat(e) {
|
|
|
23
23
|
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
24
24
|
const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
|
|
25
25
|
|
|
26
|
-
const version = "1.1.
|
|
26
|
+
const version = "1.1.18";
|
|
27
27
|
|
|
28
28
|
function createEslintRule(rule) {
|
|
29
29
|
const createRule = utils.ESLintUtils.RuleCreator(
|
|
@@ -300,6 +300,10 @@ const resolvePossibleAliasedGlobal = (global, context) => {
|
|
|
300
300
|
return alias[0];
|
|
301
301
|
return null;
|
|
302
302
|
};
|
|
303
|
+
const isAncestorTestCaseCall = ({ parent }) => {
|
|
304
|
+
if (parent?.type === utils.AST_NODE_TYPES.CallExpression && parent.callee.type === utils.AST_NODE_TYPES.Identifier)
|
|
305
|
+
return TestCaseName.hasOwnProperty(parent.callee.name);
|
|
306
|
+
};
|
|
303
307
|
const resolveScope = (scope, identifier) => {
|
|
304
308
|
let currentScope = scope;
|
|
305
309
|
while (currentScope !== null) {
|
|
@@ -314,7 +318,7 @@ const resolveScope = (scope, identifier) => {
|
|
|
314
318
|
return "testContext";
|
|
315
319
|
}
|
|
316
320
|
const namedParam = isFunction(def.node) ? def.node.params.find((params) => params.type === utils.AST_NODE_TYPES.Identifier) : void 0;
|
|
317
|
-
if (namedParam)
|
|
321
|
+
if (namedParam && isAncestorTestCaseCall(namedParam.parent))
|
|
318
322
|
return "testContext";
|
|
319
323
|
const importDetails = describePossibleImportDef(def);
|
|
320
324
|
if (importDetails?.local === identifier)
|
|
@@ -1060,7 +1064,7 @@ const noHooks = createEslintRule({
|
|
|
1060
1064
|
properties: {
|
|
1061
1065
|
allow: {
|
|
1062
1066
|
type: "array",
|
|
1063
|
-
|
|
1067
|
+
// @ts-ignore
|
|
1064
1068
|
contains: ["beforeAll", "beforeEach", "afterAll", "afterEach"]
|
|
1065
1069
|
}
|
|
1066
1070
|
},
|
|
@@ -1150,12 +1154,12 @@ const consistentTestFilename = createEslintRule({
|
|
|
1150
1154
|
additionalProperties: false,
|
|
1151
1155
|
properties: {
|
|
1152
1156
|
pattern: {
|
|
1153
|
-
|
|
1157
|
+
// @ts-ignore
|
|
1154
1158
|
format: "regex",
|
|
1155
1159
|
default: defaultPattern.source
|
|
1156
1160
|
},
|
|
1157
1161
|
allTestPattern: {
|
|
1158
|
-
|
|
1162
|
+
// @ts-ignore
|
|
1159
1163
|
format: "regex",
|
|
1160
1164
|
default: defaultTestsPattern.source
|
|
1161
1165
|
}
|
|
@@ -1942,9 +1946,9 @@ const noStandaloneExpect = createEslintRule({
|
|
|
1942
1946
|
{
|
|
1943
1947
|
properties: {
|
|
1944
1948
|
additionaltestblockfunctions: {
|
|
1945
|
-
|
|
1949
|
+
// @ts-ignore
|
|
1946
1950
|
type: "array",
|
|
1947
|
-
|
|
1951
|
+
// @ts-ignore
|
|
1948
1952
|
items: { type: `string` }
|
|
1949
1953
|
}
|
|
1950
1954
|
},
|
|
@@ -2221,7 +2225,7 @@ const validTitle = createEslintRule({
|
|
|
2221
2225
|
MatcherAndMessageSchema,
|
|
2222
2226
|
{
|
|
2223
2227
|
type: "object",
|
|
2224
|
-
|
|
2228
|
+
// @ts-ignore
|
|
2225
2229
|
propertyNames: { type: "string", enum: ["describe", "test", "it"] },
|
|
2226
2230
|
additionalProperties: {
|
|
2227
2231
|
oneOf: [{ type: "string" }, MatcherAndMessageSchema]
|
|
@@ -3247,7 +3251,7 @@ const preferViMocked = createEslintRule({
|
|
|
3247
3251
|
meta: {
|
|
3248
3252
|
type: "suggestion",
|
|
3249
3253
|
docs: {
|
|
3250
|
-
description: "
|
|
3254
|
+
description: "require `vi.mocked()` over `fn as Mock`",
|
|
3251
3255
|
requiresTypeChecking: true,
|
|
3252
3256
|
recommended: false
|
|
3253
3257
|
},
|
|
@@ -3710,7 +3714,7 @@ const requireLocalTestContextForConcurrentSnapshots = createEslintRule({
|
|
|
3710
3714
|
"toMatchFileSnapshot",
|
|
3711
3715
|
"toThrowErrorMatchingSnapshot",
|
|
3712
3716
|
"toThrowErrorMatchingInlineSnapshot"
|
|
3713
|
-
|
|
3717
|
+
// @ts-ignore
|
|
3714
3718
|
].includes(node.callee?.property.name);
|
|
3715
3719
|
if (isNotASnapshotAssertion)
|
|
3716
3720
|
return;
|
|
@@ -4390,11 +4394,11 @@ const createPaddingRule = (name, description, configs, deprecated = false) => {
|
|
|
4390
4394
|
};
|
|
4391
4395
|
const { scopeInfo } = paddingContext;
|
|
4392
4396
|
return {
|
|
4393
|
-
Program: scopeInfo.enter,
|
|
4397
|
+
"Program": scopeInfo.enter,
|
|
4394
4398
|
"Program:exit": scopeInfo.exit,
|
|
4395
|
-
BlockStatement: scopeInfo.enter,
|
|
4399
|
+
"BlockStatement": scopeInfo.enter,
|
|
4396
4400
|
"BlockStatement:exit": scopeInfo.exit,
|
|
4397
|
-
SwitchStatement: scopeInfo.enter,
|
|
4401
|
+
"SwitchStatement": scopeInfo.enter,
|
|
4398
4402
|
"SwitchStatement:exit": scopeInfo.exit,
|
|
4399
4403
|
":statement": (node) => verifyNode(node, paddingContext),
|
|
4400
4404
|
SwitchCase(node) {
|
|
@@ -4751,7 +4755,7 @@ const validExpectInPromise = createEslintRule({
|
|
|
4751
4755
|
name: RULE_NAME,
|
|
4752
4756
|
meta: {
|
|
4753
4757
|
docs: {
|
|
4754
|
-
description: "
|
|
4758
|
+
description: "require promises that have expectations in their chain to be valid"
|
|
4755
4759
|
},
|
|
4756
4760
|
messages: {
|
|
4757
4761
|
expectInFloatingPromise: "This promise should either be returned or awaited to ensure the expects in its chain are called"
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { isAbsolute, posix } from 'node:path';
|
|
|
4
4
|
import ts from 'typescript';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
|
|
7
|
-
const version = "1.1.
|
|
7
|
+
const version = "1.1.18";
|
|
8
8
|
|
|
9
9
|
function createEslintRule(rule) {
|
|
10
10
|
const createRule = ESLintUtils.RuleCreator(
|
|
@@ -281,6 +281,10 @@ const resolvePossibleAliasedGlobal = (global, context) => {
|
|
|
281
281
|
return alias[0];
|
|
282
282
|
return null;
|
|
283
283
|
};
|
|
284
|
+
const isAncestorTestCaseCall = ({ parent }) => {
|
|
285
|
+
if (parent?.type === AST_NODE_TYPES.CallExpression && parent.callee.type === AST_NODE_TYPES.Identifier)
|
|
286
|
+
return TestCaseName.hasOwnProperty(parent.callee.name);
|
|
287
|
+
};
|
|
284
288
|
const resolveScope = (scope, identifier) => {
|
|
285
289
|
let currentScope = scope;
|
|
286
290
|
while (currentScope !== null) {
|
|
@@ -295,7 +299,7 @@ const resolveScope = (scope, identifier) => {
|
|
|
295
299
|
return "testContext";
|
|
296
300
|
}
|
|
297
301
|
const namedParam = isFunction(def.node) ? def.node.params.find((params) => params.type === AST_NODE_TYPES.Identifier) : void 0;
|
|
298
|
-
if (namedParam)
|
|
302
|
+
if (namedParam && isAncestorTestCaseCall(namedParam.parent))
|
|
299
303
|
return "testContext";
|
|
300
304
|
const importDetails = describePossibleImportDef(def);
|
|
301
305
|
if (importDetails?.local === identifier)
|
|
@@ -1041,7 +1045,7 @@ const noHooks = createEslintRule({
|
|
|
1041
1045
|
properties: {
|
|
1042
1046
|
allow: {
|
|
1043
1047
|
type: "array",
|
|
1044
|
-
|
|
1048
|
+
// @ts-ignore
|
|
1045
1049
|
contains: ["beforeAll", "beforeEach", "afterAll", "afterEach"]
|
|
1046
1050
|
}
|
|
1047
1051
|
},
|
|
@@ -1131,12 +1135,12 @@ const consistentTestFilename = createEslintRule({
|
|
|
1131
1135
|
additionalProperties: false,
|
|
1132
1136
|
properties: {
|
|
1133
1137
|
pattern: {
|
|
1134
|
-
|
|
1138
|
+
// @ts-ignore
|
|
1135
1139
|
format: "regex",
|
|
1136
1140
|
default: defaultPattern.source
|
|
1137
1141
|
},
|
|
1138
1142
|
allTestPattern: {
|
|
1139
|
-
|
|
1143
|
+
// @ts-ignore
|
|
1140
1144
|
format: "regex",
|
|
1141
1145
|
default: defaultTestsPattern.source
|
|
1142
1146
|
}
|
|
@@ -1923,9 +1927,9 @@ const noStandaloneExpect = createEslintRule({
|
|
|
1923
1927
|
{
|
|
1924
1928
|
properties: {
|
|
1925
1929
|
additionaltestblockfunctions: {
|
|
1926
|
-
|
|
1930
|
+
// @ts-ignore
|
|
1927
1931
|
type: "array",
|
|
1928
|
-
|
|
1932
|
+
// @ts-ignore
|
|
1929
1933
|
items: { type: `string` }
|
|
1930
1934
|
}
|
|
1931
1935
|
},
|
|
@@ -2202,7 +2206,7 @@ const validTitle = createEslintRule({
|
|
|
2202
2206
|
MatcherAndMessageSchema,
|
|
2203
2207
|
{
|
|
2204
2208
|
type: "object",
|
|
2205
|
-
|
|
2209
|
+
// @ts-ignore
|
|
2206
2210
|
propertyNames: { type: "string", enum: ["describe", "test", "it"] },
|
|
2207
2211
|
additionalProperties: {
|
|
2208
2212
|
oneOf: [{ type: "string" }, MatcherAndMessageSchema]
|
|
@@ -3228,7 +3232,7 @@ const preferViMocked = createEslintRule({
|
|
|
3228
3232
|
meta: {
|
|
3229
3233
|
type: "suggestion",
|
|
3230
3234
|
docs: {
|
|
3231
|
-
description: "
|
|
3235
|
+
description: "require `vi.mocked()` over `fn as Mock`",
|
|
3232
3236
|
requiresTypeChecking: true,
|
|
3233
3237
|
recommended: false
|
|
3234
3238
|
},
|
|
@@ -3691,7 +3695,7 @@ const requireLocalTestContextForConcurrentSnapshots = createEslintRule({
|
|
|
3691
3695
|
"toMatchFileSnapshot",
|
|
3692
3696
|
"toThrowErrorMatchingSnapshot",
|
|
3693
3697
|
"toThrowErrorMatchingInlineSnapshot"
|
|
3694
|
-
|
|
3698
|
+
// @ts-ignore
|
|
3695
3699
|
].includes(node.callee?.property.name);
|
|
3696
3700
|
if (isNotASnapshotAssertion)
|
|
3697
3701
|
return;
|
|
@@ -4371,11 +4375,11 @@ const createPaddingRule = (name, description, configs, deprecated = false) => {
|
|
|
4371
4375
|
};
|
|
4372
4376
|
const { scopeInfo } = paddingContext;
|
|
4373
4377
|
return {
|
|
4374
|
-
Program: scopeInfo.enter,
|
|
4378
|
+
"Program": scopeInfo.enter,
|
|
4375
4379
|
"Program:exit": scopeInfo.exit,
|
|
4376
|
-
BlockStatement: scopeInfo.enter,
|
|
4380
|
+
"BlockStatement": scopeInfo.enter,
|
|
4377
4381
|
"BlockStatement:exit": scopeInfo.exit,
|
|
4378
|
-
SwitchStatement: scopeInfo.enter,
|
|
4382
|
+
"SwitchStatement": scopeInfo.enter,
|
|
4379
4383
|
"SwitchStatement:exit": scopeInfo.exit,
|
|
4380
4384
|
":statement": (node) => verifyNode(node, paddingContext),
|
|
4381
4385
|
SwitchCase(node) {
|
|
@@ -4732,7 +4736,7 @@ const validExpectInPromise = createEslintRule({
|
|
|
4732
4736
|
name: RULE_NAME,
|
|
4733
4737
|
meta: {
|
|
4734
4738
|
docs: {
|
|
4735
|
-
description: "
|
|
4739
|
+
description: "require promises that have expectations in their chain to be valid"
|
|
4736
4740
|
},
|
|
4737
4741
|
messages: {
|
|
4738
4742
|
expectInFloatingPromise: "This promise should either be returned or awaited to ensure the expects in its chain are called"
|