@lvce-editor/eslint-plugin-e2e 11.1.0 → 12.0.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 +80 -34
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const meta$
|
|
2
|
-
type: 'problem',
|
|
1
|
+
const meta$4 = {
|
|
3
2
|
docs: {
|
|
4
3
|
description: 'Disallow direct click calls in E2E tests'
|
|
5
4
|
},
|
|
6
5
|
messages: {
|
|
7
6
|
noDirectClick: 'Do not call .click() directly in e2e tests. Use Command.execute(...) or the page object API instead.'
|
|
8
|
-
}
|
|
7
|
+
},
|
|
8
|
+
type: 'problem'
|
|
9
9
|
};
|
|
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$4 = context => {
|
|
14
14
|
return {
|
|
15
15
|
CallExpression(node) {
|
|
16
16
|
if (!isDirectClickCall(node)) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
context.report({
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
messageId: 'noDirectClick',
|
|
21
|
+
node: node.callee.property
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
};
|
|
@@ -26,18 +26,18 @@ const create$3 = context => {
|
|
|
26
26
|
|
|
27
27
|
const noDirectClick = {
|
|
28
28
|
__proto__: null,
|
|
29
|
-
create: create$
|
|
30
|
-
meta: meta$
|
|
29
|
+
create: create$4,
|
|
30
|
+
meta: meta$4
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const meta$
|
|
34
|
-
type: 'problem',
|
|
33
|
+
const meta$3 = {
|
|
35
34
|
docs: {
|
|
36
35
|
description: 'Disallow inline locator expressions inside expect calls'
|
|
37
36
|
},
|
|
38
37
|
messages: {
|
|
39
38
|
noInlineLocatorInExpect: 'Assign the locator to a variable before passing it to expect(...).'
|
|
40
|
-
}
|
|
39
|
+
},
|
|
40
|
+
type: 'problem'
|
|
41
41
|
};
|
|
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;
|
|
@@ -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$3 = context => {
|
|
91
91
|
return {
|
|
92
92
|
CallExpression(node) {
|
|
93
93
|
if (!isExpectCall$1(node)) {
|
|
@@ -98,8 +98,8 @@ const create$2 = context => {
|
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
context.report({
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
messageId: 'noInlineLocatorInExpect',
|
|
102
|
+
node: firstArgument
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
};
|
|
@@ -107,18 +107,18 @@ const create$2 = context => {
|
|
|
107
107
|
|
|
108
108
|
const noInlineLocatorInExpect = {
|
|
109
109
|
__proto__: null,
|
|
110
|
-
create: create$
|
|
111
|
-
meta: meta$
|
|
110
|
+
create: create$3,
|
|
111
|
+
meta: meta$3
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
const meta$
|
|
115
|
-
type: 'problem',
|
|
114
|
+
const meta$2 = {
|
|
116
115
|
docs: {
|
|
117
116
|
description: 'Disallow inline nth locator expressions inside expect calls'
|
|
118
117
|
},
|
|
119
118
|
messages: {
|
|
120
119
|
noInlineNthInExpect: 'Assign the nth locator to a variable before passing it to expect(...).'
|
|
121
|
-
}
|
|
120
|
+
},
|
|
121
|
+
type: 'problem'
|
|
122
122
|
};
|
|
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;
|
|
@@ -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$2 = context => {
|
|
178
178
|
return {
|
|
179
179
|
CallExpression(node) {
|
|
180
180
|
if (!isExpectCall(node)) {
|
|
@@ -185,8 +185,8 @@ const create$1 = context => {
|
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
context.report({
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
messageId: 'noInlineNthInExpect',
|
|
189
|
+
node: firstArgument
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
};
|
|
@@ -194,18 +194,18 @@ const create$1 = context => {
|
|
|
194
194
|
|
|
195
195
|
const noInlineNthInExpect = {
|
|
196
196
|
__proto__: null,
|
|
197
|
-
create: create$
|
|
198
|
-
meta: meta$
|
|
197
|
+
create: create$2,
|
|
198
|
+
meta: meta$2
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
-
const meta = {
|
|
202
|
-
type: 'problem',
|
|
201
|
+
const meta$1 = {
|
|
203
202
|
docs: {
|
|
204
203
|
description: 'Disallow lazy nth-based variable names for locator variables'
|
|
205
204
|
},
|
|
206
205
|
messages: {
|
|
207
206
|
noLazyNthVariableName: 'Prefer a specific variable name like firstRow or row0 over nth-based names like rowsNth0.'
|
|
208
|
-
}
|
|
207
|
+
},
|
|
208
|
+
type: 'problem'
|
|
209
209
|
};
|
|
210
210
|
const lazyNthVariableNamePattern = /nth\d+/i;
|
|
211
211
|
const isIdentifierNode = node => {
|
|
@@ -259,7 +259,7 @@ const containsNthCall = node => {
|
|
|
259
259
|
const hasLazyNthVariableName = node => {
|
|
260
260
|
return isIdentifierNode(node) && lazyNthVariableNamePattern.test(node.name);
|
|
261
261
|
};
|
|
262
|
-
const create = context => {
|
|
262
|
+
const create$1 = context => {
|
|
263
263
|
return {
|
|
264
264
|
VariableDeclarator(node) {
|
|
265
265
|
if (!isVariableDeclaratorNode(node)) {
|
|
@@ -272,20 +272,65 @@ const create = context => {
|
|
|
272
272
|
return;
|
|
273
273
|
}
|
|
274
274
|
context.report({
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
messageId: 'noLazyNthVariableName',
|
|
276
|
+
node: node.id
|
|
277
277
|
});
|
|
278
278
|
}
|
|
279
279
|
};
|
|
280
280
|
};
|
|
281
281
|
|
|
282
282
|
const noLazyNthVariableName = {
|
|
283
|
+
__proto__: null,
|
|
284
|
+
create: create$1,
|
|
285
|
+
meta: meta$1
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const meta = {
|
|
289
|
+
docs: {
|
|
290
|
+
description: 'Prefer import.meta.resolve over new URL(..., import.meta.url).toString()'
|
|
291
|
+
},
|
|
292
|
+
messages: {
|
|
293
|
+
preferImportMetaResolve: 'Use import.meta.resolve(...) instead of new URL(..., import.meta.url).toString().'
|
|
294
|
+
},
|
|
295
|
+
type: 'suggestion'
|
|
296
|
+
};
|
|
297
|
+
const isIdentifier = (node, name) => {
|
|
298
|
+
return node.type === 'Identifier' && node.name === name;
|
|
299
|
+
};
|
|
300
|
+
const isImportMeta = node => {
|
|
301
|
+
return node.type === 'MetaProperty' && isIdentifier(node.meta, 'import') && isIdentifier(node.property, 'meta');
|
|
302
|
+
};
|
|
303
|
+
const isImportMetaUrl = node => {
|
|
304
|
+
return node.type === 'MemberExpression' && !node.computed && isImportMeta(node.object) && isIdentifier(node.property, 'url');
|
|
305
|
+
};
|
|
306
|
+
const isUrlConstructor = node => {
|
|
307
|
+
return node.type === 'NewExpression' && node.callee.type === 'Identifier' && ['URL', 'Url'].includes(node.callee.name) && node.arguments.length >= 2 && isImportMetaUrl(node.arguments[1]);
|
|
308
|
+
};
|
|
309
|
+
const isNewUrlToStringCall = node => {
|
|
310
|
+
return node.callee.type === 'MemberExpression' && !node.callee.computed && isIdentifier(node.callee.property, 'toString') && isUrlConstructor(node.callee.object);
|
|
311
|
+
};
|
|
312
|
+
const create = context => {
|
|
313
|
+
return {
|
|
314
|
+
CallExpression(node) {
|
|
315
|
+
if (!isNewUrlToStringCall(node)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
context.report({
|
|
319
|
+
messageId: 'preferImportMetaResolve',
|
|
320
|
+
node
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const preferImportMetaResolve = {
|
|
283
327
|
__proto__: null,
|
|
284
328
|
create,
|
|
285
329
|
meta
|
|
286
330
|
};
|
|
287
331
|
|
|
288
332
|
const plugin = {
|
|
333
|
+
configs: {},
|
|
289
334
|
meta: {
|
|
290
335
|
name: 'e2e',
|
|
291
336
|
version: '0.0.1'
|
|
@@ -294,9 +339,9 @@ const plugin = {
|
|
|
294
339
|
'no-direct-click': noDirectClick,
|
|
295
340
|
'no-inline-locator-in-expect': noInlineLocatorInExpect,
|
|
296
341
|
'no-inline-nth-in-expect': noInlineNthInExpect,
|
|
297
|
-
'no-lazy-nth-variable-name': noLazyNthVariableName
|
|
298
|
-
|
|
299
|
-
|
|
342
|
+
'no-lazy-nth-variable-name': noLazyNthVariableName,
|
|
343
|
+
'prefer-import-meta-resolve': preferImportMetaResolve
|
|
344
|
+
}
|
|
300
345
|
};
|
|
301
346
|
const recommended = [{
|
|
302
347
|
files: ['**/e2e/**/*.ts'],
|
|
@@ -307,7 +352,8 @@ const recommended = [{
|
|
|
307
352
|
'e2e/no-direct-click': 'error',
|
|
308
353
|
'e2e/no-inline-locator-in-expect': 'error',
|
|
309
354
|
'e2e/no-inline-nth-in-expect': 'error',
|
|
310
|
-
'e2e/no-lazy-nth-variable-name': 'error'
|
|
355
|
+
'e2e/no-lazy-nth-variable-name': 'error',
|
|
356
|
+
'e2e/prefer-import-meta-resolve': 'error'
|
|
311
357
|
}
|
|
312
358
|
}];
|
|
313
359
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/eslint-plugin-e2e",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/lvce-editor/eslint-config.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"keywords": [],
|
|
11
10
|
"license": "MIT",
|
|
12
|
-
"description": ""
|
|
11
|
+
"description": "ESLint rules for end-to-end test code."
|
|
13
12
|
}
|