-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathno-hooks.ts
50 lines (47 loc) · 1.25 KB
/
no-hooks.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
import { createRule } from '../utils/createRule.js'
import { parseFnCall } from '../utils/parseFnCall.js'
export default createRule({
create(context) {
const options = {
allow: [] as string[],
...((context.options?.[0] as Record<string, unknown>) ?? {}),
}
return {
CallExpression(node) {
const call = parseFnCall(context, node)
if (!call) return
if (call.type === 'hook' && !options.allow.includes(call.name)) {
context.report({
data: { hookName: call.name },
messageId: 'unexpectedHook',
node,
})
}
},
}
},
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow setup and teardown hooks',
recommended: false,
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-hooks.md',
},
messages: {
unexpectedHook: "Unexpected '{{ hookName }}' hook",
},
schema: [
{
additionalProperties: false,
properties: {
allow: {
contains: ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'],
type: 'array',
},
},
type: 'object',
},
],
type: 'suggestion',
},
})