@lvce-editor/eslint-plugin-e2e 10.1.0 → 10.2.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.
Files changed (2) hide show
  1. package/dist/index.js +123 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const meta$2 = {
1
+ const meta$3 = {
2
2
  type: 'problem',
3
3
  docs: {
4
4
  description: 'Disallow direct click calls in E2E tests'
@@ -10,7 +10,7 @@ const meta$2 = {
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$2 = context => {
13
+ const create$3 = context => {
14
14
  return {
15
15
  CallExpression(node) {
16
16
  if (!isDirectClickCall(node)) {
@@ -26,11 +26,11 @@ const create$2 = context => {
26
26
 
27
27
  const noDirectClick = {
28
28
  __proto__: null,
29
- create: create$2,
30
- meta: meta$2
29
+ create: create$3,
30
+ meta: meta$3
31
31
  };
32
32
 
33
- const meta$1 = {
33
+ const meta$2 = {
34
34
  type: 'problem',
35
35
  docs: {
36
36
  description: 'Disallow inline locator expressions inside expect calls'
@@ -39,16 +39,16 @@ const meta$1 = {
39
39
  noInlineLocatorInExpect: 'Assign the locator to a variable before passing it to expect(...).'
40
40
  }
41
41
  };
42
- const isCallExpressionNode$1 = node => {
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$1 = node => {
45
+ const isIdentifierNode$2 = node => {
46
46
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
47
47
  };
48
- const isMemberExpressionNode$1 = node => {
48
+ const isMemberExpressionNode$2 = node => {
49
49
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'MemberExpression' && 'object' in node && 'property' in node && 'computed' in node;
50
50
  };
51
- const isChainExpressionNode$1 = node => {
51
+ const isChainExpressionNode$2 = node => {
52
52
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'ChainExpression' && 'expression' in node;
53
53
  };
54
54
  const isAwaitExpressionNode$1 = 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$1(node) && isIdentifierNode$1(node.callee) && node.callee.name === 'Locator';
61
+ return isCallExpressionNode$2(node) && isIdentifierNode$2(node.callee) && node.callee.name === 'Locator';
62
62
  };
63
63
  const containsInlineLocatorCall = node => {
64
64
  if (!node) {
@@ -67,13 +67,13 @@ const containsInlineLocatorCall = node => {
67
67
  if (isLocatorCall(node)) {
68
68
  return true;
69
69
  }
70
- if (isCallExpressionNode$1(node)) {
70
+ if (isCallExpressionNode$2(node)) {
71
71
  return containsInlineLocatorCall(node.callee) || node.arguments.some(containsInlineLocatorCall);
72
72
  }
73
- if (isMemberExpressionNode$1(node)) {
73
+ if (isMemberExpressionNode$2(node)) {
74
74
  return containsInlineLocatorCall(node.object) || node.computed && containsInlineLocatorCall(node.property);
75
75
  }
76
- if (isChainExpressionNode$1(node)) {
76
+ if (isChainExpressionNode$2(node)) {
77
77
  return containsInlineLocatorCall(node.expression);
78
78
  }
79
79
  if (isAwaitExpressionNode$1(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$1 = context => {
90
+ const create$2 = context => {
91
91
  return {
92
92
  CallExpression(node) {
93
93
  if (!isExpectCall$1(node)) {
@@ -107,11 +107,11 @@ const create$1 = context => {
107
107
 
108
108
  const noInlineLocatorInExpect = {
109
109
  __proto__: null,
110
- create: create$1,
111
- meta: meta$1
110
+ create: create$2,
111
+ meta: meta$2
112
112
  };
113
113
 
114
- const meta = {
114
+ const meta$1 = {
115
115
  type: 'problem',
116
116
  docs: {
117
117
  description: 'Disallow inline nth locator expressions inside expect calls'
@@ -120,53 +120,53 @@ const meta = {
120
120
  noInlineNthInExpect: 'Assign the nth locator to a variable before passing it to expect(...).'
121
121
  }
122
122
  };
123
- const isCallExpressionNode = node => {
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 = node => {
126
+ const isIdentifierNode$1 = node => {
127
127
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
128
128
  };
129
- const isMemberExpressionNode = node => {
129
+ const isMemberExpressionNode$1 = node => {
130
130
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'MemberExpression' && 'object' in node && 'property' in node && 'computed' in node;
131
131
  };
132
- const isChainExpressionNode = node => {
132
+ const isChainExpressionNode$1 = node => {
133
133
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'ChainExpression' && 'expression' in node;
134
134
  };
135
135
  const isAwaitExpressionNode = node => {
136
136
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'AwaitExpression' && 'argument' in node;
137
137
  };
138
- const isTsAsExpressionNode = node => {
138
+ const isTsAsExpressionNode$1 = node => {
139
139
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSAsExpression' && 'expression' in node;
140
140
  };
141
- const isTsNonNullExpressionNode = node => {
141
+ const isTsNonNullExpressionNode$1 = node => {
142
142
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
143
143
  };
144
- const isNthCall = node => {
145
- return isCallExpressionNode(node) && isMemberExpressionNode(node.callee) && !node.callee.computed && isIdentifierNode(node.callee.property) && node.callee.property.name === 'nth';
144
+ const isNthCall$1 = node => {
145
+ return isCallExpressionNode$1(node) && isMemberExpressionNode$1(node.callee) && !node.callee.computed && isIdentifierNode$1(node.callee.property) && node.callee.property.name === 'nth';
146
146
  };
147
147
  const containsInlineNthCall = node => {
148
148
  if (!node) {
149
149
  return false;
150
150
  }
151
- if (isNthCall(node)) {
151
+ if (isNthCall$1(node)) {
152
152
  return true;
153
153
  }
154
- if (isCallExpressionNode(node)) {
154
+ if (isCallExpressionNode$1(node)) {
155
155
  return containsInlineNthCall(node.callee) || node.arguments.some(containsInlineNthCall);
156
156
  }
157
- if (isMemberExpressionNode(node)) {
157
+ if (isMemberExpressionNode$1(node)) {
158
158
  return containsInlineNthCall(node.object) || node.computed && containsInlineNthCall(node.property);
159
159
  }
160
- if (isChainExpressionNode(node)) {
160
+ if (isChainExpressionNode$1(node)) {
161
161
  return containsInlineNthCall(node.expression);
162
162
  }
163
163
  if (isAwaitExpressionNode(node)) {
164
164
  return containsInlineNthCall(node.argument);
165
165
  }
166
- if (isTsAsExpressionNode(node)) {
166
+ if (isTsAsExpressionNode$1(node)) {
167
167
  return containsInlineNthCall(node.expression);
168
168
  }
169
- if (isTsNonNullExpressionNode(node)) {
169
+ if (isTsNonNullExpressionNode$1(node)) {
170
170
  return containsInlineNthCall(node.expression);
171
171
  }
172
172
  return false;
@@ -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 = context => {
177
+ const create$1 = context => {
178
178
  return {
179
179
  CallExpression(node) {
180
180
  if (!isExpectCall(node)) {
@@ -193,6 +193,93 @@ const create = context => {
193
193
  };
194
194
 
195
195
  const noInlineNthInExpect = {
196
+ __proto__: null,
197
+ create: create$1,
198
+ meta: meta$1
199
+ };
200
+
201
+ const meta = {
202
+ type: 'problem',
203
+ docs: {
204
+ description: 'Disallow lazy nth-based variable names for locator variables'
205
+ },
206
+ messages: {
207
+ noLazyNthVariableName: 'Prefer a specific variable name like firstRow or row0 over nth-based names like rowsNth0.'
208
+ }
209
+ };
210
+ const lazyNthVariableNamePattern = /nth\d+/i;
211
+ const isIdentifierNode = node => {
212
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
213
+ };
214
+ const isVariableDeclaratorNode = node => {
215
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'VariableDeclarator' && 'id' in node && 'init' in node;
216
+ };
217
+ const isCallExpressionNode = node => {
218
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'CallExpression' && 'callee' in node && 'arguments' in node;
219
+ };
220
+ const isMemberExpressionNode = node => {
221
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'MemberExpression' && 'object' in node && 'property' in node && 'computed' in node;
222
+ };
223
+ const isChainExpressionNode = node => {
224
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'ChainExpression' && 'expression' in node;
225
+ };
226
+ const isTsAsExpressionNode = node => {
227
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSAsExpression' && 'expression' in node;
228
+ };
229
+ const isTsNonNullExpressionNode = node => {
230
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
231
+ };
232
+ const isNthCall = node => {
233
+ return isCallExpressionNode(node) && isMemberExpressionNode(node.callee) && !node.callee.computed && isIdentifierNode(node.callee.property) && node.callee.property.name === 'nth';
234
+ };
235
+ const containsNthCall = node => {
236
+ if (!node) {
237
+ return false;
238
+ }
239
+ if (isNthCall(node)) {
240
+ return true;
241
+ }
242
+ if (isCallExpressionNode(node)) {
243
+ return containsNthCall(node.callee) || node.arguments.some(containsNthCall);
244
+ }
245
+ if (isMemberExpressionNode(node)) {
246
+ return containsNthCall(node.object) || node.computed && containsNthCall(node.property);
247
+ }
248
+ if (isChainExpressionNode(node)) {
249
+ return containsNthCall(node.expression);
250
+ }
251
+ if (isTsAsExpressionNode(node)) {
252
+ return containsNthCall(node.expression);
253
+ }
254
+ if (isTsNonNullExpressionNode(node)) {
255
+ return containsNthCall(node.expression);
256
+ }
257
+ return false;
258
+ };
259
+ const hasLazyNthVariableName = node => {
260
+ return isIdentifierNode(node) && lazyNthVariableNamePattern.test(node.name);
261
+ };
262
+ const create = context => {
263
+ return {
264
+ VariableDeclarator(node) {
265
+ if (!isVariableDeclaratorNode(node)) {
266
+ return;
267
+ }
268
+ if (!hasLazyNthVariableName(node.id)) {
269
+ return;
270
+ }
271
+ if (!containsNthCall(node.init)) {
272
+ return;
273
+ }
274
+ context.report({
275
+ node: node.id,
276
+ messageId: 'noLazyNthVariableName'
277
+ });
278
+ }
279
+ };
280
+ };
281
+
282
+ const noLazyNthVariableName = {
196
283
  __proto__: null,
197
284
  create,
198
285
  meta
@@ -206,7 +293,8 @@ const plugin = {
206
293
  rules: {
207
294
  'no-direct-click': noDirectClick,
208
295
  'no-inline-locator-in-expect': noInlineLocatorInExpect,
209
- 'no-inline-nth-in-expect': noInlineNthInExpect
296
+ 'no-inline-nth-in-expect': noInlineNthInExpect,
297
+ 'no-lazy-nth-variable-name': noLazyNthVariableName
210
298
  },
211
299
  configs: {}
212
300
  };
@@ -218,7 +306,8 @@ const recommended = [{
218
306
  rules: {
219
307
  'e2e/no-direct-click': 'error',
220
308
  'e2e/no-inline-locator-in-expect': 'error',
221
- 'e2e/no-inline-nth-in-expect': 'error'
309
+ 'e2e/no-inline-nth-in-expect': 'error',
310
+ 'e2e/no-lazy-nth-variable-name': 'error'
222
311
  }
223
312
  }];
224
313
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/eslint-plugin-e2e",
3
- "version": "10.1.0",
3
+ "version": "10.2.0",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",