@lvce-editor/eslint-plugin-e2e 10.0.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 +198 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const meta$1 = {
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$1 = {
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$1 = context => {
13
+ const create$3 = context => {
14
14
  return {
15
15
  CallExpression(node) {
16
16
  if (!isDirectClickCall(node)) {
@@ -26,11 +26,11 @@ const create$1 = context => {
26
26
 
27
27
  const noDirectClick = {
28
28
  __proto__: null,
29
- create: create$1,
30
- meta: meta$1
29
+ create: create$3,
30
+ meta: meta$3
31
31
  };
32
32
 
33
- const meta = {
33
+ const meta$2 = {
34
34
  type: 'problem',
35
35
  docs: {
36
36
  description: 'Disallow inline locator expressions inside expect calls'
@@ -39,26 +39,26 @@ const meta = {
39
39
  noInlineLocatorInExpect: 'Assign the locator to a variable before passing it to expect(...).'
40
40
  }
41
41
  };
42
- const isCallExpressionNode = 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 = 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 = 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 = 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
- const isAwaitExpressionNode = node => {
54
+ const isAwaitExpressionNode$1 = node => {
55
55
  return typeof node === 'object' && node !== null && 'type' in node && node.type === 'AwaitExpression' && 'argument' in node;
56
56
  };
57
57
  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(node) && isIdentifierNode(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,16 +67,16 @@ const containsInlineLocatorCall = node => {
67
67
  if (isLocatorCall(node)) {
68
68
  return true;
69
69
  }
70
- if (isCallExpressionNode(node)) {
70
+ if (isCallExpressionNode$2(node)) {
71
71
  return containsInlineLocatorCall(node.callee) || node.arguments.some(containsInlineLocatorCall);
72
72
  }
73
- if (isMemberExpressionNode(node)) {
73
+ if (isMemberExpressionNode$2(node)) {
74
74
  return containsInlineLocatorCall(node.object) || node.computed && containsInlineLocatorCall(node.property);
75
75
  }
76
- if (isChainExpressionNode(node)) {
76
+ if (isChainExpressionNode$2(node)) {
77
77
  return containsInlineLocatorCall(node.expression);
78
78
  }
79
- if (isAwaitExpressionNode(node)) {
79
+ if (isAwaitExpressionNode$1(node)) {
80
80
  return containsInlineLocatorCall(node.argument);
81
81
  }
82
82
  if (isTsNonNullExpression(node)) {
@@ -84,13 +84,13 @@ const containsInlineLocatorCall = node => {
84
84
  }
85
85
  return false;
86
86
  };
87
- const isExpectCall = node => {
87
+ const isExpectCall$1 = node => {
88
88
  return node.callee.type === 'Identifier' && node.callee.name === 'expect';
89
89
  };
90
- const create = context => {
90
+ const create$2 = context => {
91
91
  return {
92
92
  CallExpression(node) {
93
- if (!isExpectCall(node)) {
93
+ if (!isExpectCall$1(node)) {
94
94
  return;
95
95
  }
96
96
  const [firstArgument] = node.arguments;
@@ -106,6 +106,180 @@ const create = context => {
106
106
  };
107
107
 
108
108
  const noInlineLocatorInExpect = {
109
+ __proto__: null,
110
+ create: create$2,
111
+ meta: meta$2
112
+ };
113
+
114
+ const meta$1 = {
115
+ type: 'problem',
116
+ docs: {
117
+ description: 'Disallow inline nth locator expressions inside expect calls'
118
+ },
119
+ messages: {
120
+ noInlineNthInExpect: 'Assign the nth locator to a variable before passing it to expect(...).'
121
+ }
122
+ };
123
+ const isCallExpressionNode$1 = node => {
124
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'CallExpression' && 'callee' in node && 'arguments' in node;
125
+ };
126
+ const isIdentifierNode$1 = node => {
127
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Identifier' && 'name' in node;
128
+ };
129
+ const isMemberExpressionNode$1 = node => {
130
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'MemberExpression' && 'object' in node && 'property' in node && 'computed' in node;
131
+ };
132
+ const isChainExpressionNode$1 = node => {
133
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'ChainExpression' && 'expression' in node;
134
+ };
135
+ const isAwaitExpressionNode = node => {
136
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'AwaitExpression' && 'argument' in node;
137
+ };
138
+ const isTsAsExpressionNode$1 = node => {
139
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSAsExpression' && 'expression' in node;
140
+ };
141
+ const isTsNonNullExpressionNode$1 = node => {
142
+ return typeof node === 'object' && node !== null && 'type' in node && node.type === 'TSNonNullExpression' && 'expression' in node;
143
+ };
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
+ };
147
+ const containsInlineNthCall = node => {
148
+ if (!node) {
149
+ return false;
150
+ }
151
+ if (isNthCall$1(node)) {
152
+ return true;
153
+ }
154
+ if (isCallExpressionNode$1(node)) {
155
+ return containsInlineNthCall(node.callee) || node.arguments.some(containsInlineNthCall);
156
+ }
157
+ if (isMemberExpressionNode$1(node)) {
158
+ return containsInlineNthCall(node.object) || node.computed && containsInlineNthCall(node.property);
159
+ }
160
+ if (isChainExpressionNode$1(node)) {
161
+ return containsInlineNthCall(node.expression);
162
+ }
163
+ if (isAwaitExpressionNode(node)) {
164
+ return containsInlineNthCall(node.argument);
165
+ }
166
+ if (isTsAsExpressionNode$1(node)) {
167
+ return containsInlineNthCall(node.expression);
168
+ }
169
+ if (isTsNonNullExpressionNode$1(node)) {
170
+ return containsInlineNthCall(node.expression);
171
+ }
172
+ return false;
173
+ };
174
+ const isExpectCall = node => {
175
+ return node.callee.type === 'Identifier' && node.callee.name === 'expect';
176
+ };
177
+ const create$1 = context => {
178
+ return {
179
+ CallExpression(node) {
180
+ if (!isExpectCall(node)) {
181
+ return;
182
+ }
183
+ const [firstArgument] = node.arguments;
184
+ if (!containsInlineNthCall(firstArgument)) {
185
+ return;
186
+ }
187
+ context.report({
188
+ node: firstArgument,
189
+ messageId: 'noInlineNthInExpect'
190
+ });
191
+ }
192
+ };
193
+ };
194
+
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 = {
109
283
  __proto__: null,
110
284
  create,
111
285
  meta
@@ -118,7 +292,9 @@ const plugin = {
118
292
  },
119
293
  rules: {
120
294
  'no-direct-click': noDirectClick,
121
- 'no-inline-locator-in-expect': noInlineLocatorInExpect
295
+ 'no-inline-locator-in-expect': noInlineLocatorInExpect,
296
+ 'no-inline-nth-in-expect': noInlineNthInExpect,
297
+ 'no-lazy-nth-variable-name': noLazyNthVariableName
122
298
  },
123
299
  configs: {}
124
300
  };
@@ -129,7 +305,9 @@ const recommended = [{
129
305
  },
130
306
  rules: {
131
307
  'e2e/no-direct-click': 'error',
132
- 'e2e/no-inline-locator-in-expect': 'error'
308
+ 'e2e/no-inline-locator-in-expect': 'error',
309
+ 'e2e/no-inline-nth-in-expect': 'error',
310
+ 'e2e/no-lazy-nth-variable-name': 'error'
133
311
  }
134
312
  }];
135
313
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/eslint-plugin-e2e",
3
- "version": "10.0.0",
3
+ "version": "10.2.0",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",