-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathno-nested-step.ts
58 lines (51 loc) · 1.4 KB
/
no-nested-step.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
import { Rule } from 'eslint'
import { createRule } from '../utils/createRule.js'
import { isTypeOfFnCall } from '../utils/parseFnCall.js'
export default createRule({
create(context) {
const stack: number[] = []
function pushStepCallback(node: Rule.Node) {
if (
node.parent.type !== 'CallExpression' ||
!isTypeOfFnCall(context, node.parent, ['step'])
) {
return
}
stack.push(0)
if (stack.length > 1) {
context.report({
messageId: 'noNestedStep',
node: node.parent.callee,
})
}
}
function popStepCallback(node: Rule.Node) {
const { parent } = node
if (
parent.type === 'CallExpression' &&
isTypeOfFnCall(context, parent, ['step'])
) {
stack.pop()
}
}
return {
ArrowFunctionExpression: pushStepCallback,
'ArrowFunctionExpression:exit': popStepCallback,
FunctionExpression: pushStepCallback,
'FunctionExpression:exit': popStepCallback,
}
},
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow nested `test.step()` methods',
recommended: true,
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-nested-step.md',
},
messages: {
noNestedStep: 'Do not nest `test.step()` methods.',
},
schema: [],
type: 'problem',
},
})