-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathrequire-soft-assertions.ts
41 lines (39 loc) · 1.1 KB
/
require-soft-assertions.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
import { getStringValue } from '../utils/ast.js'
import { createRule } from '../utils/createRule.js'
import { parseFnCall } from '../utils/parseFnCall.js'
export default createRule({
create(context) {
return {
CallExpression(node) {
const call = parseFnCall(context, node)
if (
call?.type !== 'expect' ||
call.modifiers.some((m) => {
const name = getStringValue(m)
return name === 'soft' || name === 'poll'
})
) {
return
}
context.report({
fix: (fixer) => fixer.insertTextAfter(call.head.node, '.soft'),
messageId: 'requireSoft',
node: call.head.node,
})
},
}
},
meta: {
docs: {
description: 'Require all assertions to use `expect.soft`',
recommended: false,
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/require-soft-assertions.md',
},
fixable: 'code',
messages: {
requireSoft: 'Unexpected non-soft assertion',
},
schema: [],
type: 'suggestion',
},
})