@lvce-editor/eslint-plugin-e2e 13.2.0 → 13.4.0
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.js +86 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const meta$
|
|
1
|
+
const meta$5 = {
|
|
2
2
|
docs: {
|
|
3
3
|
description: 'Disallow direct click calls in E2E tests'
|
|
4
4
|
},
|
|
@@ -10,7 +10,7 @@ const meta$4 = {
|
|
|
10
10
|
const isDirectClickCall = node => {
|
|
11
11
|
return node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'click';
|
|
12
12
|
};
|
|
13
|
-
const create$
|
|
13
|
+
const create$5 = context => {
|
|
14
14
|
return {
|
|
15
15
|
CallExpression(node) {
|
|
16
16
|
if (!isDirectClickCall(node)) {
|
|
@@ -26,11 +26,11 @@ const create$4 = context => {
|
|
|
26
26
|
|
|
27
27
|
const noDirectClick = {
|
|
28
28
|
__proto__: null,
|
|
29
|
-
create: create$
|
|
30
|
-
meta: meta$
|
|
29
|
+
create: create$5,
|
|
30
|
+
meta: meta$5
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const meta$
|
|
33
|
+
const meta$4 = {
|
|
34
34
|
docs: {
|
|
35
35
|
description: 'Disallow inline locator expressions inside expect calls'
|
|
36
36
|
},
|
|
@@ -42,7 +42,7 @@ const meta$3 = {
|
|
|
42
42
|
const isCallExpressionNode$2 = node => {
|
|
43
43
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'CallExpression' && 'callee' in node && 'arguments' in node;
|
|
44
44
|
};
|
|
45
|
-
const isIdentifierNode$
|
|
45
|
+
const isIdentifierNode$3 = node => {
|
|
46
46
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
|
|
47
47
|
};
|
|
48
48
|
const isMemberExpressionNode$2 = node => {
|
|
@@ -58,7 +58,7 @@ const isTsNonNullExpression = node => {
|
|
|
58
58
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
|
|
59
59
|
};
|
|
60
60
|
const isLocatorCall = node => {
|
|
61
|
-
return isCallExpressionNode$2(node) && isIdentifierNode$
|
|
61
|
+
return isCallExpressionNode$2(node) && isIdentifierNode$3(node.callee) && node.callee.name === 'Locator';
|
|
62
62
|
};
|
|
63
63
|
const containsInlineLocatorCall = node => {
|
|
64
64
|
if (!node) {
|
|
@@ -87,7 +87,7 @@ const containsInlineLocatorCall = node => {
|
|
|
87
87
|
const isExpectCall$1 = node => {
|
|
88
88
|
return node.callee.type === 'Identifier' && node.callee.name === 'expect';
|
|
89
89
|
};
|
|
90
|
-
const create$
|
|
90
|
+
const create$4 = context => {
|
|
91
91
|
return {
|
|
92
92
|
CallExpression(node) {
|
|
93
93
|
if (!isExpectCall$1(node)) {
|
|
@@ -107,11 +107,11 @@ const create$3 = context => {
|
|
|
107
107
|
|
|
108
108
|
const noInlineLocatorInExpect = {
|
|
109
109
|
__proto__: null,
|
|
110
|
-
create: create$
|
|
111
|
-
meta: meta$
|
|
110
|
+
create: create$4,
|
|
111
|
+
meta: meta$4
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
const meta$
|
|
114
|
+
const meta$3 = {
|
|
115
115
|
docs: {
|
|
116
116
|
description: 'Disallow inline nth locator expressions inside expect calls'
|
|
117
117
|
},
|
|
@@ -123,7 +123,7 @@ const meta$2 = {
|
|
|
123
123
|
const isCallExpressionNode$1 = node => {
|
|
124
124
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'CallExpression' && 'callee' in node && 'arguments' in node;
|
|
125
125
|
};
|
|
126
|
-
const isIdentifierNode$
|
|
126
|
+
const isIdentifierNode$2 = node => {
|
|
127
127
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
|
|
128
128
|
};
|
|
129
129
|
const isMemberExpressionNode$1 = node => {
|
|
@@ -142,7 +142,7 @@ const isTsNonNullExpressionNode$1 = node => {
|
|
|
142
142
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
|
|
143
143
|
};
|
|
144
144
|
const isNthCall$1 = node => {
|
|
145
|
-
return isCallExpressionNode$1(node) && isMemberExpressionNode$1(node.callee) && !node.callee.computed && isIdentifierNode$
|
|
145
|
+
return isCallExpressionNode$1(node) && isMemberExpressionNode$1(node.callee) && !node.callee.computed && isIdentifierNode$2(node.callee.property) && node.callee.property.name === 'nth';
|
|
146
146
|
};
|
|
147
147
|
const containsInlineNthCall = node => {
|
|
148
148
|
if (!node) {
|
|
@@ -174,7 +174,7 @@ const containsInlineNthCall = node => {
|
|
|
174
174
|
const isExpectCall = node => {
|
|
175
175
|
return node.callee.type === 'Identifier' && node.callee.name === 'expect';
|
|
176
176
|
};
|
|
177
|
-
const create$
|
|
177
|
+
const create$3 = context => {
|
|
178
178
|
return {
|
|
179
179
|
CallExpression(node) {
|
|
180
180
|
if (!isExpectCall(node)) {
|
|
@@ -194,11 +194,11 @@ const create$2 = context => {
|
|
|
194
194
|
|
|
195
195
|
const noInlineNthInExpect = {
|
|
196
196
|
__proto__: null,
|
|
197
|
-
create: create$
|
|
198
|
-
meta: meta$
|
|
197
|
+
create: create$3,
|
|
198
|
+
meta: meta$3
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
-
const meta$
|
|
201
|
+
const meta$2 = {
|
|
202
202
|
docs: {
|
|
203
203
|
description: 'Disallow lazy nth-based variable names for locator variables'
|
|
204
204
|
},
|
|
@@ -208,10 +208,10 @@ const meta$1 = {
|
|
|
208
208
|
type: 'problem'
|
|
209
209
|
};
|
|
210
210
|
const lazyNthVariableNamePattern = /nth\d+/i;
|
|
211
|
-
const isIdentifierNode = node => {
|
|
211
|
+
const isIdentifierNode$1 = node => {
|
|
212
212
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
|
|
213
213
|
};
|
|
214
|
-
const isVariableDeclaratorNode = node => {
|
|
214
|
+
const isVariableDeclaratorNode$1 = node => {
|
|
215
215
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'VariableDeclarator' && 'id' in node && 'init' in node;
|
|
216
216
|
};
|
|
217
217
|
const isCallExpressionNode = node => {
|
|
@@ -230,7 +230,7 @@ const isTsNonNullExpressionNode = node => {
|
|
|
230
230
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
|
|
231
231
|
};
|
|
232
232
|
const isNthCall = node => {
|
|
233
|
-
return isCallExpressionNode(node) && isMemberExpressionNode(node.callee) && !node.callee.computed && isIdentifierNode(node.callee.property) && node.callee.property.name === 'nth';
|
|
233
|
+
return isCallExpressionNode(node) && isMemberExpressionNode(node.callee) && !node.callee.computed && isIdentifierNode$1(node.callee.property) && node.callee.property.name === 'nth';
|
|
234
234
|
};
|
|
235
235
|
const containsNthCall = node => {
|
|
236
236
|
if (!node) {
|
|
@@ -257,12 +257,12 @@ const containsNthCall = node => {
|
|
|
257
257
|
return false;
|
|
258
258
|
};
|
|
259
259
|
const hasLazyNthVariableName = node => {
|
|
260
|
-
return isIdentifierNode(node) && lazyNthVariableNamePattern.test(node.name);
|
|
260
|
+
return isIdentifierNode$1(node) && lazyNthVariableNamePattern.test(node.name);
|
|
261
261
|
};
|
|
262
|
-
const create$
|
|
262
|
+
const create$2 = context => {
|
|
263
263
|
return {
|
|
264
264
|
VariableDeclarator(node) {
|
|
265
|
-
if (!isVariableDeclaratorNode(node)) {
|
|
265
|
+
if (!isVariableDeclaratorNode$1(node)) {
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
268
|
if (!hasLazyNthVariableName(node.id)) {
|
|
@@ -280,6 +280,67 @@ const create$1 = context => {
|
|
|
280
280
|
};
|
|
281
281
|
|
|
282
282
|
const noLazyNthVariableName = {
|
|
283
|
+
__proto__: null,
|
|
284
|
+
create: create$2,
|
|
285
|
+
meta: meta$2
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const meta$1 = {
|
|
289
|
+
docs: {
|
|
290
|
+
description: 'Prefer destructuring e2e test api parameters directly'
|
|
291
|
+
},
|
|
292
|
+
messages: {
|
|
293
|
+
preferDirectApiDestructuring: 'Destructure the e2e test api in the parameter list instead of from api inside the function body.'
|
|
294
|
+
},
|
|
295
|
+
type: 'problem'
|
|
296
|
+
};
|
|
297
|
+
const isIdentifierNode = node => {
|
|
298
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
|
|
299
|
+
};
|
|
300
|
+
const isObjectPatternNode = node => {
|
|
301
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'ObjectPattern';
|
|
302
|
+
};
|
|
303
|
+
const isVariableDeclaratorNode = node => {
|
|
304
|
+
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'VariableDeclarator' && 'id' in node && 'init' in node;
|
|
305
|
+
};
|
|
306
|
+
const getParameterNames = node => {
|
|
307
|
+
return node.params.filter(isIdentifierNode).map(param => param.name);
|
|
308
|
+
};
|
|
309
|
+
const create$1 = context => {
|
|
310
|
+
const functionParameterNames = [];
|
|
311
|
+
const enterFunction = node => {
|
|
312
|
+
functionParameterNames.push([...getParameterNames(node)]);
|
|
313
|
+
};
|
|
314
|
+
const exitFunction = () => {
|
|
315
|
+
functionParameterNames.pop();
|
|
316
|
+
};
|
|
317
|
+
return {
|
|
318
|
+
ArrowFunctionExpression: enterFunction,
|
|
319
|
+
'ArrowFunctionExpression:exit': exitFunction,
|
|
320
|
+
FunctionDeclaration: enterFunction,
|
|
321
|
+
'FunctionDeclaration:exit': exitFunction,
|
|
322
|
+
FunctionExpression: enterFunction,
|
|
323
|
+
'FunctionExpression:exit': exitFunction,
|
|
324
|
+
VariableDeclarator(node) {
|
|
325
|
+
if (!isVariableDeclaratorNode(node)) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (!isObjectPatternNode(node.id) || !isIdentifierNode(node.init)) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const currentFunctionParameterNames = functionParameterNames.at(-1);
|
|
332
|
+
if (!currentFunctionParameterNames?.includes(node.init.name)) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
context.report({
|
|
336
|
+
messageId: 'preferDirectApiDestructuring',
|
|
337
|
+
node: node.id
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const preferDirectApiDestructuring = {
|
|
283
344
|
__proto__: null,
|
|
284
345
|
create: create$1,
|
|
285
346
|
meta: meta$1
|
|
@@ -340,6 +401,7 @@ const plugin = {
|
|
|
340
401
|
'no-inline-locator-in-expect': noInlineLocatorInExpect,
|
|
341
402
|
'no-inline-nth-in-expect': noInlineNthInExpect,
|
|
342
403
|
'no-lazy-nth-variable-name': noLazyNthVariableName,
|
|
404
|
+
'prefer-direct-api-destructuring': preferDirectApiDestructuring,
|
|
343
405
|
'prefer-import-meta-resolve': preferImportMetaResolve
|
|
344
406
|
}
|
|
345
407
|
};
|
|
@@ -353,6 +415,7 @@ const recommended = [{
|
|
|
353
415
|
'e2e/no-inline-locator-in-expect': 'error',
|
|
354
416
|
'e2e/no-inline-nth-in-expect': 'error',
|
|
355
417
|
'e2e/no-lazy-nth-variable-name': 'error',
|
|
418
|
+
'e2e/prefer-direct-api-destructuring': 'error',
|
|
356
419
|
'e2e/prefer-import-meta-resolve': 'error'
|
|
357
420
|
}
|
|
358
421
|
}];
|