-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathno-networkidle.ts
64 lines (55 loc) · 1.71 KB
/
no-networkidle.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import ESTree from 'estree'
import { getStringValue, isStringLiteral } from '../utils/ast.js'
import { createRule } from '../utils/createRule.js'
const messageId = 'noNetworkidle'
const methods = new Set([
'goBack',
'goForward',
'goto',
'reload',
'setContent',
'waitForLoadState',
'waitForURL',
])
export default createRule({
create(context) {
return {
CallExpression(node) {
if (node.callee.type !== 'MemberExpression') return
const methodName = getStringValue(node.callee.property)
if (!methods.has(methodName)) return
// waitForLoadState has a single string argument
if (methodName === 'waitForLoadState') {
const arg = node.arguments[0]
if (arg && isStringLiteral(arg, 'networkidle')) {
context.report({ messageId, node: arg })
}
return
}
// All other methods have an options object
if (node.arguments.length >= 2) {
const [_, arg] = node.arguments
if (arg.type !== 'ObjectExpression') return
const property = arg.properties
.filter((p): p is ESTree.Property => p.type === 'Property')
.find((p) => isStringLiteral(p.value, 'networkidle'))
if (property) {
context.report({ messageId, node: property.value })
}
}
},
}
},
meta: {
docs: {
category: 'Possible Errors',
description: 'Prevent usage of the networkidle option',
recommended: true,
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-networkidle.md',
},
messages: {
noNetworkidle: 'Unexpected use of networkidle.',
},
type: 'problem',
},
})